Systemd-inhibit Not Preventing Manual Sleep Actions on Manjaro KDE

Hi all,

❱inxi -bz

System:
Kernel: 6.9.3-3-MANJARO arch: x86_64 bits: 64
Desktop: KDE Plasma v: 6.0.5 Distro: Manjaro Linux
Machine:
Type: Desktop System: Dell product: OptiPlex 7050 v: N/A
serial:
Mobo: Dell model: 055H3G v: A01 serial: UEFI: Dell
v: 1.26.0 date: 08/20/2023
CPU:
Info: quad core Intel Core i7-7700 [MCP] speed (MHz): avg: 2584
min/max: 800/4200
Graphics:
Device-1: Intel HD Graphics 630 driver: i915 v: kernel
Display: x11 server: X.Org v: 21.1.13 with: Xwayland v: 24.1.0 driver: X:
loaded: modesetting dri: iris gpu: i915 resolution: 3840x2160~60Hz
API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 24.0.9-manjaro1.1
renderer: Mesa Intel HD Graphics 630 (KBL GT2)
Network:
Device-1: Intel Ethernet I219-LM driver: e1000e
Device-2: Intel Wireless 8265 / 8275 driver: iwlwifi
Drives:
Local Storage: total: 1.84 TiB used: 474.36 GiB (25.2%)
Info:
Memory: total: 16 GiB available: 15.48 GiB used: 5.06 GiB (32.7%)
Processes: 240 Uptime: 7h 29m Shell: fish inxi: 3.3.35

Description: I am experiencing an issue where systemd-inhibit is not preventing manual sleep actions (e.g., using the power button, closing the lid, or selecting sleep from the menu) on my Manjaro KDE system. According to the systemd-inhibit man page, it should block these actions, but it is not working as expected.

Issue Details:

Inhibitor Command Used as a test:

systemd-inhibit --what=shutdown:sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch --why="Testing inhibition" leafpad &

Active Inhibitors:

❱systemd-inhibit --list
WHO            UID  USER PID   COMM            WHAT                                                                                           WHY                                       MODE 
ModemManager   0    root 619   ModemManager    sleep                                                                                          ModemManager needs to reset devices       delay
NetworkManager 0    root 546   NetworkManager  sleep                                                                                          NetworkManager needs to turn off networks delay
UPower         0    root 3559  upowerd         sleep                                                                                          Pause device polling                      delay
PowerDevil     1000 greg 3652  org_kde_powerde handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch                     KDE handles power events                  block
leafpad        1000 greg 77741 systemd-inhibit shutdown:sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch Testing inhibition                        block

5 inhibitors listed.

Logs from dbus-monitor:

❱ dbus-monitor --system "type='signal',interface='org.freedesktop.login1.Manager'"
dbus-monitor: unable to enable new-style monitoring: org.freedesktop.DBus.Error.AccessDenied: "Sender is not authorized to send message". Falling back to eavesdropping.
signal time=1719732387.258338 sender=org.freedesktop.DBus -> destination=:1.1258 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.1258"
signal time=1719732412.618874 sender=:1.6 -> destination=(null destination) serial=441 path=/org/freedesktop/login1; interface=org.freedesktop.login1.Manager; member=PrepareForSleep
   boolean true
signal time=1719732428.386691 sender=:1.6 -> destination=(null destination) serial=447 path=/org/freedesktop/login1; interface=org.freedesktop.login1.Manager; member=PrepareForSleep
   boolean false

Logs from systemd-logind:

    ❱ sudo journalctl -u systemd-logind -e
    Jun 30 01:06:08 greg-optiplex7050 systemd[1]: Starting User Login Management...
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: New seat seat0.
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event2 (Power Button)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event1 (Power Button)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event0 (Sleep Button)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event3 (SINO WEALTH USB KEYBOARD)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event4 (SINO WEALTH USB KEYBOARD System Control)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event5 (SINO WEALTH USB KEYBOARD Consumer Control)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event7 (Hailuck Co.,Ltd PTP TouchPad Keyboard)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event8 (Hailuck Co.,Ltd PTP TouchPad System Control)
    Jun 30 01:06:08 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event9 (Hailuck Co.,Ltd PTP TouchPad Consumer Control)
    Jun 30 01:06:08 greg-optiplex7050 systemd[1]: Started User Login Management.
    Jun 30 01:06:14 greg-optiplex7050 systemd-logind[552]: New session 1 of user greg.
    Jun 30 01:07:30 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 02:03:10 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 06:31:38 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 06:33:39 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 07:48:50 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 07:49:34 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 07:50:35 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 07:51:17 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 07:51:38 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 07:52:59 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 08:07:23 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 08:07:36 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 08:09:14 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 08:15:38 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 08:15:52 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 08:16:54 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 08:17:11 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.
    Jun 30 08:18:39 greg-optiplex7050 systemd-logind[552]: Watching system buttons on /dev/input/event20 (soundcore Sport X20 (AVRCP))
    Jun 30 08:26:52 greg-optiplex7050 systemd-logind[552]: The system will suspend now!
    Jun 30 08:27:08 greg-optiplex7050 systemd-logind[552]: Operation 'suspend' finished.

Issue Summary:

Despite using systemd-inhibit with all relevant options to block both automatic and manual sleep actions, my system still allows manual sleep actions such as using the power button, closing the lid, or selecting sleep from the menu. According to the systemd-inhibit man page, these actions should be blocked, but they are not working as expected on my Manjaro KDE system.
Steps Already Taken:

  • Verified inhibitors are active with systemd-inhibit --list.
  • Monitored D-Bus messages related to power management with dbus-monitor.
  • Reviewed systemd-logind and PowerDevil logs for relevant messages.

Request for Help:

I would appreciate any guidance on resolving this issue. Is there something specific to KDE or Manjaro that might be overriding the inhibitors? Are there additional configurations or settings I should check to ensure systemd-inhibit works as expected for manual actions?

Cheers.

Doesn’t KDE Plasma have it’s own power manager, allowing you to configure these things?

Here is a link to section 2 of the Arch wiki on power management.
first paragraph, second sentence

Thx for the link but I don’t have a clue what it all means. How do i stop the system from suspending while i run a backup script?

I have asked this before about how to stop it from suspeding when im using a music app and the answer was to use systemd-inhibit.
https://forum.manjaro.org/t/how-do-i-stop-the-auto-suspend-when-music-player-strawberry-clementine-is-playing

Thing is that systemd-inhibit seems to work to stop automatic suspend but not manual suspend? The man says it should do.

As far as I know, each one of the events you are talking about can be disabled or set to a certain delay,
and then I have heard of an app called “caffeine” or maybe “kaffeine” which lets you configure this.
I do not know more about it.

It was not the only answer though, but back then you marked it as a solution.
I have never needed to fiddle with systemd or systemd-inhibit to prevent my laptop from turning off,
the power management options of the DE where always enough for me
(you use Plasma, I use Xfce4 - the available options are essentially the same).

I have zero experience with what you are trying to use (systemd-inhibit) - never needed it.

Yes because it worked to stop the auto timer from sending the system to sleep while listening to music. I had just assumed at the time that it would have also stopped a manual suspend but i have just found out that it does not (even though it very specifically says it should).

Inhibitor locks may be used to block or delay system sleep and shutdown requests from the user, as well as automatic idle handling of the OS. This is useful to
avoid system suspends while an optical disc is being recorded, or similar operations that should not be interrupted.

I run a backup script in the background every few hours, i need to stop the system from going to sleep in the middle of this script running, or at least giving it time to finish. Everywhere i search say use systemd-inhibit.

I have also tried
systemctl mask sleep.target
and then
systemctl unmask sleep.target
But that causes the network to disconnect and then reconnect which is obviously no good.

How do i disable suspend at the beginning of my script and then re-enable it at the end (for both timed suspend and manual suspend)?

Probably at the same place where you set the timed suspend and so on.
Likely in System Settings → the Energy Saving Section

I’m not familiar with Plasma - only have it as a VM to try things.

The wiki I linked you to also says (seems to say to me), that this may be used

On systems with no dedicated power manager

which does not apply to Plasma, because it clearly has got one.

This is the extent of my knowledge - can’t help you further.

I would have spotted something. There is nothing to set the suspend and/or shutdown to “wait/disable” while a specific script/program/process is running. I wish there was.


K, i appreciate the help. :slight_smile:

From your screenshot, you have set it to go to sleep after 60 minutes, no matter what.
I do not know why your backup script would not count as activity - no idea.
But you could simply set it to disabled (also mentioned in the first link below).

https://unix.stackexchange.com/questions/637036/kde-equivalent-of-gnome-shell-extension-caffeine

GitHub - qunxyz/plasma-applet-caffeine-plus: Disable screensaver and auto suspend

or something similar

I need the auto suspend on 99% of the time so i can not disable it. I just need it to not suspend/shutdown if the backup script is running even i i manually hit the menu/sleep or close the lid etc because i cant be checking to see if its running a backup every time i just want to suspend the system for a minute or 2 or go to bed or whatever I’m dong. I need it programmatically disabled while the script is running and systemd-inhibit is supposed to be exactly for that.

I think not that this is the best or even correct approach -
the Plasma power manager has control over that, not systemd
and it obviously doesn’t work.

There is dbus or whatever messaging system Plasma uses to trigger events
or can be used to toggle options like this without the GUI.
I really don’t know.