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);