在 udev 中将设备解除绑定并绑定到同一驱动程序时出现无限循环

在 udev 中将设备解除绑定并绑定到同一驱动程序时出现无限循环

我在 ubuntu 20.04 上使用 Magic Mouse 2。要使用滚动功能,我必须安装此驱动程序:https://github.com/rohitpid/Linux-Magic-Trackpad-2-Driver唯一的问题是每次我重新启动或者通过蓝牙重新连接鼠标时我都需要执行这两行:

echo "0005:004C:0269.0008" > /sys/bus/hid/drivers/magicmouse/unbind
echo "0005:004C:0269.0008" > /sys/bus/hid/drivers/magicmouse/bind

如果我在鼠标连接后没有解除绑定然后绑定,我仍然可以使用魔术鼠标,但滚动不起作用。

无论如何,我一直在寻找一种方法,只要鼠标通过蓝牙连接,就可以自动执行此操作。我找到了 udev,但无法让它工作,否则会陷入无限循环。以下是我的hid-magicmouse.rules文件内容/etc/udev/rules.d

ACTION=="bind", KERNEL=="0005:004C:0269.*", SUBSYSTEM=="hid", DRIVER=="magicmouse", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/magicmouse/unbind'", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/magicmouse/bind'"

这会陷入无限循环,因为脚本在执行第二行(绑定命令)后会再次调用自身,而第二行是此规则的触发操作。

我尝试将触发操作改为“添加”而不是“绑定”,但滚动仍然不起作用。

udevadm monitor以下是连接魔术鼠标时的输出:

KERNEL[1684.898183] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12 (bluetooth)
UDEV  [1684.905964] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12 (bluetooth)
KERNEL[1685.029515] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008 (hid)
KERNEL[1685.029970] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494 (input)
KERNEL[1685.030138] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494/mouse1 (input)
KERNEL[1685.030418] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494/event15 (input)
KERNEL[1685.030510] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/hidraw/hidraw5 (hidraw)
UDEV  [1685.034983] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008 (hid)
UDEV  [1685.042271] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494 (input)
UDEV  [1685.050656] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/hidraw/hidraw5 (hidraw)
UDEV  [1685.050881] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494/mouse1 (input)
UDEV  [1685.088633] add      /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008/input/input494/event15 (input)
KERNEL[1685.627176] bind     /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008 (hid)
UDEV  [1685.632050] bind     /devices/pci0000:00/0000:00:1e.0/dw-apb-uart.2/serial1/serial1-0/bluetooth/hci0/hci0:12/0005:004C:0269.0008 (hid)

任何能自动化或修复这个问题的帮助都将不胜感激!

相关内容