LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 02-15-2009, 01:31 PM   #1
janfranken
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Rep: Reputation: 0
USB flash disk read problems using udev rules


Hello, I have the following problem:

I create a rule to launch an application when my USB flash disk is inserted:
ACTION=="add", KERNEL=="sd?1", ATTRS{removable}=="1", MODE="0666", RUN+="/usr/bin/application $env{ID_FS_LABEL} &"

The application then runs a usb_detect.sh script that must copy the files from the USB disk to the local disk.
popen(“usb_detect.sh device_id &”, "r");


The script executes but for some reason it is unable to copy any files from the USB disk. It can’t even read a filename from the USB disk.

When I run the application from terminal (instead of using udev rules) then everything works fine, the usb_detect.sh script can read and copy the files from the USB disk.

Any idea why the usb_detect.sh script can’t read any files from the USB disk when using udev rules, but works when using terminal?

Thank you.
 
Old 02-16-2009, 09:15 AM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
There might be a couple of issues I can think of - for one, udev is effectively suspended while a RUN action is being performed, so if your script takes too long there might be issues. You could detach the script to fix it.

Another might be that there's no way that I know of to get output - perhaps your script is writing to stdout, but gets a broken pipe error?

Maybe you could post your usb_detect.sh script, and that might help
 
Old 02-16-2009, 12:02 PM   #3
janfranken
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Smile

Thanks for the reply...

The usb_detect.sh script calls the actual copy script as shown below:
./copy.sh $disk_label

The copy script is quite involved, since it does a lot of other things as well. I don't think it will help that much.

I think the problem lies somewhere in the fact that udev somehow holds the system back as you explained.

Thank you anyway, I will try some work around...

Jan (South Africa)
 
Old 02-16-2009, 12:27 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
The application then runs a usb_detect.sh ... [snip] ... The script executes but for some reason it is unable to copy any files from the USB disk. It can’t even read a filename from the USB disk.
My suggestion: Have "The application" run usb_detect.sh and redirect the errors from that script to a logfile. Then look at the logfile, it should tell you what failed or was broken.

Quote:
The usb_detect.sh script calls the actual copy script as shown below:
./copy.sh $disk_label
I note you are using a relative PATH here. How are you sure the relative path is correct? Try replacing all relative paths in scripts with absolute ones Eg /full/path/to/copy.sh rather than ./copy.sh
 
Old 02-17-2009, 11:28 AM   #5
janfranken
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Smile

Hi,

I redirected the errors to a text file.

The output error says "no such file or directory".

Running the same thing from terminal doesn't give such an error.

So the script is ok, but the USB device is unreadable.

It could be that the device is not mounted when the rule is activated. I

have tried to use & when calling scripts to try and "release" udev but it doesn't help.

Thanks.
Jan.
 
Old 02-17-2009, 12:31 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
The output error says "no such file or directory".
I don't wish to appear unduly critical, but error messsages are usually a little bit more helpful:
Code:
tred@vaio:~$ ls /foo/bar
ls: cannot access /foo/bar: No such file or directory
tred@vaio:~$
So, what is / are your exact errors?

I still think you have a path problem: When you wrote those scripts maybe you assumed that they'd be called from ~ because they work when you call them from there.

When udev runs them they will be being called from somewhere else and not by the user janfranken. Think about this.

Maybe, just before your script fails with "file not found", insert a
Code:
echo scriptname is in the directory $(pwd) and about to execute the next command, which fails  >> logfile
which may give you some insight.

Or maybe insert
Code:
echo this is what's mounted right now >> logfile
mount >> logfile
the_line_that_fails
You could post your script(s) here. Please post the name of the script, and the full path to it, and its contents, like this:

Code:
cat /home/jan/copy.sh
script2 &
asd
asdasd
asdasd
etc

cat /home/jan/script2
more commands
etc


If they are long you could put them all in one post here: http://rafb.net/paste/terms.html (only good for 24Hrs though) then we'd have a better idea of what it is you are trying to do, and maybe why it isn't working for you.
 
Old 02-18-2009, 06:33 PM   #7
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
i think it has to be done on hal level which is the one mounting .
Udev creates the dev when it gets an event from the kernel.it then sends a dbus message to a listener that might mount it.
For fun, i wanted to have a sound when a usb stick was inserted like on windows, i changed an hal policy IIRC. I might have a backup somewhere, i'll post back. It took me ages to make it work..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB flash disk somehow gets read-only exenon Linux - Hardware 6 01-09-2009 08:08 AM
USB flash disk somehow gets read-only exenon Ubuntu 1 01-08-2009 03:08 PM
Multiple External camera flash memory card readers, udev rules best way? Old_Fogie Slackware 1 11-02-2006 06:18 AM
Usb flash disk read-only problem Darthomir Linux - Hardware 6 04-03-2004 09:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration