process-util: Use ret as output parameter name

There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.
This commit is contained in:
Daan De Meyer
2026-01-02 19:44:18 +01:00
committed by DaanDeMeyer
parent 944ae1286b
commit e6703a9aa4
17 changed files with 46 additions and 44 deletions
+18 -18
View File
@@ -1407,7 +1407,7 @@ int pidref_safe_fork_full(
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;
@@ -1421,7 +1421,7 @@ int pidref_safe_fork_full(
(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;
@@ -1465,7 +1465,7 @@ int pidref_safe_fork_full(
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();
@@ -1499,7 +1499,7 @@ int pidref_safe_fork_full(
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 */
@@ -1569,19 +1569,19 @@ int pidref_safe_fork_full(
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);
}
}
@@ -1763,11 +1763,11 @@ int pidref_safe_fork_full(
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);
@@ -1784,20 +1784,20 @@ int safe_fork_full(
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;
}
+6 -6
View File
@@ -186,10 +186,10 @@ int pidref_safe_fork_full(
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(
@@ -198,10 +198,10 @@ 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(
+1 -1
View File
@@ -660,7 +660,7 @@ static int asynchronous_expire(int dev_autofs_fd, int ioctl_fd) {
(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;
+1 -1
View File
@@ -2665,7 +2665,7 @@ static int ext4_offline_resize_fs(
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) {
+3 -3
View File
@@ -306,7 +306,7 @@ int import_mangle_os_tree_fd_foreign(
/* 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) {
@@ -406,7 +406,7 @@ int import_copy_foreign(
/* 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) {
@@ -464,7 +464,7 @@ int import_remove_tree_foreign(const char *path, int *userns_fd) {
/* 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) {
+1 -1
View File
@@ -1026,7 +1026,7 @@ static int connect_as(int fd, const struct sockaddr *sa, socklen_t salen, uid_t
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) {
+2 -2
View File
@@ -1160,7 +1160,7 @@ static int unprivileged_remove(Image *i) {
/* 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) {
@@ -1513,7 +1513,7 @@ static int unpriviled_clone(Image *i, const char *new_path) {
/* 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) {
+1 -1
View File
@@ -689,7 +689,7 @@ int make_filesystem(
/* except_fds= */ NULL,
/* n_except_fds= */ 0,
fork_flags,
/* ret_pid= */ NULL);
/* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
+1 -1
View File
@@ -1457,7 +1457,7 @@ int mount_fd_clone(int mount_fd, bool recursive, int *replacement_fd) {
/* 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]);
+1 -1
View File
@@ -557,7 +557,7 @@ static int unmerge(
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) {
+2 -2
View File
@@ -63,7 +63,7 @@ static void test_rename_process_one(const char *p, int ret) {
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 */
@@ -80,7 +80,7 @@ TEST(rename_process_invalid) {
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 */
+1 -1
View File
@@ -220,7 +220,7 @@ TEST(protect_kernel_logs) {
}
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;
+1 -1
View File
@@ -490,7 +490,7 @@ static int run(int argc, char **argv) {
/* 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));
+1 -1
View File
@@ -475,7 +475,7 @@ static void test_find_executable_exec_one(const char *path) {
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));
+2 -2
View File
@@ -285,7 +285,7 @@ TEST(pid_get_cmdline_harder) {
}
#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) {
@@ -573,7 +573,7 @@ TEST(getpid_cached) {
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 */
+1 -1
View File
@@ -32,7 +32,7 @@ static void sfdisk(const char *sfdisk_path, LoopDevice *loop, const char *defini
/* 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);
+3 -1
View File
@@ -155,7 +155,9 @@ TEST(pid_getrlimit) {
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) {