Greg Erskine wrote: > I am curious about the remove rule. :confused: > > It looks like it will activate whenever *any* USB device is removed.
Yes, that's right. When my DAC is connected, dmesg shows that it actually connects three devices. In this example they are devices 10, 11 and 12 - a USB HUB, the DAC, and something called DLCP, which I believe is the programming interface. Code: -------------------- [170202.072564] usb 1-1.3: new full-speed USB device number 10 using xhci_hcd [170202.179417] usb 1-1.3: New USB device found, idVendor=0451, idProduct=2036, bcdDevice= 1.01 [170202.179430] usb 1-1.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0 [170202.179441] usb 1-1.3: Product: General Purpose USB Hub [170202.186528] hub 1-1.3:1.0: USB hub found [170202.187410] hub 1-1.3:1.0: 2 ports detected [170202.480562] usb 1-1.3.1: new full-speed USB device number 11 using xhci_hcd [170202.594599] usb 1-1.3.1: New USB device found, idVendor=08bb, idProduct=2704, bcdDevice= 1.00 [170202.594611] usb 1-1.3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [170202.594622] usb 1-1.3.1: Product: USB Audio DAC [170202.594632] usb 1-1.3.1: Manufacturer: Burr-Brown from TI [170202.631275] hid-generic 0003:08BB:2704.0005: hidraw0: USB HID v1.00 Device [Burr-Brown from TI USB Audio DAC ] on usb-0000:01:00.0-1.3.1/input2 [170202.856569] usb 1-1.3.2: new full-speed USB device number 12 using xhci_hcd [170202.965778] usb 1-1.3.2: New USB device found, idVendor=04d8, idProduct=ff89, bcdDevice= 0.01 [170202.965791] usb 1-1.3.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [170202.965801] usb 1-1.3.2: Product: DLCP [170202.965811] usb 1-1.3.2: Manufacturer: Hypex BV [170202.973646] hid-generic 0003:04D8:FF89.0006: hiddev96,hidraw1: USB HID v1.11 Device [Hypex BV DLCP] on usb-0000:01:00.0-1.3.2/input0 -------------------- But there's plenty of information about each device, most notably the idVendor and idProduct values, and these allow the 'add' rule to be targeted very specifically so that it only fires for one of those three devices. However, when my DAC is disconnected, the only information reported by dmesg is device number and the so-callled kernel name ($kernel), in this case 1-1.3, 1-1.3.1 or 1-1.3.2. The idVendor and idProduct attributes aren't available to filter the 'remove' rule. Code: -------------------- [183513.447152] usb 1-1.3: USB disconnect, device number 10 [183513.447171] usb 1-1.3.1: USB disconnect, device number 11 [183513.454398] usb 1-1.3.2: USB disconnect, device number 12 -------------------- Unfortunately, $kernel doesn't seem to be something that the rule can be filtered on in the way that idVendor and idProduct are, but it CAN be passed to the function that is called when the rule fires. So the approach that the script takes is to record the kernel name associated with the specific idVendor and idProduct into a file in the /tmp directory, and then every time the 'remove' event is triggered, by whatever USB device, the script compares the associated kernel name to the one in the file, and only stops Squeezelite if they match. This example from the script's log file shows it in action: Code: -------------------- [ 170202.63] Script parameters: restart DAC 1-1.3.1 [ 170202.64] DAC detected on 1-1.3.1 [ 170202.67] Attempting to start squeezelite [ 170203.72] Restarting Squeezelite player... Stopping Squeezelite player: Squeezelite... Starting Squeezelite player: Squeezelite... [ 183513.46] Script parameters: stop DAC 1-1.3.1:1.0 [ 183513.46] Script parameters: stop DAC 1-1.3.1:1.1 [ 183513.47] Script parameters: stop DAC 1-1.3:1.0 [ 183513.47] Script parameters: stop DAC 1-1.3.1:1.2 [ 183513.47] Script parameters: stop DAC 1-1.3.2:1.0 [ 183513.48] Script parameters: stop DAC 1-1.3.1 [ 183513.48] Script parameters: stop DAC 1-1.3.2 [ 183513.48] DAC on 1-1.3.1 removed [ 183513.50] Stopping Squeezelite player: Squeezelite... [ 183513.51] Script parameters: stop DAC 1-1.3 -------------------- With this approach, the script is briefly called for each of the devices associated with the DAC, and it would be called also if I removed as USB flash drive, but the script returns very quickly without doing anything, except when the $kernel parameter matches the one associated with the DAC device. The file in the /tmp directory is created whenever the DAC is connected, or, if it's already connected at boot, by the 'find' option, which gets it from dmesg. ------------------------------------------------------------------------ chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 _______________________________________________ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix