core: export $PIDFILE env var for services, derived from PIDFile=

This commit is contained in:
Lennart Poettering 2019-01-30 17:39:09 +01:00
parent 7ca9289ca2
commit dcf3c3c3d9
3 changed files with 18 additions and 1 deletions

View File

@ -2468,6 +2468,18 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
</listitem>
</varlistentry>
<varlistentry>
<term><varname>$PIDFILE</varname></term>
<listitem><para>The path to the configured PID file, in case the process is forked off on behalf of a
service that uses the <varname>PIDFile=</varname> setting, see
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. Service code may use this environment variable to automatically generate a PID file at
the location configured in the unit file. This field is set to an absolute path in the file
system.</para></listitem>
</varlistentry>
</variablelist>
<para>For system services, when <varname>PAMName=</varname> is enabled and <command>pam_systemd</command> is part

View File

@ -587,6 +587,7 @@ static char** sanitize_environment(char **l) {
"MAINPID",
"MANAGERPID",
"NOTIFY_SOCKET",
"PIDFILE",
"REMOTE_ADDR",
"REMOTE_PORT",
"SERVICE_RESULT",

View File

@ -1458,7 +1458,7 @@ static int service_spawn(
if (r < 0)
return r;
our_env = new0(char*, 9);
our_env = new0(char*, 10);
if (!our_env)
return -ENOMEM;
@ -1474,6 +1474,10 @@ static int service_spawn(
if (asprintf(our_env + n_env++, "MANAGERPID="PID_FMT, getpid_cached()) < 0)
return -ENOMEM;
if (s->pid_file)
if (asprintf(our_env + n_env++, "PIDFILE=%s", s->pid_file) < 0)
return -ENOMEM;
if (s->socket_fd >= 0) {
union sockaddr_union sa;
socklen_t salen = sizeof(sa);