]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: Use ret as output parameter name
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 20 Dec 2025 09:48:41 +0000 (10:48 +0100)
committerDaanDeMeyer <daan.j.demeyer@gmail.com>
Fri, 2 Jan 2026 18:44:18 +0000 (19:44 +0100)
There's only one output parameter for all these
functions, so let's just name it ret following the
coding style.

17 files changed:
src/basic/process-util.c
src/basic/process-util.h
src/core/automount.c
src/home/homework-luks.c
src/import/import-common.c
src/libsystemd/sd-bus/bus-socket.c
src/shared/discover-image.c
src/shared/mkfs-util.c
src/shared/mount-util.c
src/sysext/sysext.c
src/test/test-argv-util.c
src/test/test-namespace.c
src/test/test-nss-hosts.c
src/test/test-path-util.c
src/test/test-process-util.c
src/test/test-reread-partition-table.c
src/test/test-rlimit-util.c

index 63223a635e5b7186f9a200efcc836efd768e17e8..53845cc213b6b668b6851104571fdd1156de03c4 100644 (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;
 }
index ecd010f38f3f2745ce7bd97fa7bcc381b30872e7..0b8587bed40dfcc5e827ce2d321cb2d792abd08e 100644 (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(
index 6543204400149fbc33f29b71d4f9ea3c8fe84385..b70ef42abafd3d5205bb24301cad69fc31d1775f 100644 (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;
 
index 10ed181fcf53aa210da41f963705fba97bc46bbc..9147b3dfcfbe88ec2e971d846b3472dbe172d710 100644 (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) {
index c9d0672e7ff5de997d36347a53fa3924861be2b8..b0a54e8b43f7955f3560331e778fd6621770a413 100644 (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) {
index 32eda5627e71d0ad493e86acb00642259d78ebc5..93550a668f78664b36459801e6cb1f3dbfa5cc9c 100644 (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) {
index fa92b47172363d48d1434e8dc32831182a379613..bccd1590798a2f2747f1e63f1a9fd41d4639fdce 100644 (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) {
index c9dd431795f3fbf83c3362257e3c3dd8932b3406..be9b30b47e0434f2a505596f74ebb7a7d34f9835 100644 (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) {
index 12d9cdaeb87af48645c537bd4592b2d98b0f0fc9..d98a9616fcb3583282e16f82fb4a9e59e63606fc 100644 (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]);
 
index 33a5ea8bcda09ee783f3e843ea7a8317e4b415ae..931aadea4c059ad61d5032ddbc86656d714c758f 100644 (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) {
index f449f2aefa2c2993f51bcb8536bb9d12b9d49ead..153278efb3fceae24f542833fe74563334718df3 100644 (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 */
index 4890ecc72958b2f779957f538c570e473d38b05f..b3ac293be3fe17e2f966b0dfa3a50881d2f4559e 100644 (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;
index 0307bcb45ccd85fce4f8de34e6736cc6896494ea..4b82b96d1a723c068bb14cc668c0535d5f9da559 100644 (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));
index 3df3e747ffafe6b17201d7e381e1a25d7e20bfaf..2a909e95ddf9e5c5634f0e39771f0150d07d0ae2 100644 (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));
index d4f39bf3ee91ccce19558bfddae06c5f6c7ddb4e..31e79370b52d67048c1681c23052b0425bd97bb4 100644 (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 */
index 53e72b7f13ee6bea2afc76f320225988a7020099..3897a30653069adedee54af19ebf6c04ee79eb21 100644 (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);
index 2d5d5d4d486f8050eb0950dfef068ce9baf3fd67..962c776bd32c484d552d213df1d74a6e40a7cb5f 100644 (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) {