mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
core: set $SYSTEMD_EXEC_PID= environment variable for executed commands
It may be useful to detect a command is directly executed by systemd manager, or indirectly as a child of another process.
This commit is contained in:
parent
d2acb93dc5
commit
dc4e2940e8
@ -3043,6 +3043,17 @@ StandardInputData=SWNrIHNpdHplIGRhIHVuJyBlc3NlIEtsb3BzLAp1ZmYgZWVtYWwga2xvcHAncy
|
|||||||
</para></listitem>
|
</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><varname>$SYSTEMD_EXEC_PID</varname></term>
|
||||||
|
|
||||||
|
<listitem><para>The PID of the unit process (e.g. process invoked by
|
||||||
|
<varname>ExecStart=</varname>). The child process can use this information to determine
|
||||||
|
whether the process is directly invoked by the service manager or indirectly as a child of
|
||||||
|
another process by comparing this value with the current PID (as similar to the scheme used in
|
||||||
|
<citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||||
|
with <varname>$LISTEN_PID</varname> and <varname>$LISTEN_FDS</varname>).</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>$TERM</varname></term>
|
<term><varname>$TERM</varname></term>
|
||||||
|
|
||||||
|
@ -1794,7 +1794,7 @@ static int build_environment(
|
|||||||
assert(p);
|
assert(p);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
#define N_ENV_VARS 16
|
#define N_ENV_VARS 17
|
||||||
our_env = new0(char*, N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
|
our_env = new0(char*, N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
|
||||||
if (!our_env)
|
if (!our_env)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -1950,6 +1950,11 @@ static int build_environment(
|
|||||||
our_env[n_env++] = x;
|
our_env[n_env++] = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (asprintf(&x, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached()) < 0)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
our_env[n_env++] = x;
|
||||||
|
|
||||||
our_env[n_env++] = NULL;
|
our_env[n_env++] = NULL;
|
||||||
assert(n_env <= N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
|
assert(n_env <= N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX);
|
||||||
#undef N_ENV_VARS
|
#undef N_ENV_VARS
|
||||||
|
Loading…
Reference in New Issue
Block a user