From dcf3c3c3d90485f86c89f473cba8fcf7a1127dc9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 30 Jan 2019 17:39:09 +0100 Subject: [PATCH] core: export $PIDFILE env var for services, derived from PIDFile= --- man/systemd.exec.xml | 12 ++++++++++++ src/core/manager.c | 1 + src/core/service.c | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 0248c3a8e0..d39149bd0c 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -2468,6 +2468,18 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy + + + $PIDFILE + + The path to the configured PID file, in case the process is forked off on behalf of a + service that uses the PIDFile= setting, see + systemd.service5 + 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. + + For system services, when PAMName= is enabled and pam_systemd is part diff --git a/src/core/manager.c b/src/core/manager.c index 6086531bab..fc6f89f85b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -587,6 +587,7 @@ static char** sanitize_environment(char **l) { "MAINPID", "MANAGERPID", "NOTIFY_SOCKET", + "PIDFILE", "REMOTE_ADDR", "REMOTE_PORT", "SERVICE_RESULT", diff --git a/src/core/service.c b/src/core/service.c index 324dcf2311..fd9a809b3e 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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);