]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run0: Stay in cwd if --empower is specified without a user
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Nov 2025 11:36:42 +0000 (12:36 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Nov 2025 13:39:34 +0000 (14:39 +0100)
If we run "run0 --empower", the expectation is to stay in the
current working directory, not switch to ~.

src/run/run.c

index 510d4c51ab03e46b6b44b64ee52c4952a5521c37..9ee539b5edbf28b9ecd5c1dcb76f54139b50275b 100644 (file)
@@ -1098,6 +1098,12 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                 arg_exec_user = getusername_malloc();
                 if (!arg_exec_user)
                         return log_oom();
+
+                if (arg_empower && !arg_working_directory) {
+                        r = safe_getcwd(&arg_working_directory);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to get current working directory: %m");
+                }
         }
 
         if (!arg_working_directory) {