Skip to contentSkip to conversation

Udev rule $attr substitution

DISCUSSION Josua Dietze 3 participants 8 messages Dec 21, 2010 – Dec 26, 2010

lore
Share & tools
lore
#0 lore raw

Hi, everyone!

I'm scratching my head over this:

Rule line:
KERNEL="ttyUSB*" RUN+="myprog %p %s{idVendor} %s{idProduct}"

%p expands to something like:
/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.2/ttyUSB2/tty/ttyUSB2

But the %s (or $attr) format string will not be substituted with anything when using udev version 157. The same rule works fine with version 125.

When doing the attribute walk with "udevadm info", the attributes are of course found in the parent chain.

Did I miss something?

#1 lore raw

Never mind, I figured it out.

It was all a problem of not-quite-accurate man pages.

I found the man page (well, xml file) in the git tree and just added an ATTRS match to the top level USB device.

This worked:
KERNEL="ttyUSB*", ATTRS{bNumConfigurations}="*", RUN+="myprog %p %s{idVendor} %s{idProduct}"

Sorry for the noise, thanks anyway.

But I might add that there is certainly some documentation lacking on this one, practially everything I found was outdated or inaccurate ...

Josua Dietze

#2 lore raw
In reply to Josua Dietze

Hello Josua,

Josua Dietze [2010-12-21 21:25 +0100]:

Quoted 6 lines

I found the man page (well, xml file) in the git tree and just added an ATTRS match to the top level USB device.

This worked:
KERNEL="ttyUSB*", ATTRS{bNumConfigurations}="*", RUN+="myprog %p %s{idVendor} %s{idProduct}"

Right, you need to "select" the parent device of which you need the id* attribute.

Quoted 3 lines

But I might add that there is certainly some documentation lacking on this one, practially everything I found was outdated or inaccurate ...

This is indeed a common trap, so some time ago I tried to point this out more clearly in the manpage:

$attr{file}, %s{file}
The value of a sysfs attribute found at the device, where all keys of the rule have matched. If the matching device does not have such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS test selected a parent device, use the attribute from that parent device.

This tries to point out that this won't match attributes from any parent device. Do you think this paragraph is unclear? If so, do you have a suggestion how to improve it? Or did you not see it in the first place?

Thank you,

Martin

Signature · 2 lines
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
#3 lore raw
In reply to Josua Dietze

Am 22.12.2010 09:51, schrieb Martin Pitt:

Quoted 14 lines
Quoted 3 lines

But I might add that there is certainly some documentation lacking on this one, practially everything I found was outdated or inaccurate ...

This is indeed a common trap, so some time ago I tried to point this out more clearly in the manpage:

$attr{file}, %s{file}
The value of a sysfs attribute found at the device, where all keys of the rule have matched. If the matching device does not have such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS test selected a parent device, use the attribute from that parent device.

Quoted 4 lines

This tries to point out that this won't match attributes from any parent device. Do you think this paragraph is unclear? If so, do you have a suggestion how to improve it? Or did you not see it in the first place?

The entry in the current man page is fine.

I was broadly referring to the documentation floating around in the Web, examples, howtos and forum discussions. Nothing of your responsibility, really.

What's a bit unfortunate though is the discrepancy between man pages and functionality of versions before the man page correction. OpenSUSE 11.3 ships with v. 157 which claims to do the upward chain search for $attr but doesn't.

Maybe an "official" udev page consisting of the current man page and two or three additional notes regarding changes in previously available features would help. Or does it exist and I missed it?

Just my 2c,

Josua Dietze

#4 lore raw
In reply to Josua Dietze

Hello Josua,

Josua Dietze [2010-12-22 12:42 +0100]:

Quoted 2 lines

What's a bit unfortunate though is the discrepancy between man pages and functionality of versions before the man page correction.

That's right, there was a time when the manpage was still wrong. The manpage was fixed in August:

http://git.kernel.org/?p=linux/hotplug/udev.git;a=commitdiff;hƒ184d008ba2

Quoted 3 lines

Maybe an "official" udev page consisting of the current man page and two or three additional notes regarding changes in previously available features would help. Or does it exist and I missed it?

The one I quoted from is the official manpage, as it is released upstream in the last few versions (>= 162).

Martin

Signature · 2 lines
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
#5 lore raw
In reply to Josua Dietze

Am 22.12.2010 16:58, schrieb Martin Pitt:

Quoted 7 lines

Josua Dietze [2010-12-22 12:42 +0100]:

Quoted 3 lines

Maybe an "official" udev page consisting of the current man page and two or three additional notes regarding changes in previously available features would help. Or does it exist and I missed it?

The one I quoted from is the official manpage, as it is released upstream in the last few versions (>= 162).

I was thinking of something that would come up if you google for "udev man page" or "udev home"; this will hardly work for a XML file in a git tree ...

But it's no big deal either; I mean, I found it eventually, right? Those who really care will arrive there sooner or later.

Thanks for your time!

Josua Dietze

#6 lore raw
In reply to Josua Dietze
Quoted 12 lines · Josua Dietze

Am 22.12.2010 16:58, schrieb Martin Pitt:

Quoted 8 lines

Josua Dietze [2010-12-22 12:42 +0100]:

Quoted 4 lines

Maybe an "official" udev page consisting of the current man page and two or three additional notes regarding changes in previously available features would help. Or does it exist and I missed it?

The one I quoted from is the official manpage, as it is released upstream in the last few versions (>= 162).

Quoted 7 lines

I was thinking of something that would come up if you google for "udev man page" or "udev home"; this will hardly work for a XML file in a git tree ...

But it's no big deal either; I mean, I found it eventually, right? Those who really care will arrive there sooner or later.

Thanks for your time!

We sync (make doc-sync in the tree) the generated html from the libs the git tree to kernel.org for libudev and gudev:
http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
http://www.kernel.org/pub/linux/utils/kernel/hotplug/gudev/
Should be easy to let xmlto create html pages for theman pages and
sync them to:
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/
at the same time.

Kay

#7 lore raw
In reply to Josua Dietze
Quoted 21 lines · Kay Sievers
Quoted 12 lines · Josua Dietze

Am 22.12.2010 16:58, schrieb Martin Pitt:

Quoted 8 lines

Josua Dietze [2010-12-22 12:42 +0100]:

Quoted 4 lines

Maybe an "official" udev page consisting of the current man page and two or three additional notes regarding changes in previously available features would help. Or does it exist and I missed it?

The one I quoted from is the official manpage, as it is released upstream in the last few versions (>= 162).

Quoted 7 lines

I was thinking of something that would come up if you google for "udev man page" or "udev home"; this will hardly work for a XML file in a git tree ...

But it's no big deal either; I mean, I found it eventually, right? Those who really care will arrive there sooner or later.

Thanks for your time!

Quoted 8 lines

We sync (make doc-sync in the tree) the generated html from the libs the git tree to kernel.org for libudev and gudev:
 http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
 http://www.kernel.org/pub/linux/utils/kernel/hotplug/gudev/
 Should be easy to let xmlto create html pages for theman pages and sync them to:
 http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/
 at the same time.

It's here now:
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/

Cheers,
Kay