Skip to contentSkip to conversation

It just works - USB removal script suggestion/patch

DISCUSSION Dan Gray 2 participants 3 messages Jun 2, 2005

lore
Share & tools
lore

Dan Gray

author
#0 lore raw

Hi,
I've been playing around with hotplug for a while now and am not entirely happy with the way that usb.agent handles removal requests.
The documentation is fairly wooly on the subject, and initially it appears as though the $ACTION received by the specified agent script can be one of 'add' or 'remove' - this is of course not the case (as far as I can see). While we should all RTFM this required a trawl through the source and the skills of an experianced user. This patch is aimed at 'Desktop Linux' where a user would presumably have admin rights but not necessarily alot of experiance and may need a clear model within which to place the necessary removal script without playing with the hotplugging 'base' scripts and damaging the system.

So I tracked down the /var/run/usb/ based 'remover' script and the system works very well. I think that there is a problem however with the functionality of this system for the non-skilled user, in that the name for the script is not intuitive and it must be created every time that the usb device is inserted (if the script is trivial that a simple 'echo' from the insertion script can do it, if non-trivial a script must be copied from elsewhere), this seems over complicated and, should a user wish to create a removal script, it requires that they edit the agent script in /etc/hotplug/usb/ directly, hardly desirable.

The last few months we've been hearing alot about 'it just works', and trying to simplify some of linux' functions and so heres my proposition as a patch to usb.agent:

---------------------------
< basicVendor=$1
< basicProduct=$2
<
379d373
<
443,459d436
<
< usb_convert_vars
<
< # Since the 'remover' function is a little obscure and requires a user < # to delve into a few levels of code we add the possibility to add a < # simple script named after a devices vendorID and productID to < # the directory /etc/hotplug/removers/. If present and executable < # this script runs on product removal. Less elegant perhaps, but < # much, much simpler and possible for a user to fathom, extracting the < # corrent Vendor and Product ID from a simple 'dmesg'.
<
< if [ -f /etc/hotplug/removers/$basicVendor:$basicProduct ]; then
< if [ -x /etc/hotplug/removers/$basicVendor:$basicProduct ]; then
< /etc/hotplug/removers/$basicVendor:$basicProduct
< fi
< fi
<
------------------

As you can see, we can create an additional removel script in /etc/rc.d/usb/removers/ named for the device in question (i.e. /etc/rc.d/usb/removers/66f:4100 ) which, if present and executable will be called whenever the device is removed. This method, while not as elegant as the existing solution is an addition to it and removes the need for a user to edit any configuration scripts other that that contained in '/etc/rc.d/usb/removers/', which presumably they wish to create in the first place. If a distro or user wishes to make use of the '/var/run/usb' remover functionality they are free to so but a user may simply use the file above to add any additional functionality without the risk of fubar'ing the system (although the script is still run with root permissions, and created with admin permissions, but I trust my meaning is clear).

Obviously the same can be done for the insertion case, but I didn't require that functionality and it will be trivial to add. I've not extended this to FireWire as I don't have a system to test it on.

What do you think? Any chance of getting this made 'official'???

Regards
Dan Gray

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw

Did you look into dbus/hal yet?
dbus/hal works in userspace and should do what you want :)

- Stefan

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

author
#2 lore raw
In reply to Dan Gray
Quoted 4 lines · You

Did you look into dbus/hal yet?
dbus/hal works in userspace and should do what you want :)

- Stefan

I did, but they present three problems:

First, it's an extra daemon/configuration burden

Second, the userspace function only works for processes you own. I wanted to kill irattach when I removed a USB dongle, hal/dbus would have needed additional configuration.

This just seems like a sensible, K.I.S.S. approach to the problem within the hotplug framework with no need for additional configuration. I'm thinking of patching my usb.agent to do the same for inserts. I have to say I even dislike the existing system of /etc/hotplug/usb scripts as it relies on a properly condigured usb map file which seems superfluous to most peoples needs (i.e Plug in a device, write a script with a unique name, put it in the right place, so again, no need to write/edit an additional file.)

Dan

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel