当我执行 echo 0 >authorized 时,我的 USB udev 规则不会触发; echo 1 >授权

当我执行 echo 0 >authorized 时,我的 USB udev 规则不会触发; echo 1 >授权

当我物理插入 USB 设备时,我的自定义规则会运行 shell 命令。

/etc/udev/rules.d/85-my_stk1160_pal.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05e1", ATTR{idProduct}=="0408", RUN+="/usr/local/bin/my_stk1160_pal.sh"

但当我以编程方式重置该设备时,它不会运行。

/usr/local/bin/camreplug:

#!/bin/bash

# find
fn_findusb() {
    for fn_findusb_devpath in /sys/bus/usb/devices/*; do
        read -r fn_findusb_vendor <"$fn_findusb_devpath/idVendor" && read -r fn_findusb_product <"$fn_findusb_devpath/idProduct" \
            && [ x"$1" = x"$fn_findusb_vendor" -a x"$2" = x"$fn_findusb_product" ] && return
    done 2>/dev/null
    fn_findusb_devpath=
    return 1
}

fn_findusb 05e1 0408 && echo 0 >"$fn_findusb_devpath/authorized" && echo 1 >"$fn_findusb_devpath/authorized"

udevadm monitor之后的输出echo 1 >authorized

KERNEL[17717.589940] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0 (usb)
KERNEL[17717.592006] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6 (i2c)
UDEV  [17717.593360] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0 (usb)
UDEV  [17717.603394] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6 (i2c)
KERNEL[17717.631988] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6/6-0025 (i2c)
UDEV  [17717.633784] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6/6-0025 (i2c)
KERNEL[17719.256716] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/video4linux/video0 (video4linux)
KERNEL[17719.260381] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1 (usb)
UDEV  [17719.263691] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1 (usb)
KERNEL[17719.267396] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
KERNEL[17719.267923] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/controlC1 (sound)
KERNEL[17719.268138] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/pcmC1D0c (sound)
KERNEL[17719.268516] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.2 (usb)
UDEV  [17719.274465] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/video4linux/video0 (video4linux)
UDEV  [17719.285210] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
UDEV  [17719.287165] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.2 (usb)
UDEV  [17719.292012] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/pcmC1D0c (sound)
KERNEL[17719.293854] change   /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
UDEV  [17719.299169] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/controlC1 (sound)
UDEV  [17719.306564] change   /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)

物理插入后:

KERNEL[17926.766100] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1 (usb)
KERNEL[17926.767912] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0 (usb)
KERNEL[17926.767957] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6 (i2c)
KERNEL[17926.792798] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6/6-0025 (i2c)
KERNEL[17928.353290] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/video4linux/video0 (video4linux)
KERNEL[17928.354010] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1 (usb)
KERNEL[17928.355404] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
KERNEL[17928.355687] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/controlC1 (sound)
KERNEL[17928.355943] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/pcmC1D0c (sound)
KERNEL[17928.356707] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.2 (usb)
UDEV  [17928.491720] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1 (usb)
UDEV  [17928.506965] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0 (usb)
UDEV  [17928.508603] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6 (i2c)
UDEV  [17928.515808] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/i2c-6/6-0025 (i2c)
UDEV  [17928.527017] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1 (usb)
UDEV  [17928.534729] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.0/video4linux/video0 (video4linux)
UDEV  [17928.538411] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.2 (usb)
UDEV  [17928.539868] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
UDEV  [17928.542376] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/pcmC1D0c (sound)
KERNEL[17928.544205] change   /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)
UDEV  [17928.552321] add      /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1/controlC1 (sound)
UDEV  [17928.556793] change   /devices/pci0000:00/0000:00:13.2/usb1/1-1/1-1:1.1/sound/card1 (sound)

相关内容