udev considerations: usb-storage script and $REMOVER problem
Hi.
I use kernel 2.6.11, udev 054 and hotplug-2004_09_23.
My hotplug scripts for a digital camera (usb-storage) worked well in 2.4.x series, but stoped working in 2.6. Yesterday I put my mind in trying to figure out what the problem was. Its not the kernel but udev.
I have a /etc/hotplug/usb/my.usermap file for my camera, that executes a script that mounts the storage device and places a link from $REMOVER env var to a script that simply unmounts the storage device.
The problem was that when usb.agent executed the script, udev had not yet created the device and mount failed.
Since I suck at bash scripting, I made a simple ugly-but-working-script that checks if the device exists and executes the commands. Also has a retry time out.
Would be nice if hotplug could handle this management somehow...
________________________________
#!/usr/bin/perl -w
system "logger -t Hotplug Mounting Fuji";
my $ret = 0;
my $retry = 0;
while ($retry < 10 && !$ret ){
if ( -e '/dev/sda1' ){
$ret = 1
}
else{
system "logger ...sleeping $retry";
sleep 1;
$retry++;
}
}if ( $ret ){
system "mount /mnt/fuji-f401";
system "logger -t Hotplug REMOVER script: $ENV{REMOVER}";
system "ln -s /etc/hotplug/usb/fuji401-remove $ENV{REMOVER}";}
else{
system "logger Fuji mount script failed";
}________________________________
Afterwards, the mount script worked ok. But when I turned off the camera, the shutdown script didn't. Digging a bit more I found that the error was here:
REMOVER=/var/run/usb/$(readlink -f $SYSFS/$DEVPATH | sed -e 's;/;%;g')
Since udev removed the device from the system before the hotplug executed the script, readlink returned an empty string and the script was not found.
I changed this line to:
REMOVER=/var/run/usb/$(echo $SYSFS/$DEVPATH | sed -e 's;/;%;g')
and now all works ok.
I saw in the mailing list some references to this readlink problem, but was not clear to me if this was a bug or a feature.
Hope this helps.
Thanks
Signature · 13 lines
Pedro Alves [email protected] ------------------------------------------------------- This SF.Net email is sponsored by: New Crystal Reports XI. Version 11 adds new functionality designed to reduce time involved in creating, integrating, and deploying reporting solutions. Free runtime info, new features, or free trial, at: http://www.businessobjects.com/devxi/728 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel