On Thu, Aug 21, 2008 at 03:37, Aras Vaichas <arasv@xxxxxxxxxxxxxx> wrote: > Hi, I'm looking to unload a userspace driver when a particular device is > removed. > > My load rule is this: > > ACTION=="add",SUBSYSTEM=="usb_endpoint",ATTR{device/manufacturer}=="Crystalfontz", > RUN+="/usr/bin/sv up lcdd" > > Now the problem was that when I disconnect the device there is no longer > a "device/manufacturer" file, so I added an environment variable > LCDD_DEVICE to the rule: > > ACTION=="add",SUBSYSTEM=="usb_endpoint",ATTR{device/manufacturer}=="Crystalfontz", > ENV{LCDD_DEVICE}="%k", RUN+="/usr/bin/sv up lcdd" Why do you match against the endpoint? These devices do not do anything. You should also never use the "device" link, it's deprecated and udev should print a warning to the logs. > I had hoped to be able to match this LCDD_DEVICE variable when the > kernel name appeared in the remove event. So I tried: > > ACTION=="remove", ENV{LCDD_DEVICE}=="%k", RUN+="... remove the driver ..." > > But this rule never triggered. > > I put in a debug line, and disconnected the device: > > ACTION=="remove", RUN+="/bin/sh -c 'logger B %k = $env{LCDD_DEVICE}'" > > Jan 1 00:41:21 user.notice root: B usbdev1.23_ep81 = > Jan 1 00:41:21 user.notice root: B usbdev1.23_ep02 = > Jan 1 00:41:21 user.notice root: B usbdev1.23_ep00 = usbdev1.23_ep00 > <--- !!! > Jan 1 00:41:21 user.notice root: B ttyUSB1 = > Jan 1 00:41:21 user.notice root: B ttyUSB1 = > Jan 1 00:41:21 user.notice root: B 1-1:1.0 = > Jan 1 00:41:21 user.notice root: B 1-1 = > > So there is a situation where %k was equal to LCDD_DEVICE, but > regardless the rule didn't trigger. Did I get the syntax wrong? > > Also, it appears that the scope of the environment variable LCDD_DEVICE > only occurs when the actual device has caused the uevent. OK. > > So should I make my remove rule like this? > > ACTION=="remove", ENV{LCDD_DEVICE}!="", RUN+="... remove the driver ..." By matching on the endpoint, you get several events which will all trigger your script. Try using the USB-device only, by adding: ENV{DEVTYPE}=="usb_device" Try setting: ENV{REMOVE_CMD}="/bin/something" with the "add" rule, it should be called by udev itself on "remove". Kay -- To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html