int except_fds[],
size_t n_except_fds,
ForkFlags flags,
- PidRef *ret_pid) {
+ PidRef *ret) {
pid_t original_pid, pid;
sigset_t saved_ss, ss;
(flags & (FORK_WAIT|FORK_DEATHSIG_SIGTERM|FORK_DEATHSIG_SIGINT|FORK_DEATHSIG_SIGKILL)) == 0);
/* A wrapper around fork(), that does a couple of important initializations in addition to mere
- * forking. If provided, ret_pid is initialized in both the parent and the child process, both times
+ * forking. If provided, ret is initialized in both the parent and the child process, both times
* referencing the child process. Returns == 0 in the child and > 0 in the parent. */
prio = flags & FORK_LOG ? LOG_ERR : LOG_DEBUG;
if (!r) {
/* Not a reaper process, hence do a double fork() so we are reparented to one */
- if (ret_pid && socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, pidref_transport_fds) < 0)
+ if (ret && socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, pidref_transport_fds) < 0)
return log_full_errno(prio, errno, "Failed to allocate pidref socket: %m");
pid = fork();
if (n < 0)
return log_full_errno(prio, n, "Failed to receive child pidref: %m");
- *ret_pid = (PidRef) { .pid = pid, .fd = pidfd };
+ *ret = (PidRef) { .pid = pid, .fd = pidfd };
}
return 1; /* return in the parent */
return -EPROTO;
/* If we are in the parent and successfully waited, then the process doesn't exist anymore. */
- if (ret_pid)
- *ret_pid = PIDREF_NULL;
+ if (ret)
+ *ret = PIDREF_NULL;
return 1;
}
- if (ret_pid) {
+ if (ret) {
if (FLAGS_SET(flags, _FORK_PID_ONLY))
- *ret_pid = PIDREF_MAKE_FROM_PID(pid);
+ *ret = PIDREF_MAKE_FROM_PID(pid);
else {
- r = pidref_set_pid(ret_pid, pid);
+ r = pidref_set_pid(ret, pid);
if (r < 0) /* Let's not fail for this, no matter what, the process exists after all, and that's key */
- *ret_pid = PIDREF_MAKE_FROM_PID(pid);
+ *ret = PIDREF_MAKE_FROM_PID(pid);
}
}
if (FLAGS_SET(flags, FORK_FREEZE))
freeze();
- if (ret_pid) {
+ if (ret) {
if (FLAGS_SET(flags, _FORK_PID_ONLY))
- *ret_pid = PIDREF_MAKE_FROM_PID(getpid_cached());
+ *ret = PIDREF_MAKE_FROM_PID(getpid_cached());
else {
- r = pidref_set_self(ret_pid);
+ r = pidref_set_self(ret);
if (r < 0) {
log_full_errno(prio, r, "Failed to acquire PID reference on ourselves: %m");
_exit(EXIT_FAILURE);
int except_fds[],
size_t n_except_fds,
ForkFlags flags,
- pid_t *ret_pid) {
+ pid_t *ret) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
int r;
/* Getting the detached child process pid without pidfd is racy, so don't allow it if not returning
* a pidref to the caller. */
- assert(!FLAGS_SET(flags, FORK_DETACH) || !ret_pid);
+ assert(!FLAGS_SET(flags, FORK_DETACH) || !ret);
- r = pidref_safe_fork_full(name, stdio_fds, except_fds, n_except_fds, flags|_FORK_PID_ONLY, ret_pid ? &pidref : NULL);
- if (r < 0 || !ret_pid)
+ r = pidref_safe_fork_full(name, stdio_fds, except_fds, n_except_fds, flags|_FORK_PID_ONLY, ret ? &pidref : NULL);
+ if (r < 0 || !ret)
return r;
- *ret_pid = pidref.pid;
+ *ret = pidref.pid;
return r;
}
int except_fds[],
size_t n_except_fds,
ForkFlags flags,
- PidRef *ret_pid);
+ PidRef *ret);
-static inline int pidref_safe_fork(const char *name, ForkFlags flags, PidRef *ret_pid) {
- return pidref_safe_fork_full(name, NULL, NULL, 0, flags, ret_pid);
+static inline int pidref_safe_fork(const char *name, ForkFlags flags, PidRef *ret) {
+ return pidref_safe_fork_full(name, NULL, NULL, 0, flags, ret);
}
int safe_fork_full(
int except_fds[],
size_t n_except_fds,
ForkFlags flags,
- pid_t *ret_pid);
+ pid_t *ret);
-static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) {
- return safe_fork_full(name, NULL, NULL, 0, flags, ret_pid);
+static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret) {
+ return safe_fork_full(name, NULL, NULL, 0, flags, ret);
}
int namespace_fork_full(
(int[]) { dev_autofs_fd, ioctl_fd },
/* n_except_fds= */ 2,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_REOPEN_LOG,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r != 0)
return r;
r = pidref_safe_fork(
"(e2resize)",
FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_WAIT|FORK_STDOUT_TO_STDERR|FORK_CLOSE_ALL_FDS,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { userns_fd, tree_fd }, 2,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_REOPEN_LOG|FORK_WAIT,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { *userns_fd, source_fd, target_fd }, 3,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_REOPEN_LOG|FORK_WAIT,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { *userns_fd, tree_fd }, 2,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_REOPEN_LOG|FORK_WAIT,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
if (pipe2(pfd, O_CLOEXEC) < 0)
return -errno;
- r = safe_fork("(sd-setresuid)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_WAIT, /* ret_pid= */ NULL);
+ r = safe_fork("(sd-setresuid)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_WAIT, /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { userns_fd, tree_fd, }, 2,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_WAIT|FORK_REOPEN_LOG,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return log_debug_errno(r, "Process that was supposed to remove tree failed: %m");
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { userns_fd, tree_fd, target_fd }, 3,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_WAIT|FORK_REOPEN_LOG,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return log_debug_errno(r, "Process that was supposed to clone tree failed: %m");
if (r == 0) {
/* except_fds= */ NULL,
/* n_except_fds= */ 0,
fork_flags,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
/* stdio_fds= */ NULL,
(int[]) { mount_fd, transfer_fds[1], errno_pipe_fds[1] }, 3,
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGKILL|FORK_REOPEN_LOG|FORK_WAIT|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r < 0) {
errno_pipe_fds[1] = safe_close(errno_pipe_fds[1]);
return r;
need_to_reload = r > 0;
- r = safe_fork("(sd-unmerge)", FORK_WAIT|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_NEW_MOUNTNS, /* ret_pid= */ NULL);
+ r = safe_fork("(sd-unmerge)", FORK_WAIT|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_NEW_MOUNTNS, /* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
log_info("/* %s(%s) */", __func__, p);
- r = ASSERT_OK(safe_fork("(rename)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(rename)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret= */ NULL));
if (r == 0) {
/* child */
TEST(rename_process_multi) {
int r;
- r = ASSERT_OK(safe_fork("(rename)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(rename)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret= */ NULL));
if (r == 0) {
/* child */
}
ASSERT_OK(r);
- r = ASSERT_OK(safe_fork("(protect)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(protect)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret= */ NULL));
if (r == 0) {
_cleanup_close_ int fd = -EBADF;
/* Testing with several syscalls filtered, and check if the nss modules gracefully handle failures in
* masked syscalls. See issue #38582. */
- ASSERT_OK(r = safe_fork("(with-seccomp)", FORK_LOG | FORK_WAIT, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(with-seccomp)", FORK_LOG|FORK_WAIT, /* ret= */ NULL));
if (r == 0) {
_cleanup_hashmap_free_ Hashmap *filter = NULL;
ASSERT_NOT_NULL(filter = hashmap_new(NULL));
if (path_is_absolute(path))
ASSERT_STREQ(t, path);
- r = ASSERT_OK(safe_fork("(find-exec)", FORK_LOG|FORK_DEATHSIG_SIGKILL|FORK_WAIT, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(find-exec)", FORK_LOG|FORK_DEATHSIG_SIGKILL|FORK_WAIT, /* ret= */ NULL));
if (r == 0) {
r = fexecve_or_execve(fd, t, STRV_MAKE(t, "--version"), STRV_MAKE(NULL));
}
#endif
- r = ASSERT_OK(safe_fork("(cmdline)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(cmdline)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret= */ NULL));
if (r == 0) {
r = detach_mount_namespace();
if (r < 0) {
ASSERT_EQ(a, b);
ASSERT_EQ(a, c);
- r = ASSERT_OK(safe_fork("(getpid)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret_pid= */ NULL));
+ r = ASSERT_OK(safe_fork("(getpid)", FORK_WAIT|FORK_LOG|FORK_DEATHSIG_SIGKILL, /* ret= */ NULL));
if (r == 0) {
/* In child */
/* except_fds= */ NULL,
/* n_except_fds= */ 0,
FORK_CLOSE_ALL_FDS|FORK_RESET_SIGNALS|FORK_REARRANGE_STDIO|FORK_LOG|FORK_WAIT,
- /* ret_pid= */ NULL);
+ /* ret= */ NULL);
if (r == 0) {
/* child */
execl(sfdisk_path, "fdisk", "--no-tell-kernel", "--no-reread", loop->node, NULL);
assert_se(getrlimit(resource, &direct) >= 0);
/* We fork off a child so that getrlimit() doesn't work anymore */
- r = safe_fork("(getrlimit)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_LOG|FORK_WAIT, /* ret_pid= */ NULL);
+ r = safe_fork("(getrlimit)",
+ FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_LOG|FORK_WAIT,
+ /* ret= */ NULL);
assert_se(r >= 0);
if (r == 0) {