]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: export $PIDFILE env var for services, derived from PIDFile=
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Jan 2019 16:39:09 +0000 (17:39 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 Feb 2019 10:32:19 +0000 (11:32 +0100)
man/systemd.exec.xml
src/core/manager.c
src/core/service.c

index 0248c3a8e0081746aad054bee1148df6a9cefd15..d39149bd0c005a8cb83202ecd9e63896dffcc29c 100644 (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
index 6086531bab7a624617dd5a56aaabfb6bc3089810..fc6f89f85b928ba44e74b466826d3e577a4193ad 100644 (file)
@@ -587,6 +587,7 @@ static char** sanitize_environment(char **l) {
                         "MAINPID",
                         "MANAGERPID",
                         "NOTIFY_SOCKET",
+                        "PIDFILE",
                         "REMOTE_ADDR",
                         "REMOTE_PORT",
                         "SERVICE_RESULT",
index 324dcf2311081f3c6023ea35207aa3f97c259f84..fd9a809b3eba738112f1e93cf9ca0df8246c8c9b 100644 (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);