Udev

PS/2 和遊戲埠的 udev 規則在 attr 上不匹配,僅在 env 上匹配

  • August 7, 2014

當我為連接 PS/2 或遊戲埠的設備建構規則時,udev 永遠不會匹配屬性,但會匹配環境值。這是一個問題的原因可以在下面的輸出中看到。給定的環境值相當不具體,不清楚規則中引用了哪些設備,而屬性值可以非常清楚地與實際設備名稱一起使用。特別是對於我的 Gravis GamePad,它具有非常深奧的 ENV 值,但 ATTR 名稱為“Gravis GamePad Pro”。

這有效:

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

不起作用

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

我通過執行以下命令獲取環境值:

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

以及執行中的屬性值:

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==""

在建構我的規則時,我主要遵循這個站點的建議,這些建議很可能已經過時了。特別是,我正在關注以下內容:

…將相關設備的屬性與單個父設備組合是合法的,您不能混合和匹配來自多個父設備的屬性 - 您的規則將不起作用。

根據 udev 手冊頁 ( man 7 udev),屬性匹配有兩種不同的形式:

  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.

  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.

由於name是父節點的一個屬性,所以需要使用第二種形式,即

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

代替

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

引用自:https://unix.stackexchange.com/questions/148863