linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pedro Alves <pedro.alves@zmail.pt>
To: linux-hotplug@vger.kernel.org
Subject: udev considerations: usb-storage script and $REMOVER problem
Date: Wed, 20 Apr 2005 19:11:27 +0000	[thread overview]
Message-ID: <20050420191127.GA3092@zmail.pt> (raw)



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

                 reply	other threads:[~2005-04-20 19:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050420191127.GA3092@zmail.pt \
    --to=pedro.alves@zmail.pt \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).