You are not logged in.

#1 2023-05-21 21:39:39

VDmvKcW9JamBSir5fNfehqpG
Member
From: Earth
Registered: 2019-12-30
Posts: 59

[SOLVED] How do I determine what is screen-locking my system?

For the past few weeks, my system has been screen locking itself when it shouldn't. However, lately it got more annoying, so I'm trying to fix it. The behavior I want is:

* After 15 minutes of being idle or when the lid is closed, it should go to sleep if there is no inhibitor in effect. If there is an inhibitor in effect, it should lock the screen.
* The screen should be guaranteed to be locked when the laptop wakes up from suspend. Taking a few seconds for the screen locker to appear is not acceptable.
* The screen should NOT be locked when the laptop resumes from hibernation (even if it was locked before), because the drive is encrypted and I don't want to enter a password twice.

I'm using Sway, with swayidle and swaylock. In order to implement most of this, I have the following in my config files:

    * ~/.config/sway/config

exec swayidle -w

    * ~/.config/swayidle/config

lock 'guake --hide; swaylock; pkill -SIGRTMIN+1 waybar'
unlock 'killall -USR1 swaylock; pkill -SIGRTMIN+1 waybar'
before-sleep 'loginctl lock-session'
timeout 900 'systemctl suspend || loginctl lock-session'

    * /etc/systemd/system/unlock-after-hibernate.service

[Unit]
Description=Unlock the system after hibernating to avoid having to enter the password twice
After=hibernate.target

[Service]
ExecStart=loginctl unlock-sessions

[Install]
WantedBy=hibernate.target

Previously, that covered everything except for:
* Locking the screen if the lid was closed with an inhibitor in effect, which I have not yet figured out a reasonable way to do.
* Guaranteeing that the screen is locked immediately upon resume from suspend. It seemed to *usually* work, but sometimes be unlocked for a split second. If I add a sleep command to the before-sleep line, it seems to just make it take longer to suspend, but not change the chance of it being unlocked for a split second upon resume.

However, a few weeks ago, with no changes to my config, this started misbehaving. The most annoying issue is that my screen is locking when it shouldn't. However, it does not seem to be completely random. There seems to be a few things that trigger it:
* Mounting or unmounting a drive seems to always do it if it's a LUKS-encrypted drive. If it's an unencrypted drive, it usually won't do it, but sometimes will.
* A web scraping task that I'm currently running manually whenever I feel like it, which invokes systemd-inhibit to prevent the laptop from sleeping, might lock the system when starting and might lock the system when ending. (It seems like these are independent events. Locking the system when starting does not necessarily mean it will lock when finishing and vice versa.)
* When resuming from suspend, the system is sometimes immediately locked again once I unlock it, and I have to unlock it 2 or 3 times to actually use it.
* When resuming from hibernate, the system appears to never be unlocked even though unlock-after-hibernate.service runs successfully, so I think it's immediately getting re-locked. Once I unlock, the laptop goes to sleep. (Then, as described above, I might only have to unlock it once, or I might have to unlock it 2 or 3 more times.)

When an undesired lock happens, nothing that appears to be about locking or unlocking appears in journalctl -x. And when I tried to lock manually to see what I should be looking for, it didn't work and I got

polkitd[794]: Unregistered Authentication Agent for unix-process:1137909:15278889 (system bus name :1.32388, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)

When an undesired suspend happens, all I see is

systemd-logind[734]: The system will suspend now!

but nothing about *why* it's suspending. Where should I even begin with troubleshooting this?

Last edited by VDmvKcW9JamBSir5fNfehqpG (2023-05-25 21:38:23)

Offline

#2 2023-05-22 15:02:13

VDmvKcW9JamBSir5fNfehqpG
Member
From: Earth
Registered: 2019-12-30
Posts: 59

Re: [SOLVED] How do I determine what is screen-locking my system?

Just had an infinite loop of unlocking the screen after resuming from hibernate this morning. Had to switch to another tty and unlock from there with loginctl unlock-session 1.

Offline

#3 2023-05-22 15:49:57

seth
Member
Registered: 2012-09-03
Posts: 49,947

Re: [SOLVED] How do I determine what is screen-locking my system?

Online

#4 2023-05-25 16:14:55

VDmvKcW9JamBSir5fNfehqpG
Member
From: Earth
Registered: 2019-12-30
Posts: 59

Re: [SOLVED] How do I determine what is screen-locking my system?

Sorry for taking so long to reply, but following the recommendations there (disabling logind's handling of buttons and lid switch, do the button/switch handling myself within the sway config, just invoke/kill swaylock rather than loginctl with swayidle) has fixed the issues I was having. Additionally, I was able to easily make the laptop lock when closed even when suspend is inhibited, it seems like locking before suspend is guaranteed now, suspend seems to happen faster, and I managed to add a warning when I press the suspend key while the action is inhibited.

I have noticed that the power button doesn't show up in wev, and things bound to it do not work. This is not a real problem for me because I never use that (always either the lid or occasionally the suspend key), but it is worth mentioning. Also, applications that try to do things when I lock (such as keepassxc locking the database when the system is locked) now no longer do so. I assume this is because they were listening for logind events. Is it OK to put loginctl lock/unlock in the config to make keepassxc respond to locking, even if I have swaylock/swayidle ignore it? Or would that break things again?

Offline

#5 2023-05-25 19:59:51

seth
Member
Registered: 2012-09-03
Posts: 49,947

Re: [SOLVED] How do I determine what is screen-locking my system?

I've no idea, you'll have to try
But make sure that swaylock doesn't respond to systemd lock because otherwise you might cause a recursion.

Online

#6 2023-05-25 21:38:06

VDmvKcW9JamBSir5fNfehqpG
Member
From: Earth
Registered: 2019-12-30
Posts: 59

Re: [SOLVED] How do I determine what is screen-locking my system?

OK, I see no sign of anything bad happening. I will mark this as solved.

Offline

Board footer

Powered by FluxBB