How can I reliably block GUI-initiated system shutdown when systemd-inhibit only delays terminal shutdown commands?
1
vote
0
answers
45
views
I'm developing a desktop application using PySide6 for Linux, and I need to prevent or delay system shutdowns that are initiated from the graphical interface. I know that running systemd-inhibit --what=shutdown --who="MyApp" --why="Blocking shutdown" ... works for terminal-initiated shutdowns (like when using systemctl poweroff), but many desktop environments (e.g., GNOME or KDE) seem to bypass these inhibitors when the shutdown is triggered from the GUI (for example, via gnome-session-quit --power-off).
My questions are:
1. Is there a user-space, non-root method to reliably block or delay GUI-initiated shutdowns on Linux?
2. What systemd, DBus, or desktop API mechanisms (or combinations thereof) can be leveraged so that GUI shutdown requests are also inhibited?
3. Are there any proven approaches or workarounds that work across different desktop environments without requiring system-level modifications (like altering polkit rules or shutdown scripts)?
Any insights, code examples, or documentation references would be greatly appreciated.
Asked by Nirav Jangale
(11 rep)
Mar 31, 2025, 08:18 AM