You are not logged in.

#1 2019-03-21 04:54:24

electric-ladyland
Member
Registered: 2018-12-12
Posts: 9

Service for lock on suspend shows screen momentarily on resume

Apologies in advance if this is answered already, but I cannot find a solution.

I have a service as follows:

[Unit]
Description=lock on suspend
Before=suspend.target

[Service]
User=xyz123
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock
ExecStartPost=/usr/bin/sleep 2

[Install]
WantedBy=suspend.target

This is supposed to lock the screen when suspending.

The issue is that on resume, the unlocked screen shows briefly (1 second or less) before the lock starts.

I understood this to be an issue that the ExecStartPost sleep is supposed to work around, where the lock doesn't have time to start before suspend.

But in this case the ExecStartPost sleep doesn't seem to have any effect on this.

What information can I show to help debug this? Here I try to pick out the relevant journalctl entries (not sure if safe to post all the output):

Suspend started:

Mar 21 01:36:07 hp NetworkManager[588]: <info>  [1553142967.1010] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Mar 21 01:36:07 hp NetworkManager[588]: <info>  [1553142967.1011] manager: NetworkManager state is now ASLEEP
Mar 21 01:36:07 hp systemd[1]: Reached target Sleep.
Mar 21 01:36:07 hp systemd[1]: Starting Suspend...
Mar 21 01:36:07 hp systemd[1]: Starting lock on suspend...
Mar 21 01:36:07 hp systemd-sleep[24740]: Suspending system...

Resume started:

Mar 21 01:36:15 hp ntpd[615]: Deleting interface #29 wlo1, fe80::1437:f529:66cd:fe16%3#123, interface stats: received=0, sent=0, dropped=0, active_time=690 secs
Mar 21 01:36:15 hp systemd[1]: lock_suspend.service: Succeeded.
Mar 21 01:36:15 hp audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=lock_suspend comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? t>

Since it shows that lock_suspend.service succeded AFTER suspend, the problem must be ExecStartPost has no effect... How come?

Offline

#2 2019-03-21 10:24:59

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: Service for lock on suspend shows screen momentarily on resume

This works for me:

# /etc/systemd/system/resume@.service
[Unit]
Description=Lock the screen on resume

[Service]
User=%i
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

[Install]
WantedBy=suspend.target sleep.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

No need for Before=suspend.target or the ExecStartPost delay.


Jin, Jîyan, Azadî

Offline

#3 2019-03-21 17:48:58

electric-ladyland
Member
Registered: 2018-12-12
Posts: 9

Re: Service for lock on suspend shows screen momentarily on resume

Thanks for reply. I tried your service, I still get a brief glimpse of my screen on resume. You don't see that at all? What command are you using to suspend? I'm now wondering if there's some other setting forcing too quick suspend, maybe I need a delay somehow.

Offline

#4 2019-03-21 17:51:32

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: Service for lock on suspend shows screen momentarily on resume

electric-ladyland wrote:

I still get a brief glimpse of my screen on resume. You don't see that at all?

I do see a (very) brief flash of the screen if I use systemctl suspend from the command line (and then press the power button to resume) but I don't see that at all if I suspend the machine by closing the laptop lid and then open it.

Last edited by Head_on_a_Stick (2019-03-21 17:51:49)


Jin, Jîyan, Azadî

Offline

#5 2019-03-21 18:27:48

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,426

Re: Service for lock on suspend shows screen momentarily on resume

Instead of adding a postdelay, what about blanking your screen in an ExecStartPre= e.g.

ExecStartPre=/usr/bin/xset dpms force suspend

Offline

#6 2019-03-21 19:36:46

electric-ladyland
Member
Registered: 2018-12-12
Posts: 9

Re: Service for lock on suspend shows screen momentarily on resume

Good idea, still see the screen flash. It's like the suspend is just forced regardless of the hooks. Worst case workaround I can use a suspend wrapper that locks the screen then suspends, but I don't like this as I don't trust that wrapper will always be used. Thanks.

Offline

Board footer

Powered by FluxBB