gnome-systemd: Actually create scopes for launched applications - #275
Open
Fantu wants to merge 1 commit into
Open
gnome-systemd: Actually create scopes for launched applications#275Fantu wants to merge 1 commit into
Fantu wants to merge 1 commit into
Conversation
The transient scope is never created, because gnome_start_systemd_scope() gives up when sd_pid_get_user_unit() returns -ENODATA. That check comes from gnome-desktop, where it holds: gnome-shell is started as a systemd user unit, so it is itself part of the user instance. Cinnamon is not - cinnamon-session and everything it spawns live in the logind session scope - so the check always fails and every application ends up sharing the session cgroup with the desktop itself (linuxmint/cinnamon#12015). Being outside the user instance does not prevent us from using it: the user manager happily migrates a PID from the logind session scope into a transient scope it owns. So only give up when there is no user instance at all, which keeps the current behaviour on systems that are not managed by systemd. Name the unit app-cinnamon-<ApplicationID>-<pid>.scope, following the scheme documented at https://systemd.io/DESKTOP_ENVIRONMENTS/ and matching what gnome-desktop does. This matters beyond cosmetics: system monitors look for the app- prefix to tell applications apart from other units, so the old gnome-launched- name would have left the reported issue unfixed. The .desktop suffix is stripped since the scheme expects the bare application ID. Also set CollectMode=inactive-or-failed, so that failed applications do not linger as failed units, as gnome-desktop does. Assisted-by: Claude Code:claude-opus-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applications launched from Cinnamon end up in the same cgroup as the desktop itself, instead of getting one of their own — linuxmint/cinnamon#12015.
The code to fix this has been here since 2023:
cinnamon_global_app_launched_cb()callsgnome_start_systemd_scope()on every launch. It just never does anything, because the function gives up whensd_pid_get_user_unit()returns-ENODATA. That check is inherited from gnome-desktop, where it holds: gnome-shell is started as a systemd user unit, so it is part of the user instance. Cinnamon is not — cinnamon-session and everything it spawns live in the logind session scope — so the check fails every time:Being outside the user instance does not stop us from using it. The user manager is perfectly willing to migrate a PID out of the logind session scope into a transient scope it owns:
So this only gives up when there is no user instance at all, checking that logind knows about us and that the user manager is reachable. Systems not managed by systemd behave exactly as before: same early return, no D-Bus traffic, no new warnings.
Two related changes come with it:
app-cinnamon-<ApplicationID>-<pid>.scope, following https://systemd.io/DESKTOP_ENVIRONMENTS/ and matching gnome-desktop, which renamedgnome-launched-toapp-gnome-for the same reason. Tools that inspect cgroups look for theapp-prefix to tell applications apart from other units, so keeping the old name would have left the reported issue effectively unfixed. The.desktopsuffix is stripped, as the scheme expects the bare application ID.CollectMode=inactive-or-failedis set, so failed applications do not linger as failed units. Same as gnome-desktop.What this buys us
Every application gets an identity systemd can act on: per-app resource accounting and limits,
systemctl --user stop app-cinnamon-…, sane systemd-oomd targets instead of taking the whole session down, recognition by cgroup-based system monitors, and an orderly per-app shutdown at logout.Testing
Built and installed on Mint 23 (Cinnamon 6.7.4, cinnamon-session 6.7.3), X11 and Wayland sessions:
Mission Center now lists them under Running Apps. Note that recent Mission Center releases also match applications heuristically, so this is no longer the only way it can see them — the other benefits above are the reason to do it regardless.
Related
pid == 0guard for D-Bus activated applications. Without it, those launches create an emptyapp-cinnamon-<id>-0.scopeas soon as this PR lands, so the two should go in together.