diff --git a/man/run0.xml b/man/run0.xml
index fee0e08a5e..c2e891149f 100644
--- a/man/run0.xml
+++ b/man/run0.xml
@@ -108,7 +108,9 @@
Make the new .service unit part of the specified slice, instead
- of user.slice.
+ of user.slice. This option conflicts with and
+ , and implies XDG_SESSION_CLASS=none,
+ to keep the new process within the specified slice instead of a new session scope.
@@ -120,7 +122,9 @@
Make the new .service unit part of the slice the
run0 itself has been invoked in. This option may be combined with
, in which case the slice specified via is placed
- within the slice the run0 command is invoked in.
+ within the slice the run0 command is invoked in. Also conflicts with
+ and and implies
+ XDG_SESSION_CLASS=none, similar to .
Example: consider run0 being invoked in the slice
foo.slice, and the argument is
diff --git a/src/run/run.c b/src/run/run.c
index f7dc5b5670..2e37a0a2f6 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -992,6 +992,14 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
_cleanup_strv_free_ char **l = NULL;
char **args = option_parser_get_args(&opts);
+ bool custom_slice = arg_slice_inherit || arg_slice;
+ if (custom_slice && arg_lightweight >= 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--lightweight= may not be combined with a custom slice");
+ if (custom_slice && !isempty(arg_area))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--area= may not be combined with a custom slice");
+
if (!strv_isempty(args)) {
if (arg_validate)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -1108,9 +1116,12 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
}
if (!strv_env_get(arg_environment, "XDG_SESSION_CLASS")) {
+ const char *class = NULL;
+ if (custom_slice)
+ class = "none";
/* If logging into an area, imply lightweight mode */
- if (arg_lightweight < 0 && !isempty(arg_area))
+ else if (arg_lightweight < 0 && !isempty(arg_area))
arg_lightweight = true;
/* When using run0 to acquire privileges temporarily, let's not pull in session manager by
@@ -1120,14 +1131,14 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
* this for root or --empower though, under the assumption that if a regular user temporarily
* transitions into another regular user it's a better default that the full user environment is
* uniformly available. */
- if (arg_lightweight < 0 && (become_root() || arg_empower))
+ else if (arg_lightweight < 0 && (become_root() || arg_empower))
arg_lightweight = true;
- if (arg_lightweight >= 0) {
- const char *class =
- arg_lightweight ? (arg_stdio == ARG_STDIO_PTY ? (become_root() ? "user-early-light" : "user-light") : "background-light") :
+ if (arg_lightweight >= 0)
+ class = arg_lightweight ? (arg_stdio == ARG_STDIO_PTY ? (become_root() ? "user-early-light" : "user-light") : "background-light") :
(arg_stdio == ARG_STDIO_PTY ? (become_root() ? "user-early" : "user") : "background");
+ if (class) {
log_debug("Setting XDG_SESSION_CLASS to '%s'.", class);
r = strv_env_assign(&arg_environment, "XDG_SESSION_CLASS", class);