From: Shihao Ren Date: Wed, 24 Jun 2026 03:46:56 +0000 (+0800) Subject: run: default run0 to root explicitly X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4fb350a46afc5ad978cbcef34da383211840ed50;p=thirdparty%2Fsystemd.git run: default run0 to root explicitly 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 --- diff --git a/src/run/run.c b/src/run/run.c index 785ac9e6687..1fca68c76f8 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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(); }