]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-run: refuse --working-directory option with --scope
authorJoost Heitbrink <joostheitbrink@outlook.com>
Wed, 21 Sep 2022 18:11:44 +0000 (20:11 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 21 Sep 2022 23:12:08 +0000 (08:12 +0900)
systemd-run's man page says the following about the working directory of
the process:

"If a command is run as transient scope unit, it will be executed
by systemd-run itself as parent process and will thus inherit the
execution environment of the caller."

This means working directory assignment does not work, as evidenced by
the following invocation:
```bash
$ systemd-run --scope --property=WorkingDirectory=/tmp/ bash -c 'echo $(pwd)'
Unknown assignment: WorkingDirectory=/tmp/
```

However, using the shorthand switch --working-directory silently ignores
this instead of giving a similar error.
```bash
systemd-run --scope --user --working-directory=/tmp/ bash -c 'echo $(pwd)'
Running scope as unit: run-r19cc32e744e64285814dbf2204637a2b.scope
/home/test/projects/systemd
```

This commit fixes this by explicitly generating an error instead of
silently ignoring the switch:
```bash
$ systemd-run --scope --working-directory=/tmp/ bash -c 'echo $(pwd)'
--working-directory is not supported in --scope mode.
```

src/run/run.c

index e2915fe4defdbe9567227d07cd0eeb9072fbb00c..741f7b279fea339bfd83888c48c56f59dd2648e3 100644 (file)
@@ -593,6 +593,10 @@ 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.");