Skip to content

gnome-systemd: Actually create scopes for launched applications - #275

Open
Fantu wants to merge 1 commit into
linuxmint:masterfrom
Fantu:app-scopes
Open

gnome-systemd: Actually create scopes for launched applications#275
Fantu wants to merge 1 commit into
linuxmint:masterfrom
Fantu:app-scopes

Conversation

@Fantu

@Fantu Fantu commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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() calls gnome_start_systemd_scope() on every launch. It just never does anything, because the function gives up when sd_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:

$ cat /proc/$(pidof -s cinnamon)/cgroup
0::/user.slice/user-1000.slice/session-2.scope
sd_pid_get_user_unit(cinnamon) -> -61 (ENODATA)

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:

cgroup before: /user.slice/user-1000.slice/session-2.scope
cgroup after:  /user.slice/user-1000.slice/user@1000.service/app.slice/test.scope

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:

  • The unit is now named app-cinnamon-<ApplicationID>-<pid>.scope, following https://systemd.io/DESKTOP_ENVIRONMENTS/ and matching gnome-desktop, which renamed gnome-launched- to app-gnome- for the same reason. Tools that inspect cgroups look for the app- prefix to tell applications apart from other units, so keeping the old name would have left the reported issue effectively unfixed. The .desktop suffix is stripped, as the scheme expects the bare application ID.
  • CollectMode=inactive-or-failed is 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:

$ systemctl --user list-units --type=scope --all --no-legend
  app-cinnamon-debian-xterm-16842.scope  loaded active running  Application launched by cinnamon
  app-cinnamon-nemo-16923.scope          loaded active running  Application launched by cinnamon

$ cat /proc/16842/cgroup
0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-cinnamon-debian-xterm-16842.scope

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant