From 43f565c6770f940a978a5325fea8b0e6d8ee4c99 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 1 Feb 2021 00:51:33 +0900 Subject: core: also set $SYSTEMD_EXEC_PID= for generators --- src/core/manager.c | 6 ++++-- src/shared/exec-util.c | 10 ++++++++-- src/shared/exec-util.h | 7 ++++--- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/manager.c b/src/core/manager.c index a1d6f7cc10..73a850e5da 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -4105,7 +4105,8 @@ static int manager_run_environment_generators(Manager *m) { RUN_WITH_UMASK(0022) r = execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, gather_environment, - args, NULL, m->transient_environment, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); + args, NULL, m->transient_environment, + EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID); return r; } @@ -4140,7 +4141,8 @@ static int manager_run_generators(Manager *m) { RUN_WITH_UMASK(0022) (void) execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, NULL, NULL, - (char**) argv, m->transient_environment, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); + (char**) argv, m->transient_environment, + EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID); r = 0; diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index bdea60ca02..6355ce8ce4 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -34,7 +34,7 @@ /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); -static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid) { +static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid, bool set_systemd_exec_pid) { pid_t _pid; int r; @@ -57,6 +57,12 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid) { (void) rlimit_nofile_safe(); + if (set_systemd_exec_pid) { + r = setenv_systemd_exec_pid(false); + if (r < 0) + log_warning_errno(r, "Failed to set $SYSTEMD_EXEC_PID, ignoring: %m"); + } + if (!argv) { _argv[0] = (char*) path; _argv[1] = NULL; @@ -132,7 +138,7 @@ static int do_execute( return log_error_errno(fd, "Failed to open serialization file: %m"); } - r = do_spawn(t, argv, fd, &pid); + r = do_spawn(t, argv, fd, &pid, FLAGS_SET(flags, EXEC_DIR_SET_SYSTEMD_EXEC_PID)); if (r <= 0) continue; diff --git a/src/shared/exec-util.h b/src/shared/exec-util.h index df6214e4c3..5bd4a3785f 100644 --- a/src/shared/exec-util.h +++ b/src/shared/exec-util.h @@ -15,9 +15,10 @@ enum { }; typedef enum { - EXEC_DIR_NONE = 0, /* No execdir flags */ - EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */ - EXEC_DIR_IGNORE_ERRORS = 1 << 1, /* Ignore non-zero exit status of scripts */ + EXEC_DIR_NONE = 0, /* No execdir flags */ + EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */ + EXEC_DIR_IGNORE_ERRORS = 1 << 1, /* Ignore non-zero exit status of scripts */ + EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 << 2, /* Set $SYSTEMD_EXEC_PID environment variable */ } ExecDirFlags; typedef enum ExecCommandFlags { -- cgit v1.2.1