]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: fix bug causing run0 to ignore `-D /`.
authorJohn A. Leuenhagen <john@zlima12.com>
Tue, 15 Oct 2024 04:57:52 +0000 (00:57 -0400)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Oct 2024 09:59:44 +0000 (18:59 +0900)
Since the root directory was being suppressed to NULL, the subsequent
check would erroneously think that no working directory was specified.
This caused the default working directory to be applied instead.

src/run/run.c

index 1f2938f9eae3099e00e8e4ca92915af0e94c06e4..5d2298a5f6c19f1516058a3c31ca55140f60e050 100644 (file)
@@ -862,7 +862,8 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                         break;
 
                 case 'D':
-                        r = parse_path_argument(optarg, true, &arg_working_directory);
+                        /* Root will be manually suppressed later. */
+                        r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_working_directory);
                         if (r < 0)
                                 return r;
 
@@ -901,6 +902,10 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to get current working directory: %m");
                 }
+        } else {
+                /* Root was not suppressed earlier, to allow the above check to work properly. */
+                if (empty_or_root(arg_working_directory))
+                        arg_working_directory = mfree(arg_working_directory);
         }
 
         arg_service_type = "exec";