[systemd-devel] UDEV rule not matching...why?

Mantas Mikulėnas grawity at gmail.com
Thu Oct 10 05:34:03 UTC 2024


On Thu, Oct 10, 2024 at 8:24 AM Daniel Spannbauer <ds at marco.de> wrote:

> Am 09.10.2024 um 20:55 schrieb Andrei Borzenkov:
> > 09.10.2024 17:02, Daniel Spannbauer wrote:
> >> Hello,
> >>
> >>
> >> thanks for the response.
> >>
> >> My rule is in "55-my-rules.rules"
> >>
> >
> > For SUBSYSTEM=="tty" the usb_id is called in 60-serial.rules.
>
>
> Thats the trick, thanks.
>
>
> I moved my rules to 98-.... and this line works:
>
> SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*",
> ENV{ID_USB_INTERFACE_NUM}=="02", ATTRS{idVendor}=="1dfb",
> ATTRS{idProduct}=="0010", SYMLINK+="2a"
>
>
> It also works with SUBSYSTEMS=="usb".
>
> But the following still doesn't work:
>
> SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*", ATTRS{bInterfaceNumber}=="02",
> ATTRS{idVendor}=="1dfb", ATTRS{idProduct}=="0010", SYMLINK+="2a
>

I suspect this is because idVendor and bInterfaceNumber are from different
levels of the hierarchy – one belongs to the USB device parent, the other
belongs to its usb_interface child.

ATTRS is "sticky" – it only does the upward search *once* per rule, so e.g.
after it finds bInterfaceNumber on the 'usb_interface' level, it will
expect all other attributes to be there as well. I think the same applies
to ENVS.

So if you need to gather sysfs attributes from multiple levels, you
probably need to use separate rules to copy them into ENV one-by-one,
either using ATTRS directly or using IMPORT{parent} or something.

I suppose that is why most of the information is already being duplicated
as ENV by the stock rules to begin with – because ENV is easier to import
from multiple layers of parents.


>
> And how can I find out, which value comes with which rules so I can set
> my rules at the right time?
>

I grepped my ~/src/systemd/src for "ID_USB_INTERFACE_NUM" and saw it
defined in udev-builtin-usb_id.c, then I grepped /lib/udev/rules.d for
"usb_id". Generally safest to place your rules no earlier than 80-*, I
guess.

-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20241010/32d12c11/attachment-0001.htm>


More information about the systemd-devel mailing list