1
0
mirror of https://github.com/systemd/systemd.git synced 2025-09-13 05:44:40 +03:00

core: also set $SYSTEMD_EXEC_PID= for generators

This commit is contained in:
Yu Watanabe
2021-02-01 00:51:33 +09:00
parent cfd1c6e262
commit 43f565c677
3 changed files with 16 additions and 7 deletions

View File

@@ -4105,7 +4105,8 @@ static int manager_run_environment_generators(Manager *m) {
RUN_WITH_UMASK(0022) RUN_WITH_UMASK(0022)
r = execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, gather_environment, 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; return r;
} }
@@ -4140,7 +4141,8 @@ static int manager_run_generators(Manager *m) {
RUN_WITH_UMASK(0022) RUN_WITH_UMASK(0022)
(void) execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, NULL, NULL, (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; r = 0;

View File

@@ -34,7 +34,7 @@
/* Put this test here for a lack of better place */ /* Put this test here for a lack of better place */
assert_cc(EAGAIN == EWOULDBLOCK); 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; pid_t _pid;
int r; 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(); (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) { if (!argv) {
_argv[0] = (char*) path; _argv[0] = (char*) path;
_argv[1] = NULL; _argv[1] = NULL;
@@ -132,7 +138,7 @@ static int do_execute(
return log_error_errno(fd, "Failed to open serialization file: %m"); 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) if (r <= 0)
continue; continue;

View File

@@ -15,9 +15,10 @@ enum {
}; };
typedef enum { typedef enum {
EXEC_DIR_NONE = 0, /* No execdir flags */ EXEC_DIR_NONE = 0, /* No execdir flags */
EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */ 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_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; } ExecDirFlags;
typedef enum ExecCommandFlags { typedef enum ExecCommandFlags {