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. |
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 :) |
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) |
Quote:
Quote:
|
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. |
Quote:
Code:
tred@vaio:~$ ls /foo/bar 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 Or maybe insert Code:
echo this is what's mounted right now >> logfile Code:
cat /home/jan/copy.sh 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. |
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.. |
All times are GMT -5. The time now is 02:01 PM. |