diff options
-rw-r--r-- | man/systemd.exec.xml | 138 | ||||
-rw-r--r-- | src/core/manager.c | 5 |
2 files changed, 117 insertions, 26 deletions
diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 5721dc1553..ba4e808ddd 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -57,7 +57,7 @@ <title>Description</title> <para>Unit configuration files for services, sockets, - mount points and swap devices share a subset of + mount points, and swap devices share a subset of configuration options which define the execution environment of spawned processes.</para> @@ -76,27 +76,6 @@ configuration options are configured in the [Service], [Socket], [Mount], or [Swap] sections, depending on the unit type.</para> - - <para>Processes started by the system systemd instance - are executed in a clean environment in which only the - <varname>$PATH</varname> and <varname>$LANG</varname> - variables are set by default. In order to add - additional variables, see the - <varname>Environment=</varname> and - <varname>EnvironmentFile=</varname> options below. To - specify variables globally, see - <varname>DefaultEnvironment=</varname> in - <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> - or the kernel option - <varname>systemd.setenv=</varname> in - <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>. Processes - started by the user systemd instances inherit all - environment variables from the user systemd instance, - and have <varname>$HOME</varname>, - <varname>$USER</varname>, - <varname>$XDG_RUNTIME_DIR</varname> defined, among - others. In addition, <varname>$MANAGERPID</varname> - contains the PID of the user systemd instance.</para> </refsect1> <refsect1> @@ -1006,6 +985,118 @@ </refsect1> <refsect1> + <title>Environment variables in spawned processes</title> + + <para>Processes started by the system are executed in + a clean environment in which select variables + listed below are set. System processes started by systemd + do not inherit variables from PID 1, but processes + started by user systemd instances inherit all + environment variables from the user systemd instance. + </para> + + <variablelist class='environment-variables'> + <varlistentry> + <term><varname>$PATH</varname></term> + + <listitem><para>Colon-separated list + of directiories to use when launching + executables. Systemd uses a fixed + value of + <filename>/usr/local/sbin</filename>:<filename>/usr/local/bin</filename>:<filename>/usr/sbin</filename>:<filename>/usr/bin</filename>:<filename>/sbin</filename>:<filename>/bin</filename>. + </para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$LANG</varname></term> + + <listitem><para>Locale. Can be set in + <citerefentry><refentrytitle>locale.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> + or on the kernel command line (see + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> + and + <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>). + </para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$USER</varname></term> + <term><varname>$HOME</varname></term> + + <listitem><para>User name and home + directory. Set for the units which + have <varname>User=</varname> set, + which includes user + <command>systemd</command> instances. + See + <citerefentry><refentrytitle>passwd</refentrytitle><manvolnum>5</manvolnum></citerefentry>. + </para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$XDG_RUNTIME_DIR</varname></term> + + <listitem><para>The directory for volatile + state. Set for the user <command>systemd</command> + instance, and also in user sessions. + See + <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>. + </para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$XDG_SESSION_ID</varname></term> + <term><varname>$XDG_SEAT</varname></term> + <term><varname>$XDG_VTNR</varname></term> + + <listitem><para>The identifier of the + session, and the seat name, and + virtual terminal of the session. Set + by + <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> + for login sessions. + <varname>$XDG_SEAT</varname> and + <varname>$XDG_VTNR</varname> will be + only set when attached to a seat and a + tty.</para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$MANAGERPID</varname></term> + + <listitem><para>The PID of the user + <command>systemd</command> instance, + set for processes spawned by it. + </para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>$LISTEN_FDS</varname></term> + <term><varname>$LISTEN_PID</varname></term> + + <listitem><para>Information about file + descriptors passed to a service for + socket activation. See + <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>. + </para></listitem> + </varlistentry> + </variablelist> + + <para>Additional variables may be configured by the + following means: for processes spawned in specific + units, use the <varname>Environment=</varname> and + <varname>EnvironmentFile=</varname> options above; to + specify variables globally, use + <varname>DefaultEnvironment=</varname> (see + <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>) + or the kernel option + <varname>systemd.setenv=</varname> (see + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>). Additional + variables may also be set through PAM, + c.f. <citerefentry><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> + </refsect1> + + <refsect1> <title>See Also</title> <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, @@ -1018,7 +1109,8 @@ <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd.cgroup</refentrytitle><manvolnum>5</manvolnum></citerefentry>, - <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry> + <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>exec</refentrytitle><manvolnum>3</manvolnum></citerefentry> </para> </refsect1> diff --git a/src/core/manager.c b/src/core/manager.c index 669af1524f..079db4157b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -456,8 +456,6 @@ static int manager_setup_signals(Manager *m) { } static int manager_default_environment(Manager *m) { - const char *path = "PATH=" DEFAULT_PATH; - assert(m); if (m->running_as == SYSTEMD_SYSTEM) { @@ -468,7 +466,8 @@ static int manager_default_environment(Manager *m) { * The initial passed environ is untouched to keep * /proc/self/environ valid; it is used for tagging * the init process inside containers. */ - m->environment = strv_new(path, NULL); + m->environment = strv_new("PATH=" DEFAULT_PATH, + NULL); /* Import locale variables LC_*= from configuration */ locale_setup(&m->environment); |