From fa02d58d858233e10b7524e6c7fcacfa6031aee6 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 7 May 2025 00:36:41 +0200 Subject: [PATCH] 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 '~'. --- src/run/run.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 7b6fe01d562..4504c97df19 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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; -- 2.47.3