[mythtv-users] X dpms problem SOLVED

Robin Gilks g8ecj at gilks.org
Sun Jun 8 22:47:31 UTC 2008

> I'm having problems getting the dpms line in my power on/off script (see
> below) to work!!
> If I run the script from a telnet session its OK, if I run it from an
> xterm in the same X session as MythTV it runs OK but if the script is run
> by irexec (as a result of me pressing the Power button on the remote) it
> doesn't seem to do anything.
> I guess this is something to do with irexec being run as a service and
> hence run by root so something is missing from the environment but even
> putting the '-display' option into the xset command as "xset -display :0
> dpms force off" I don't get anywhere. I've also tried exporting the
> DISPLAY variable at the start of the shell script and I've tried it in
> short and long form (i.e. as :0 and as hostname:0).
> More ideas required:-)
> #!/bin/sh
> AMP=rm-aap013
> FILE=/home/mythtv/.power
> DEV=/dev/lircd1
> DATE=`date +%s`
> # Use the presense of a flag file to see if we are powering up or down
> if [ -e $FILE  ]
> then
> LAST=`cat $FILE`
> # ignore unless at least 10 seconds has passed  this stops a keybounce
> # from turning us off straight after a turn on
> if [ $(($LAST + 10)) -lt $DATE ]
> then
> # power down - just blindly do it
> /usr/bin/xset dpms force off
> # the amp needs the code repeated to get it to work - handled by repeat
> value in the conf file
> /usr/bin/irsend -d $DEV SEND_ONCE $AMP A_power
> /bin/rm -f $FILE
> fi
> else
> # power up and select the correct input on the amp
> /usr/bin/xset dpms force on
> /usr/bin/irsend -d $DEV SEND_ONCE $AMP A_dvd
> /usr/bin/irsend -d $DEV SEND_ONCE $AMP A_dvd
> /usr/bin/irsend -d $DEV SEND_ONCE $AMP A_dvd
> echo $DATE > $FILE
> fi

Well not so much solved as working now...

My assumption that irexec was running as root was wrong. The init script
that starts it in daemon mode runs it as a normal user (mythtv as it
happens). By SUIDing the power on/off script as root I was actually making
it worse as the root user is not allowed to connect to the X server.

What I ended up doing was using
   su mythtv -c '/usr/bin/xset dpms force on|off'
having started the irexec process as root.

Why that should work but running without the 'su' in the script and
running irexec as the mythtv user in the first place sure beats me. At
least it works now...

If anyone can explain what is going on I'd appreciate it - maybe something
to do with the root user spawning a process with a different uid misses
something out?


Robin Gilks

More information about the mythtv-users mailing list