linux-surface / iptsd

Userspace daemon for Intel Precise Touch & Stylus
GNU General Public License v2.0
94 stars 46 forks source link

Why `tail -n1`? #100

Closed groengpx closed 1 year ago

groengpx commented 1 year ago

Out of sheer curiosity, why is $DEVICES piped through tail -n1 before being piped to grep? tail -n1 seems a no-op to me. Am I missing something?

https://github.com/linux-surface/iptsd/blob/c7c484477206b4a49c0caf76b94ccdfc9311ba76/etc/iptsd-find-hidraw#L4

StollD commented 1 year ago

Due to how the bus / hardware works, the driver is unloaded every time the system suspends. An error during unloading can result in the hidraw device staying around as a ghost device with no driver backing it. So when you resume, you get two hidraw devices called "IPTS", and you want the one that was created last.

groengpx commented 1 year ago

Whoops, my bad. I confused it with tail -c +1 , which would output lines from the beginning, which would not be very useful in a pipe, unless there was some shell trick I was unaware of. Of course, tail -n1 lists only the last line, which is not a trick, but just regular use.

Well, at least I learned why we only need the last line from $DEVICES.

Thanks for the explanation.