1

When I build rules for either a PS/2 or game port connected device, udev will never match on attributes, but it will on environment values. The reason why this is an issue can be seen in the output below. The given environment values are rather unspecific, it isn't clear what devices are being referenced in the rules, while the attribute values can be very clear with the actual device name. Especially in the case of my Gravis GamePad, which has very esoteric ENV values, but an ATTR name of "Gravis GamePad Pro".

This works:

ENV{XKBMODEL}=="pc105", RUN+="keymap $name microsoft-internet-keyboard"

This does not work:

ATTR{name}=="AT Translated Set 2 keyboard", RUN+="keymap $name microsoft-internet-keyboard"

I get the environment values from running the following:

udevadm info -q all -n /dev/input/event0
P: /devices/pci0000:00/0000:00:1e.0/0000:02:04.0/gameport0/input/input5/js0
N: input/js0
S: input/by-path/pci-0000:02:04.0-joystick
E: DEVLINKS=/dev/input/by-path/pci-0000:02:04.0-joystick
E: DEVNAME=/dev/input/js0
E: DEVPATH=/devices/pci0000:00/0000:00:1e.0/0000:02:04.0/gameport0/input/input5/js0
E: ID_INPUT=1
E: ID_INPUT_JOYSTICK=1
E: ID_PATH=pci-0000:02:04.0
E: ID_PATH_TAG=pci-0000_02_04_0
E: ID_SERIAL=noserial
E: MAJOR=13
E: MINOR=0
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=3244030793

And the attribute values from running:

udevadm info -n /dev/input/event0 --attribute-walk

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/i8042/serio0/input/input0/event0':
    KERNEL=="event0"
    SUBSYSTEM=="input"
    DRIVER==""

  looking at parent device '/devices/platform/i8042/serio0/input/input0':
    KERNELS=="input0"
    SUBSYSTEMS=="input"
    DRIVERS==""
    ATTRS{name}=="AT Translated Set 2 keyboard"
    ATTRS{phys}=="isa0060/serio0/input0"
    ATTRS{uniq}==""
    ATTRS{properties}=="0"

  looking at parent device '/devices/platform/i8042/serio0':
    KERNELS=="serio0"
    SUBSYSTEMS=="serio"
    DRIVERS=="atkbd"
    ATTRS{description}=="i8042 KBD port"
    ATTRS{bind_mode}=="auto"
    ATTRS{extra}=="0"
    ATTRS{force_release}=="369-370"
    ATTRS{scroll}=="0"
    ATTRS{set}=="2"
    ATTRS{softrepeat}=="0"
    ATTRS{softraw}=="1"
    ATTRS{err_count}=="0"

  looking at parent device '/devices/platform/i8042':
    KERNELS=="i8042"
    SUBSYSTEMS=="platform"
    DRIVERS=="i8042"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

When constructing my rules, I'm mainly following the advice from this site which could very well be outdated. In particular, I'm paying attention to the bit which says:

... it is legal to combine the attributes from the device in question and a single parent device, you cannot mix-and-match attributes from multiple parent devices - your rule will not work.

  • Have you tried ATTRS{name}? I think the singular form ATTR{...} only matches in the current 'event device' (whereas the name attribute in your case belongs to the parent node) – steeldriver Aug 7 '14 at 1:54
  • I hadn't realized that was an option. Changing to ATTRS{name} fixed my problems. – Steve Aug 7 '14 at 2:05
  • OK - for the record, I will post it as an answer – steeldriver Aug 7 '14 at 2:11
1

According to the udev manpage (man 7 udev), there are two distinct forms of the attribute match:

   ATTR{filename}
       Match sysfs attribute values of the event device. Trailing
       whitespace in the attribute values is ignored unless the specified
       match value itself contains trailing whitespace.

and

   ATTRS{filename}
       Search the devpath upwards for a device with matching sysfs
       attribute values. If multiple ATTRS matches are specified, all of
       them must match on the same device. Trailing whitespace in the
       attribute values is ignored unless the specified match value itself
       contains trailing whitespace.

Since name is an attribute of the parent node, you need to use the second form, i.e.

ATTRS{name}=="AT Translated Set 2 keyboard"

instead of

ATTR{name}=="AT Translated Set 2 keyboard" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.