From f872ddd182bd33d9ba0569d050374b9b9a9a2ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 2 Apr 2023 23:17:58 +0200 Subject: run: add --expand-environment=no to disable server-side envvar expansion This uses StartExecEx to get the equivalent of ExecStart=:. StartExecEx was added in b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb, so this will not work with older systemds. A hint is emitted if we get an error indicating lack of support. PID1 returns SD_BUS_ERROR_PROPERTY_READ_ONLY, but I'm checking for SD_BUS_ERROR_UNKNOWN_PROPERTY too for safety. --- man/systemd-run.xml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'man') diff --git a/man/systemd-run.xml b/man/systemd-run.xml index cd9e50d5b8..2ad68d8884 100644 --- a/man/systemd-run.xml +++ b/man/systemd-run.xml @@ -92,6 +92,11 @@ Consider using the service type (i.e. ) to ensure that systemd-run returns successfully only if the specified command line has been successfully started. + + After systemd-run passes the command to the service manager, the manager + performs variable expansion. This means that dollar characters ($) which should not be + expanded need to be escaped as $$. Expansion can also be disabled using + --expand-environment=no. @@ -169,6 +174,24 @@ + + + + Expand environment variables in command arguments. If enabled (the default), the + service manager that spawns the actual command will expand variables specified as + ${VARIABLE} in the same way as in commands specied via + ExecStart= in units. Note that this is similar to, but not the same as variable + expansion in + bash1 + and other shells. + + See + systemd.service5 + for a description of variable expansion. Disabling variable expansion is useful if the specified + command includes or may include a $ sign. + + + @@ -533,7 +556,8 @@ There is a screen on: $ systemd-run --user --wait true $ systemd-run --user --wait -p SuccessExitStatus=11 bash -c 'exit 11' -$ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 bash -c 'kill -SIGUSR1 $$$$' +$ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 --expand-environment=no \ + bash -c 'kill -SIGUSR1 $$' Those three invocations will succeed, i.e. terminate with an exit code of 0. -- cgit v1.2.1