running lxde-logout on power button.

Please post all general support questions for LXDE here.
Locked
ajvogel
Posts: 1
Joined: Tue Jan 13, 2009 6:15 am

running lxde-logout on power button.

Post by ajvogel »

I recently installed lxde on my eee pc, and I must say that I am impressed.

I however have one nagging irritation. I am unable to get lxde-logout (or lxsession-logout) to run when pressing the power button. It seems that /etc/acpi/powerbtn.sh is run as root. I tried adding the following line to /etc/acpi/powerbtn.sh:

Code: Select all

sudo -u ajvogel lxde-logout


Any help would be greatly appreciated.
Cloudane
Posts: 1
Joined: Fri Apr 03, 2009 7:41 pm

Re: running lxde-logout on power button.

Post by Cloudane »

Bit late for this thread I guess, but just registered to answer this in case others were googling in circles like I was.

Linux from Scratch here and in my case lxde-logout wasn't working from the ACPI scripts because it didn't think there was an lxsession running. It determines this by looking for the _LXSESSION_PID environment variable, which as the name suggests holds the PID of the lxsession process. However as the ACPI script runs as root, it's not got the same environment.

It's a bit hacky (not quite as hacky as hard-coding your username like that hehe) but what I did was put the following command in the ACPI script:

Code: Select all

export _LXSESSION_PID=`pidof lxsession`
Before the call to lxsession-logout (or lxde-logout). I don't think it'd work in the case where you have multiple sessions running on different displays or something crazy like that, but in a fairly simple environment (especially one where you can get away with hard-coding your username) it's good enough.

If it helps, here is the full /etc/acpi/powerbutton.sh script that I use (I borrowed quite a bit from elsewhere... I think it was Ubuntu or Gentoo or some other -oo). I needed to substitute finger, which I can't find anywhere, with pinky, which apparently does the same thing.

Code: Select all

getXuser() {
       user=`pinky| grep -m1 ":$displaynum " | awk '{print $1}'`
       if [ x"$user" = x"" ]; then
               user=`pinky| grep -m1 ":$displaynum" | awk '{print $1}'`
       fi
       if [ x"$user" != x"" ]; then
               userhome=`getent passwd $user | cut -d: -f6`
               export XAUTHORITY=$userhome/.Xauthority
       else
               export XAUTHORITY=""
       fi
}

for x in /tmp/.X11-unix/*; do
   displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
   getXuser;
   if [ x"$XAUTHORITY" != x"" ]; then
       export DISPLAY=":$displaynum"
       export _LXSESSION_PID=`pidof lxsession`
       lxsession-logout
   fi
done
User detection ;) By setting the Xauthority variable to point to the currently logged in user's .Xauthority file, the command still runs as root but can put a window on the user's display. To run something as user, such as firefox, it'd be: su $user -c 'firefox'

I'm using SLiM, which doesn't report logins to utmp / wtmp by default (breaking the user detection) and so the following lines are required in slim.conf:

Code: Select all

sessionstart_cmd    /usr/bin/sessreg -a -l $DISPLAY %user
sessionstop_cmd     /usr/bin/sessreg -d -l $DISPLAY %user 
Locked