udev isn't hard

1622333096297

udev isn't hard

I had ignored udev for a while as it seemed too have a lot of arcane incantations (I know, it's Linux, I should be used to this) to do something that I could do just as easily with a script and I'd know when it triggered because I did it.

Along came a headless system that needed to map arbitrary devices FTDI serial chip devices to fixed /dev/ttyXYZ locations so that they could be discovered and accessed. Doing this in the apps that needed to access the data was going to prove tricky signalling either between apps or to the kernel while avoiding race conditions with exclusive access to the devices. Enter udev.

I started with this article but quickly had more questions and found Daniel Drake (dsd)'s site about writing udev rules that is relevant today even though it's over a decade old (although the udevinfo command was udevadm info for me). In particular it calls out the difference between ATTRS (match the listed attribute anywhere in the device tree) and ATTR (match the listed attribute only on the leaf device) which can be confusing.

A little sysfs / udevadm info inspection yielded:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{manufacturer}=="someMan", SYMLINK+="ttyXYZ"

And I know reliable have the product from someMan at ttyXYZ (and the system only has room for one at a time so I can skip dealing with mulitples).

Some other references that were helpful: https://v2.openhab.org/addons/bindings/serial1/ default rules are at /lib/udev/rules.d/60-persistent-serial.rules

powered by offpress