summaryrefslogtreecommitdiff
path: root/man
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-04-02 23:17:58 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-04-24 10:02:30 +0200
commitf872ddd182bd33d9ba0569d050374b9b9a9a2ab4 (patch)
tree0a3f316e98820d25a154b0456ecfbbec8fa8e529 /man
parentb58026bddce8cc418c10e1c69f96de34b0dffcbf (diff)
downloadsystemd-f872ddd182bd33d9ba0569d050374b9b9a9a2ab4.tar.gz
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.
Diffstat (limited to 'man')
-rw-r--r--man/systemd-run.xml26
1 files changed, 25 insertions, 1 deletions
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 <option>exec</option> service type (i.e. <option>--property=Type=exec</option>) to
ensure that <command>systemd-run</command> returns successfully only if the specified command line has
been successfully started.</para>
+
+ <para>After <command>systemd-run</command> passes the command to the service manager, the manager
+ performs variable expansion. This means that dollar characters (<literal>$</literal>) which should not be
+ expanded need to be escaped as <literal>$$</literal>. Expansion can also be disabled using
+ <varname>--expand-environment=no</varname>.</para>
</refsect1>
<refsect1>
@@ -170,6 +175,24 @@
</varlistentry>
<varlistentry>
+ <term><option>--expand-environment=<replaceable>BOOL</replaceable></option></term>
+
+ <listitem><para>Expand environment variables in command arguments. If enabled (the default), the
+ service manager that spawns the actual command will expand variables specified as
+ <literal>${<replaceable>VARIABLE</replaceable>}</literal> in the same way as in commands specied via
+ <varname>ExecStart=</varname> in units. Note that this is similar to, but not the same as variable
+ expansion in
+ <citerefentry project='man-pages'><refentrytitle>bash</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+ and other shells.</para>
+
+ <para>See
+ <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ for a description of variable expansion. Disabling variable expansion is useful if the specified
+ command includes or may include a <literal>$</literal> sign.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-r</option></term>
<term><option>--remain-after-exit</option></term>
@@ -533,7 +556,8 @@ There is a screen on:
<programlisting>$ 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 $$$$'</programlisting>
+$ systemd-run --user --wait -p SuccessExitStatus=SIGUSR1 --expand-environment=no \
+ bash -c 'kill -SIGUSR1 $$'</programlisting>
<para>Those three invocations will succeed, i.e. terminate with an exit code of 0.</para>
</example>