From: Daan De Meyer Date: Sat, 20 Dec 2025 09:48:41 +0000 (+0100) Subject: process-util: Use ret as output parameter name X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6703a9aa44a83a6adf3cfc423316c90d6dd7ee1;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 63223a635e5..53845cc213b 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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; } diff --git a/src/basic/process-util.h b/src/basic/process-util.h index ecd010f38f3..0b8587bed40 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -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( diff --git a/src/core/automount.c b/src/core/automount.c index 65432044001..b70ef42abaf 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -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; diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 10ed181fcf5..9147b3dfcfb 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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) { diff --git a/src/import/import-common.c b/src/import/import-common.c index c9d0672e7ff..b0a54e8b43f 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -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) { diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 32eda5627e7..93550a668f7 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -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) { diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index fa92b471723..bccd1590798 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -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) { diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index c9dd431795f..be9b30b47e0 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -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) { diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 12d9cdaeb87..d98a9616fcb 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -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]); diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 33a5ea8bcda..931aadea4c0 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -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) { diff --git a/src/test/test-argv-util.c b/src/test/test-argv-util.c index f449f2aefa2..153278efb3f 100644 --- a/src/test/test-argv-util.c +++ b/src/test/test-argv-util.c @@ -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 */ diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index 4890ecc7295..b3ac293be3f 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -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; diff --git a/src/test/test-nss-hosts.c b/src/test/test-nss-hosts.c index 0307bcb45cc..4b82b96d1a7 100644 --- a/src/test/test-nss-hosts.c +++ b/src/test/test-nss-hosts.c @@ -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)); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 3df3e747ffa..2a909e95ddf 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -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)); diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index d4f39bf3ee9..31e79370b52 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -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 */ diff --git a/src/test/test-reread-partition-table.c b/src/test/test-reread-partition-table.c index 53e72b7f13e..3897a306530 100644 --- a/src/test/test-reread-partition-table.c +++ b/src/test/test-reread-partition-table.c @@ -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); diff --git a/src/test/test-rlimit-util.c b/src/test/test-rlimit-util.c index 2d5d5d4d486..962c776bd32 100644 --- a/src/test/test-rlimit-util.c +++ b/src/test/test-rlimit-util.c @@ -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) {