lunes, 4 de mayo de 2015

ScreenLock on Jessie's systemd

Something I was used to and which came as standard on wheezy if you installed acpi-support was screen locking when you where suspending, hibernating, ...

This is something that I still haven't found on Jessie and which somebody had point me to solve via /lib/systemd/system-sleep/whatever hacking, but that didn't seem quite right, so I gave it a look again and this time I was able to add some config files at /etc/systemd and then a script which does what acpi-support used to do before

Edit: Michael Biebl has sugested on my google+ post that this is an ugly hack and that one shouldn't use this solution and instead what we should use are solutions with direct support for logind like desktops with built in support or xss-lock, the reasons for this being ugly are pointed at this bug

Edit (2): I've just done the recommended thing for LXDE but it should be similar for any other desktop or window manager lacking logind integration, you just need to apt-get install xss-lock and then add @xss-lock -- xscreensaver-command --lock to .config/lxsession/LXDE/autostart or do it through lxsession-default-apps on the autostart tab. Oh, btw, you don't need acpid or the acpi-support* packages with this setup, so you can remove them safely and avoid weird things.

The main thing here is this little config file: /etc/systemd/system/screenlock.service

[Unit] Description=Lock X session Before=sleep.target [Service] Type=oneshot ExecStart=/usr/local/sbin/screenlock.sh [Install] WantedBy=sleep.target

This config file is activated by running: systemctl enable screenlock

As you can see that config file calls /usr/local/sbin/screenlock.sh which is this little script:

#!/bin/sh # This depends on acpi-support being installed # and on /etc/systemd/system/screenlock.service # which is enabled with: systemctl enable screenlock test -f /usr/share/acpi-support/state-funcs || exit 0 . /etc/default/acpi-support . /usr/share/acpi-support/power-funcs if [ x$LOCK_SCREEN = xtrue ]; then . /usr/share/acpi-support/screenblank fi

The script of course needs execution permissions. I tend to combine this with my power button making the machine hibernate, which was also easier to do before and which is now done at /etc/systemd/logind.conf (doesn't the name already tell you?) where you have to set: HandlePowerKey=hibernate

And that's all.

5 comentarios:

Vincent Bernat dijo...

You may want to have a look at "xss-lock" instead.

Unknown dijo...

This works in GNOME and I think it works in the other desktop environments. I guess that you are using a custom X session instead?

The modern way to get notifications of suspend in a user session is to talk to logind over D-Bus (http://freedesktop.org/wiki/Software/systemd/logind/). Anything that relies on global hook scripts is going to be a bit of a hack (and insecure on a multi-user system).

Santiago García Mantiñán dijo...

I did this for lxde on which, at least by default, locking doesn't work.

I have edited the original entry to mention xss-lock and built-in logind support.

I'd really love to see a solution for lxde which on a google search seems to have support for this, I wonder what I'm missing.

dmr dijo...

I had the same issue after upgrading and used xss-lock. However, I had some trouble with high CPU use by xss-lock after X restart; I had to apply this patch to get it to work properly: https://bitbucket.org/raymonad/xss-lock/commits/2627bce23e9919203f45f4b02c228e4c60a1699b

Now it works fine.

Will try the systemd solution soon.

Florian Strankowski dijo...

Hi, can you please care about bridge-utils? I've prepared a fix for a bug i posted:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=783956

Thanks!