From c7b5ea69551c021a729a5d9a898a1a0d5d924bdf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Sep 2022 14:19:10 +0200 Subject: [PATCH 1/2] Revert "systemd-run: refuse --working-directory option with --scope" This reverts commit 780c8055378589e5a7d419789761c35d05295291. --- src/run/run.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 741f7b279f..e2915fe4de 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -593,10 +593,6 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--remain-after-exit and --service-type= are not supported in --scope mode."); - if (arg_scope && arg_working_directory) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "--working-directory is not supported in --scope mode."); - if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--pty/--pipe is not compatible in timer or --scope mode."); From fecc44776638a24099ce7e9ac227bcaa2c34f1e0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Sep 2022 14:21:46 +0200 Subject: [PATCH 2/2] run: make --working-directory= work for --scope too This sounds like a more user-friendly alternative to #24780 --- src/run/run.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/run/run.c b/src/run/run.c index e2915fe4de..627a6b11da 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -1529,6 +1529,9 @@ static int start_transient_scope(sd_bus *bus) { return log_error_errno(errno, "Failed to change UID to " UID_FMT ": %m", uid); } + if (arg_working_directory && chdir(arg_working_directory) < 0) + return log_error_errno(errno, "Failed to change directory to '%s': %m", arg_working_directory); + env = strv_env_merge(environ, user_env, arg_environment); if (!env) return log_oom();