* udev considerations: usb-storage script and $REMOVER problem
@ 2005-04-20 19:11 Pedro Alves
0 siblings, 0 replies; only message in thread
From: Pedro Alves @ 2005-04-20 19:11 UTC (permalink / raw)
To: linux-hotplug
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
--
Pedro Alves
pedro.alves@zmail.pt
-------------------------------------------------------
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
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-04-20 19:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-20 19:11 udev considerations: usb-storage script and $REMOVER problem Pedro Alves
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.