LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Suse/Novell
User Name
Password
Suse/Novell This Forum is for the discussion of Suse Linux.

Notices



Reply
 
Search this Thread
Old 04-25-2012, 03:29 PM   #1
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Rep: Reputation: Disabled
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!
 
Old 04-25-2012, 04:16 PM   #2
Erfankam
Member
 
Registered: Jun 2011
Location: Tehran, Islamic Repulic of, Iran
Distribution: Ubuntu, Arch, Suse
Posts: 32

Rep: Reputation: 13
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.
 
Old 04-25-2012, 10:04 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
udev runs as root and does not, by default, have access to desktop sessions.

Two things need to be done:
  1. The desktop user needs to give permission for other users on the local host to access their desktop.
  2. The script needs the DISPLAY variable set.

For the first, one way for bash users to do it is to have this in ~/.bash_profile:
Code:
[[ $DISPLAY ]] && /usr/bin/xhost +localhost
For the second, on a single user system (so only one X display running) the script needs something like this:
Code:
export DISPLAY='localhost:0.0'
 
Old 04-26-2012, 02:22 AM   #4
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-26-2012, 02:44 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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.
 
Old 04-27-2012, 04:27 AM   #6
Erfankam
Member
 
Registered: Jun 2011
Location: Tehran, Islamic Repulic of, Iran
Distribution: Ubuntu, Arch, Suse
Posts: 32

Rep: Reputation: 13
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.
 
Old 04-30-2012, 01:02 PM   #7
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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'
code from the bash script.
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'
, and the script ran as I expected.
So, thank you very much again!
 
1 members found this post helpful.
Old 04-30-2012, 10:36 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Glad you solved it and thanks for sharing the solution
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Running a python script on multiple files ManyouRisms *BSD 7 06-01-2011 05:49 AM
[SOLVED] Chose udev for services... udev starts twice... hotplug fails flipjarg Linux - Newbie 2 09-19-2010 01:49 PM
Error while running a python-ogre script konqi Programming 4 01-03-2008 01:43 PM
Running script (probably python) Bob Jones Linux - Software 1 09-29-2007 02:20 AM
udev rules - running script OllieGator Linux - Software 4 03-29-2007 07:44 AM


All times are GMT -5. The time now is 02:33 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration