swaywm / swaylock

Screen locker for Wayland
MIT License
853 stars 202 forks source link

Multiple instances of swaylock #314

Closed mvasi90 closed 9 months ago

mvasi90 commented 1 year ago

Hello everyone.

I'm using Hyperland. I have two sessions opened. user1 on tty1 and user2 on tty2 (without display manager). I need to work concurrently with two accounts (developer and normal user).

When I'm in the tty2 (user2), I can suspend the system and resume it. Also I can wait 30 seconds for auto-suspend. Everything works well.

The problem is when I switch to user1 (tty1). After 30 seconds, I see two swaylock instances:

56767 swaylock -f
56768 swaylock -f

I added the condition if ! -x pgrep swaylcok; ... but the same thing happens.

This is my testing configuration:


exec-once = swayidle -w timeout 5 'if pgrep -x swaylock; then hyprctl dispatch dpms off; fi' resume 'hyprctl dispatch dpms on' 

exec-once = swayidle -w timeout 10 'hyprctl dispatch dpms off' timeout 20 'if ! pgrep -x swaylock; then swaylock -f; fi' timeout 30 'systemctl suspend -i' resume 'hyprctl dispatch dpms on' before-sleep 'if ! pgrep -x swaylock; then swaylock -f; fi'
mvasi90 commented 1 year ago

Same result after changing the last line to:

exec-once = swayidle -w timeout 10 'hyprctl dispatch dpms off' timeout 20 'if ! pgrep -x swaylock; then swaylock -f; fi; date >> /home/developer/test' resume 'hyprctl dispatch dpms on' before-sleep 'if ! pgrep -x swaylock; then swaylock -f; fi'

Note: /home/developer/test contains a single line. It runs once. Note2: The first user (user1, tty1) does not have any swayidle and swaylock setting.

Why are there two instances of swaylock? is it swaylock itself that forks?

kennylevinsen commented 1 year ago

If you use latest swaylock release and hyprland supports ext-session-lock, or use swaylock master which requires the protocol, then there is no need for any pgrep or kill tricks. Only the first swaylock isntance will be allowed to start, so you can call it freely.

is it swaylock itself that forks?

swaylock forks a child for password validation. It also forks for daemonization when you pass the -f argument.

emersion commented 9 months ago

swaylock forks and uses a separate process to check the password. It's expected that two swaylock processes are running per swaylock instance.