]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: default run0 to root explicitly
authorShihao Ren <renshihao.rsh@bytedance.com>
Wed, 24 Jun 2026 03:46:56 +0000 (11:46 +0800)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Jul 2026 19:34:15 +0000 (21:34 +0200)
When neither --user=, --area= nor --empower is given, run0 already
behaves as if root was requested, but only implicitly. That can be
misleading downstream.

Set arg_exec_user to "root" up front in parse_argv_sudo_mode(), so the
intent is visible and the rest of the code can rely on it.

Fixes #40468

Signed-off-by: Shihao Ren <renshihao.rsh@bytedance.com>
src/run/run.c

index 785ac9e6687524f0394bc100544613a2343aeed3..1fca68c76f84b60a235b8daef0adf21b72877a08 100644 (file)
@@ -968,14 +968,20 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                         arg_working_directory = mfree(arg_working_directory);
         }
 
-        if (!arg_exec_user && (arg_area || arg_empower)) {
+        if (!arg_exec_user) {
                 /* If the user specifies --area= but not --user= then consider this an area switch request,
                  * and default to logging into our own account.
                  *
                  * If the user specifies --empower but not --user= then consider this a request to empower
-                 * the current user. */
+                 * the current user.
+                 *
+                 * If neither --user=, --area= nor --empower is specified, default to switching to root
+                 * explicitly. */
 
-                arg_exec_user = getusername_malloc();
+                if (arg_area || arg_empower)
+                        arg_exec_user = getusername_malloc();
+                else
+                        arg_exec_user = strdup("root");
                 if (!arg_exec_user)
                         return log_oom();
         }