Skip to content

csm-systemd.c: Take the session's logind inhibitor in block-weak mode when available - #219

Open
Fantu wants to merge 1 commit into
linuxmint:masterfrom
Fantu:systemd-block-weak-inhibitor
Open

Fantu wants to merge 1 commit into
linuxmint:masterfrom
Fantu:systemd-block-weak-inhibitor

Conversation

@Fantu

@Fantu Fantu commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

When an application inhibits suspend through the session manager (Rhythmbox while playing, browsers playing media, ...), cinnamon-session takes a logind sleep:shutdown inhibitor in block mode. Since systemd 257, logind always obeys block inhibitors, also when the request comes from the same user who holds them (before, they were ignored for the same user and for root). So the session now blocks itself:

  • closing the lid: csd-power locks the screen and calls Suspend(), logind refuses it and the laptop stays on;
  • end-session dialog: logind answers inhibited to CanSuspend/CanPowerOff/CanReboot, so cinnamon-session does not offer suspend, restart and shut down, and "Ignore and continue" for suspend does nothing.

This PR takes the inhibitor in block-weak mode, added in systemd 257 to keep the previous semantics, when logind supports it. Suspend on idle still honours the inhibitors, because csd-power checks the session inhibitors itself before arming the sleep timeout.

gnome-session made the same change: 39d51c9e6 "systemd: Downgrade suspend inhibitor to block-weak", with the same rationale (a suspend inhibitor is implicitly ignored anyway when logind handles the lid, since LidSwitchIgnoreInhibited=yes is the default), later extended to the shutdown inhibitor in df8cf27b8.

Testing

Debian sid VM (systemd 262, Cinnamon 6.6.9, cinnamon-session and cinnamon-settings-daemon 6.6.4), with cinnamon-session rebuilt with this change (the code is identical to master). The lid was simulated with a uinput SW_LID device, which upower and logind handle as a real lid switch. The application was a small GTK program calling gtk_application_inhibit (..., GTK_APPLICATION_INHIBIT_SUSPEND, ...), the same path as Rhythmbox.

unpatched (block) patched (block-weak)
closing the lid no suspend suspends
Can* from the session inhibited yes
end-session dialog GetCapabilities restart, shut down, suspend, hibernate all false all true
Suspend + IgnoreInhibitors nothing happens suspends

Without the application, closing the lid suspends in both cases. The table was collected with block-weak hard-coded; with the final version the same VM takes the inhibitor in block-weak mode.

Compatibility

block-weak needs systemd-logind >= 257 or elogind >= 257; older versions (systemd 255 in Linux Mint 22, elogind 255 still shipped by Debian) don't know it. The mode is chosen from the BlockWeakInhibited logind property, added together with it: when the property is missing the inhibitor is taken in block mode as before, which on those versions is already ignored for the same user. Checked on Linux Mint 22.3 (systemd 255) with this change applied to 6.6.3: the inhibitor is still taken, in block mode, with no errors.

Related: linuxmint/cinnamon#13219, #147, #186, #193, and Debian bug #1107965.

… when available.

Since systemd 257, logind always obeys "block" inhibitors, including the
ones held by the user who requests the operation (before, those were
ignored for the same user and for root). The "sleep:shutdown" inhibitor
that cinnamon-session takes on behalf of applications inhibiting suspend
(Rhythmbox while playing, browsers playing media, ...) now blocks the
session itself:

- closing the lid: csd-power locks the screen and calls Suspend(), which
is refused, so the laptop stays on;
- end-session dialog: logind answers "inhibited" to
CanSuspend/CanPowerOff/CanReboot, so suspend, restart and shut down are
not offered, and "Ignore and continue" for suspend does nothing.

The "block-weak" mode, added in systemd 257, keeps the previous
semantics. Suspend on idle still honours the inhibitors, since csd-power
checks the session inhibitors itself before arming the sleep timeout.
gnome-session did the same (39d51c9e6, "systemd: Downgrade suspend
inhibitor to block-weak").

systemd-logind and elogind older than 257 don't know "block-weak": there
the inhibitor is still taken in "block" mode, which on those versions is
ignored for the same user anyway. The BlockWeakInhibited property, added
together with the new mode, tells the two apart.

Ref: linuxmint/cinnamon#13219

Assisted-by: Claude Code:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant