diff options
author | Luca Boccassi <bluca@debian.org> | 2024-05-29 22:17:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 22:17:13 +0200 |
commit | 1af8b31e67453e6f21aade1ee3e68c56bad6f261 (patch) | |
tree | 1fc8da1622a5adf16c80b54f1aec0af87c4e3eb8 /src | |
parent | Merge pull request #33062 from DaanDeMeyer/virtio-scsi (diff) | |
parent | exec-util: make sure to close all fds for invoked generators (diff) | |
download | systemd-1af8b31e67453e6f21aade1ee3e68c56bad6f261.tar.xz systemd-1af8b31e67453e6f21aade1ee3e68c56bad6f261.zip |
Merge pull request #33072 from poettering/generator-fixes
various fixes to generator execution
Diffstat (limited to 'src')
-rw-r--r-- | src/core/generator-setup.c | 12 | ||||
-rw-r--r-- | src/shared/exec-util.c | 30 |
2 files changed, 22 insertions, 20 deletions
diff --git a/src/core/generator-setup.c b/src/core/generator-setup.c index 00d6ad61fa..b16211e8f4 100644 --- a/src/core/generator-setup.c +++ b/src/core/generator-setup.c @@ -8,7 +8,7 @@ #include "rm-rf.h" int lookup_paths_mkdir_generator(LookupPaths *p) { - int r, q; + int r; assert(p); @@ -16,14 +16,8 @@ int lookup_paths_mkdir_generator(LookupPaths *p) { return -EINVAL; r = mkdir_p_label(p->generator, 0755); - - q = mkdir_p_label(p->generator_early, 0755); - if (q < 0 && r >= 0) - r = q; - - q = mkdir_p_label(p->generator_late, 0755); - if (q < 0 && r >= 0) - r = q; + RET_GATHER(r, mkdir_p_label(p->generator_early, 0755)); + RET_GATHER(r, mkdir_p_label(p->generator_late, 0755)); return r; } diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 1c7b14d98d..996edbf997 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -36,27 +36,35 @@ /* 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, bool set_systemd_exec_pid) { - pid_t _pid; +static int do_spawn( + const char *path, + char *argv[], + int stdout_fd, + bool set_systemd_exec_pid, + pid_t *ret_pid) { + int r; + assert(path); + assert(ret_pid); + if (null_or_empty_path(path) > 0) { log_debug("%s is empty (a mask).", path); return 0; } - r = safe_fork("(direxec)", FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_RLIMIT_NOFILE_SAFE, &_pid); + pid_t pid; + r = safe_fork_full( + "(direxec)", + (const int[]) { STDIN_FILENO, stdout_fd < 0 ? STDOUT_FILENO : stdout_fd, STDERR_FILENO }, + /* except_fds= */ NULL, /* n_except_fds= */ 0, + FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_RLIMIT_NOFILE_SAFE|FORK_REARRANGE_STDIO|FORK_CLOSE_ALL_FDS, + &pid); if (r < 0) return r; if (r == 0) { char *_argv[2]; - if (stdout_fd >= 0) { - r = rearrange_stdio(STDIN_FILENO, TAKE_FD(stdout_fd), STDERR_FILENO); - if (r < 0) - _exit(EXIT_FAILURE); - } - if (set_systemd_exec_pid) { r = setenv_systemd_exec_pid(false); if (r < 0) @@ -75,7 +83,7 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid, b _exit(EXIT_FAILURE); } - *pid = _pid; + *ret_pid = pid; return 1; } @@ -147,7 +155,7 @@ static int do_execute( log_debug("About to execute %s%s%s", t, argv ? " " : "", argv ? strnull(args) : ""); } - r = do_spawn(t, argv, fd, &pid, FLAGS_SET(flags, EXEC_DIR_SET_SYSTEMD_EXEC_PID)); + r = do_spawn(t, argv, fd, FLAGS_SET(flags, EXEC_DIR_SET_SYSTEMD_EXEC_PID), &pid); if (r <= 0) continue; |