summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-02-01 00:51:33 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-01 01:13:44 +0900
commit43f565c6770f940a978a5325fea8b0e6d8ee4c99 (patch)
tree43ee10df7871ae002cee12571d1571e4ec74e2ac /src
parentcfd1c6e26280f27454a0759853befee08382bf7d (diff)
downloadsystemd-43f565c6770f940a978a5325fea8b0e6d8ee4c99.tar.gz
core: also set $SYSTEMD_EXEC_PID= for generators
Diffstat (limited to 'src')
-rw-r--r--src/core/manager.c6
-rw-r--r--src/shared/exec-util.c10
-rw-r--r--src/shared/exec-util.h7
3 files changed, 16 insertions, 7 deletions
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 {