1

My custom rule runs a shell command when I physically plug the USB device.

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

But it won't run, when I programmatically reset this device.

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

output of udevadm monitor after 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)

after physically plugging:

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)
5
  • 2
    ... well, probably because you're not actually unplugging/replugging the device. Could you back up a little here, and explain the ultimate goal you're trying to accomplish? (You can BTW use udevadm monitor to see what events udev is getting).
    – derobert
    Aug 18, 2015 at 13:07
  • @derobert goal is to reset a hung device without actually replugging it and to set some defaults after.
    – basin
    Aug 18, 2015 at 13:19
  • Hmmm, does the answer here unix.stackexchange.com/questions/165447/… help?
    – derobert
    Aug 18, 2015 at 13:22
  • @derobert, no, it does not react when I echo 0 to autosuspend_delay_ms
    – basin
    Aug 18, 2015 at 13:30
  • Thanks, udevadm monitor helped: no "add" event for the root node. Updated my rule to monitor one of the children
    – basin
    Aug 18, 2015 at 13:42

0

You must log in to answer this question.

Browse other questions tagged .