You are not logged in.

#1 2012-04-15 07:45:49

spikeh
Member
Registered: 2012-04-14
Posts: 33

[SOLVED] acpid - Catch button/lid close and locking the screen

Hello,

I'm trying to get acpid's handler.sh to catch lid closure and locking the screen. I'm running Gnome Shell. The relevant snippet adapted from the acpid wiki in my handler.sh is shown below:

    button/lid)
        case "$3" in
            close)
                # Screen on/off handled by BIOS.
                gss=$(ps up $(pidof gnome-screensaver) | awk '/gnome-screensaver/ { print $1 }')
                logger $gss
                # /usr/sbin/pm-suspend
                su $gss -c "gnome-screensaver-command -l"
                ;;
        esac
        ;;

handler.sh is definitely catching "button/lid LID close", as $gss (containing my username) is indeed logged to /var/log/messages.log. But the `su $gss -c "gnome-screensaver-command -l"` line isn't working! If I uncomment the pm-suspend line and comment the gnome-screensaver-command line, the machine correctly suspends to RAM. If I run `su spikeh -c "gnome-screensaver-command -l"` as root in terminal, the machine correctly locks the screen.

I'm really baffled by this! Can anyone see a problem with my code?

Edit: It seems like I need to define the DISPLAY env var for root to specify the screen to lock before running gnome-screensaver-command!

DISPLAY=:0.0 su $gss -c "gnome-screensaver-command -l"

Last edited by spikeh (2012-04-15 08:13:03)


Thinkpad T420

Offline

#2 2012-04-15 08:11:11

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: [SOLVED] acpid - Catch button/lid close and locking the screen

Is acpi-handler.sh running as the same user that you use to perform the command manually? Are you sure it isn't hanging because su asks for a password? Sometimes su has unexpected behaviour because of environment variables. There's also "sudo -u $gss gnome-screensaver-command -l" that you could try.


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#3 2012-04-15 08:17:25

spikeh
Member
Registered: 2012-04-14
Posts: 33

Re: [SOLVED] acpid - Catch button/lid close and locking the screen

While I have resolved the issue, I appreciate your post ConnorBehan.

I believe `su spikeh -c "gnome-screensaver-command -l"` worked for me in terminal because DISPLAY is already set when I su to root, so you're right that su didn't behave how I expected because of env vars.


Thinkpad T420

Offline

Board footer

Powered by FluxBB