Udev:附加设备时执行cmd,但不执行任何操作

Udev:附加设备时执行cmd,但不执行任何操作

我创建了规则,当我连接 USB 鼠标以禁用触摸板和指点杆时,应运行命令:

machine ~ # cat /etc/udev/rules.d/61-touchpad.rules 
# 61-touchpad.rules
# disable PS/2 touchpad on DISPLAY :0 if a mouse is added to the system
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", ENV{ID_BUS}=="usb", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user/.Xauthority", RUN+="/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint'"

# enable PS/2 touchpad on DISPLAY :0 if a mouse is removed from the system
ACTION=="remove", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", ENV{ID_BUS}=="usb", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user/.Xauthority", RUN+="/usr/bin/xinput --enable 'AlpsPS/2 ALPS GlidePoint'"

# disable Point Stick on DISPLAY :0 if a mouse is added to the system
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", ENV{ID_BUS}=="usb", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user/.Xauthority", RUN+="/usr/bin/xinput --disable 'DualPoint Stick'"

# enable Point Stick on DISPLAY :0 if a mouse is removed from the system
ACTION=="remove", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", ENV{ID_BUS}=="usb", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user/.Xauthority", RUN+="/usr/bin/xinput --enable 'DualPoint Stick'"

machine ~ #

当我从 shell 以 root 身份运行命令时,之前设置了 DISPLAY 和 XAUTHORITY,然后当我移除/重新连接 USB 鼠标时,触摸板和指点杆将相应地激活/停用。

当我用来udevadm test --action=add /sys/class/input/mouse0测试规则时,udev 会写入大量信息,其中写入它在正确的环境下运行命令:

LINK 'input/by-path/pci-0000:00:14.0-usb-0:6:1.0-mouse' /lib/udev/rules.d/60-persistent-input.rules:32
RUN '/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint'' /etc/udev/rules.d/61-touchpad.rules:20
RUN '/usr/bin/xinput --disable 'DualPoint Stick'' /etc/udev/rules.d/61-touchpad.rules:26
device 0x7f0315c20320 filled with db file data
...
ACTION=add
DEVLINKS=/dev/input/by-id/usb-Logitech_USB_Optical_Mouse-mouse /dev/input/by-path/pci-0000:00:14.0-usb-0:6:1.0-mouse
DEVNAME=/dev/input/mouse0
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/0003:046D:C077.002A/input/input63/mouse0
DISPLAY=:0.0
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
...
MAJOR=13
MINOR=32
SUBSYSTEM=input
UDEV_LOG=7
USEC_INITIALIZED=8190049649
XAUTHORITY=/home/user/.Xauthority
run: '/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint''
run: '/usr/bin/xinput --disable 'DualPoint Stick''
...

当我运行udevd --debug并移除/重新连接 USB 鼠标时,我获得了有关正在发生的情况的大量信息:

starting '/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint''
starting '/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint''
'/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint'' [27714] exit with return code 0
'/usr/bin/xinput --disable 'AlpsPS/2 ALPS GlidePoint'' [27715] exit with return code 0
starting '/usr/bin/xinput --disable 'DualPoint Stick''
starting '/usr/bin/xinput --disable 'DualPoint Stick''
'/usr/bin/xinput --disable 'DualPoint Stick'' [27719] exit with return code 0

一切看起来都不错...唯一的问题是,当我连接 USB 鼠标时,触摸板和指点杆未被禁用。

我错过了什么?

相关内容