From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Williams Date: Wed, 23 May 2001 00:44:45 +0000 Subject: Re: Hotunplug MIME-Version: 1 Content-Type: multipart/mixed; boundary="==_Exmh_407786057430" Message-Id: List-Id: To: linux-hotplug@vger.kernel.org This is a multipart MIME message. --==_Exmh_407786057430 Content-Type: text/plain; charset=us-ascii I've made a go at implementing support for hot unplug in the hotplug scripts. What I have done is calculated a path to a "remover" program that is passed as the REMOVE environment variable to the existing add scripts. If the add script wants to make something happen when the device is removed, it writes something to the remover and marks it executable. The hotplug scripts' response to this is to run the remover when the device is pulled. So this is the hotplug script for my device. It is called on add, and creates a remover to remove the symbolic link, like so: case "$PRODUCT" in 547/2235/*) exec /usr/sbin/gflashd -I /usr/share/gflash/aa55.ihx ;; 12c5/*/*) echo 'rm -f /var/run/gflash.lnk' > $REMOVER chmod u+x $REMOVER exec /usr/sbin/gflashd -m 0666 -L/var/run/gflash.lnk ;; esac (The first case is loading the firmware, so a renumeration is about to happen and the link is not ready to be created.) I tested it on my system, and the good news is this that remove is very fast. I pull the device and the /var/run/gflash.lnk goes away right away. This is *exactly* what I want. So I've attached a patch to the CVS version , for your critical review. It's surprisingly small. -- Steve Williams "The woods are lovely, dark and deep. steve@icarus.com But I have promises to keep, steve@picturel.com and lines to code before I sleep, http://www.picturel.com And lines to code before I sleep." --==_Exmh_407786057430 Content-Type: application/x-patch ; name="usb-remove.patch" Content-Description: usb-remove.patch Content-Disposition: attachment; filename="usb-remove.patch" Index: etc/hotplug/usb.agent =================================================================== RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/usb.agent,v retrieving revision 1.12 diff -u -r1.12 usb.agent --- etc/hotplug/usb.agent 2001/04/24 15:07:33 1.12 +++ etc/hotplug/usb.agent 2001/05/23 00:35:47 @@ -18,6 +18,14 @@ # DEVFS=/proc/bus/usb # DEVICE=/proc/bus/usb/%03d/%03d # +# This script then adds the variable: +# +# REMOVER=/var/run/usb/ +# +# This is the path where the script would like to find a remover, if +# the target device needs one. This script is executed on remove if +# it is executable when the remove happens. +# # If usbdevfs is mounted on /proc/bus/usb, $DEVICE is a file which # can be read to get the device's current configuration descriptor. # (The "usbmodules" utility helps do that.) @@ -269,6 +277,11 @@ done } +# +# declare a REMOVER name that the add action can use to create a +# remover, or that the remove action can use to execute a remover. +# +declare -rx REMOVER=/var/run/usb/`echo $DEVICE | sed -e 's;/;%;g'` # # What to do with this USB hotplug event? @@ -281,6 +294,10 @@ FOUND=false LABEL="USB product $PRODUCT" + if [ -e "$REMOVER" ]; then + rm -f "$REMOVER" + fi + # on 2.4 systems, modutils 2.4.2+ maintains MAP_CURRENT # ... otherwise we can't rely on it (sigh) case "$KERNEL" in @@ -320,6 +337,13 @@ exit 2 fi + ;; + +remove) + if [ -x $REMOVER ]; then + $REMOVER + fi + rm -f $REMOVER ;; *) Index: etc/hotplug/usb.rc =================================================================== RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/usb.rc,v retrieving revision 1.8 diff -u -r1.8 usb.rc --- etc/hotplug/usb.rc 2001/03/22 04:52:56 1.8 +++ etc/hotplug/usb.rc 2001/05/23 00:35:47 @@ -134,6 +134,11 @@ return 1 fi + # Create a directory to hold remover programs. Close it up so + # that only hotplug scripts can write to this directory. + mkdir /var/run/usb + chmod 0700 /var/run/usb + # hotplug events didn't fire during booting; # cope with devices that enumerated earlier # and may not have been fully configured. --==_Exmh_407786057430-- _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel