![PS/2 和游戏端口的 udev 规则在 attr 上不匹配,仅在 env 上匹配](https://linux22.com/image/41173/PS%2F2%20%E5%92%8C%E6%B8%B8%E6%88%8F%E7%AB%AF%E5%8F%A3%E7%9A%84%20udev%20%E8%A7%84%E5%88%99%E5%9C%A8%20attr%20%E4%B8%8A%E4%B8%8D%E5%8C%B9%E9%85%8D%EF%BC%8C%E4%BB%85%E5%9C%A8%20env%20%E4%B8%8A%E5%8C%B9%E9%85%8D.png)
当我为 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==""
在构建我的规则时,我主要遵循以下建议这个网站这可能已经过时了。我特别关注的是以下部分:
...将相关设备和单个父设备的属性组合起来是合法的,您不能混合匹配多个父设备的属性 - 您的规则将不起作用。
答案1
根据 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"