Udev fails running python script
Hi All!
I have a PC openSuSE 12.1 base and X11 installed on it. I use icewm as windowmanager. I wrote some udev rules that finds the attached USB keys, and runs a bash script. That bash script then starts a python script, that implements GUI interface for clamav, with Tkinter. The problem is that, the python script doesn't start clamav_scan. If I run the first bash script from console, everything works perfectly, but if it's started by udev, the clamav_scan doesn't start, but the bash and python script runs. Is there a special environment, where the udev runs, and this causes the failure? Or what else can be the problem? Thanks for replies! |
try use root privileges in your udev rules. I dont remember how could you use root privileges in udev. Use google. Also take a look at gksudo to use. Maybe you have not sufficient privilege to invoke gui from a scripts.
Thus Do proper actions by graphical root privileges. I hope it be useful for you. |
udev runs as root and does not, by default, have access to desktop sessions.
Two things need to be done:
For the first, one way for bash users to do it is to have this in ~/.bash_profile: Code:
[[ $DISPLAY ]] && /usr/bin/xhost +localhost Code:
export DISPLAY='localhost:0.0' |
wow, thanks for the fast replies!
Both of you are true, but my problem is not with the gui. The gui works fine, even if it's called from udev, but the clamav_scan program is not called from python. So, I plug in my USB key, udev realizes that, successfully starts the first bash script. That script mounts the new drive into a temporary directory, and starts the python script. The python script starts running, the window appears. At this point, the clamav_scan should start, and should scan the directory (the mounted USB key), and should display the results. But this last two steps never happens. Just these last two steps. If I mount the USB key manually, into the same temporary directory, and I start the bash script also manually, the python window appears, the clamav_scan starts scanning, and in the end, the window displays the results. Normally, the scanning lasts about 10 seconds (the key has 1 partition, ext3 fs, and 1, 342 byte sized file), and I've already waited for udev to scan the key for half an hour, but it didn't scan. |
When I tested the environment set by udev in a script run by udev the PATH was limited. It may be that your bash script is robust against that but the python script is not. It would do no harm to set the envars the scripts depend on in the scripts themselves. At least PATH and DISPLAY. Running env at the command prompt may suggest others.
|
Maybe catkin s right. but I suggest test your python program whether knowing proper path to look for a device. Also you can use 'findfs' tool to find your device mount point based on UUID or lable. You can pass UUID and mount point of new device as some arguments to your python script. I think there s some issue in your script.
Regards. |
Again Thank you all for the fast replies!
I found something strange in my code. I started the python script with Code:
su -c 'export DISPLAY=:0;xhost local:$USER;/usr/local/sbin/scandrive.py' This started the beginning of the python code (showed the GUI), but it didn't refer the other functions in the file. I changed the above code to Code:
su $USER -c 'export DISPLAY=:0; xhost local:$USER;/usr/local/sbin/scandrive.py' So, thank you very much again! |
Glad you solved it and thanks for sharing the solution :)
|
All times are GMT -5. The time now is 07:14 AM. |