Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd: move toplevel to separate scopes #795

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cmeissl
Copy link
Contributor

@cmeissl cmeissl commented Nov 10, 2024

Currently niri creates a separate scope per spawn action matching the name of the executable.
So for example launching the non flatpak version of firefox through fuzzel will result in this firefox instance
to run under a scope name app-niri-fuzzel-<PID>.scope.
This can be problematic in combination with xdg-portal, which will use the scope name as a fallback for the
non accessible app id.

To solve this, this PR tries to mimic what systemd-sway does, moving toplevels to systemd scopes matching their app id.
In addition to moving the process it also add slices like systemd-sway offers. This allows to override resource
limits per app id slice.

The code is more a PoC and needs a major cleanup. The worst part is finding out all child pids that should also be moved to the new scope.

Cargo.toml Outdated
@@ -86,6 +86,7 @@ wayland-backend = "0.3.7"
wayland-scanner = "0.31.5"
xcursor = "0.3.8"
zbus = { version = "~3.15.2", optional = true }
zvariant = { version = "~3.15.2", optional = true }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's exported under zbus::zvariant::

}
}

let _ = write!(slice_name, ".slice");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a slice and not a scope btw? All apps are in app.slice, and I only have the few pre-created slices on my system.

└─ systemctl --user | grep .slice
  -.slice
  app.slice
  background.slice
  session.slice
  user.slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be both, the scope is named like app-niri-<app_id>-{pid}.scope and the slice is named app-niri-<app_id>.slice. This allows to override limits per app_id

@cmeissl cmeissl force-pushed the feature/toplevel_scopes branch from 2babba6 to 9944957 Compare November 11, 2024 07:47
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.

2 participants