scripts: Fix powermenu log out without elogind

On my current voidlinux system I have no access to elogind and riverwm
will just be restarted when I exit it (since it is watched over by a
user service).

My session is started by the display manager 'greetd' (which in turn
runs tuigreet but that is not important here). So, to log out of the
session - we do a search for the 'greetd' process and if we find it we
search its _child_ processes which are the ones that we can kill without
being a super user.

If we kill the right process here, the session will close (since the
'watched' process exits and greetd just takes over again). This would be
a little easier if we started riverwm through greetd directly but I like
this indirection for stability (automatic service restarts), flexibility
(I can stop the riverwm service independent of my session), and adaption
(we can use Turnstile environment variables between my session
services).

So we just close all the processes that are children of greetd --
perhaps we accidentally catch a process which is _not_ the root session
process run by greetd but we'll kill it nevertheless since all child
processes might stop greetd from taking over (and they would be closed
anyway when ending the session afaik).

I have no linger enabled on my system so far (user processes staying
enabled after log-out) and I do not know how that would interact with
this method.
This commit is contained in:
Marty Oehme 2025-03-07 14:20:01 +01:00
parent 554e13cd36
commit 47a96a2d42
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -85,6 +85,11 @@ case "$result" in
if [ -n "$POWERMENU_LOGOUT_CMD" ]; then eval "$POWERMENU_LOGOUT_CMD"; else
command -v i3 >/dev/null 2>&1 && i3-msg exit
command -v riverctl >/dev/null 2>&1 && riverctl exit
# Try to heuristically find the program started by greetd and shut it down.
# Generally this will just be a 'pause' program on my system.
if command -v pgrep >/dev/null 2>&1 && pgrep greetd; then
kill $(pgrep -P "$(pgrep greetd | tr '\n' ',')" pause)
fi
fi
;;
"Suspend" | "$suspend_btn")