run0: support --chdir='~' for switching to target user's home dir

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 '~'.
This commit is contained in:
Mike Yuan
2025-05-07 00:36:41 +02:00
parent 5b8bcbcf00
commit fa02d58d85

View 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;