1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

service: when invoking service processes in --user mode set MANAGERPID to PID of systemd

This commit is contained in:
Lennart Poettering 2012-10-18 01:18:50 +02:00
parent c978343015
commit 97ae63e2a9
2 changed files with 23 additions and 11 deletions

View File

@ -365,6 +365,13 @@
explicitly to a shell implementation
of some kind. Example:
<literal>ExecStart=/bin/sh -c 'dmesg | tac'</literal></para>
<para>For services run by a user
instance of systemd the special
environment variable
<literal>MANAGERPID</literal> is set
to the PID of the systemd
instance.</para>
</listitem>
</varlistentry>
@ -407,12 +414,12 @@
variable substitution is supported
here following the same scheme as for
<varname>ExecStart=</varname>. One
special environment variable is set:
if known <literal>$MAINPID</literal> is
set to the main process of the
daemon, and may be used for command
lines like the following:
<command>/bin/kill -HUP
additional special environment
variables is set: if known
<literal>$MAINPID</literal> is set to
the main process of the daemon, and
may be used for command lines like the
following: <command>/bin/kill -HUP
$MAINPID</command>.</para></listitem>
</varlistentry>

View File

@ -1801,7 +1801,8 @@ static int service_spawn(
goto fail;
}
if (!(our_env = new0(char*, 4))) {
our_env = new0(char*, 5);
if (!our_env) {
r = -ENOMEM;
goto fail;
}
@ -1824,10 +1825,14 @@ static int service_spawn(
goto fail;
}
if (!(final_env = strv_env_merge(2,
UNIT(s)->manager->environment,
our_env,
NULL))) {
if (s->meta.manager->running_as != SYSTEMD_SYSTEM)
if (asprintf(our_env + n_env++, "MANAGERPID=%lu", (unsigned long) getpid()) < 0) {
r = -ENOMEM;
goto fail;
}
final_env = strv_env_merge(2, UNIT(s)->manager->environment, our_env, NULL);
if (!final_env) {
r = -ENOMEM;
goto fail;
}