]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run0: support --chdir='~' for switching to target user's home dir
authorMike Yuan <me@yhndnzj.com>
Tue, 6 May 2025 22:36:41 +0000 (00:36 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 7 May 2025 16:32:19 +0000 (18:32 +0200)
parse_path_argument() unconditionally makes the passed path absolute,
without handling '~' of any sort. I think this generally makes sense
in most tools, since ~ expansion is typically done by the shell
and we wouldn't be seeing them in the first place and hence special
casing is not worth it. But in run0 let's explicit enable '~'.

src/run/run.c

index 7b6fe01d5620083d180bf3cc94f732f0ce4bfaa9..4504c97df19f28135ab901f545eacc99d6b3f3e6 100644 (file)
@@ -924,8 +924,11 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                         break;
 
                 case 'D':
-                        /* Root will be manually suppressed later. */
-                        r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_working_directory);
+                        if (streq(optarg, "~"))
+                                r = free_and_strdup_warn(&arg_working_directory, optarg);
+                        else
+                                /* Root will be manually suppressed later. */
+                                r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_working_directory);
                         if (r < 0)
                                 return r;