From: Daan De Meyer Date: Thu, 18 Dec 2025 09:28:30 +0000 (+0100) Subject: process-util: Use pidref_wait_for_terminate_and_check in pidref_safe_fork() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c367868eeaa59e72ef8d5560bf0ae307ac3561a;p=thirdparty%2Fsystemd.git process-util: Use pidref_wait_for_terminate_and_check in pidref_safe_fork() Note that we still have to block SIGCHLD so that we can be certain the process is not reaped before we get the pidfd to it. safe_fork() and friends are used in libsystemd where we don't control how the SIGCHLD signal is configured. Specifically, kernel autoreaping could be enabled which is why we have to block SIGCHLD until we get the pidfd so that the kernel cannot autoreap the process before we get the pidfd. --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index f25f4b81e51..e319214f4aa 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1566,9 +1566,13 @@ int pidref_safe_fork_full( pidref_transport_fds[1] = safe_close(pidref_transport_fds[1]); if (pidref_transport_fds[0] >= 0) { - /* Wait for the intermediary child to exit so the caller can be certain the actual child - * process has been reparented by the time this function returns. */ - r = wait_for_terminate_and_check(name, pid, FLAGS_SET(flags, FORK_LOG) ? WAIT_LOG : 0); + /* Wait for the intermediary child to exit so the caller can be + * certain the actual child process has been reparented by the time + * this function returns. */ + r = pidref_wait_for_terminate_and_check( + name, + &PIDREF_MAKE_FROM_PID(pid), + FLAGS_SET(flags, FORK_LOG) ? WAIT_LOG : 0); if (r < 0) return log_full_errno(prio, r, "Failed to wait for intermediary process: %m"); if (r != EXIT_SUCCESS) /* exit status > 0 should be treated as failure, too */ @@ -1644,7 +1648,10 @@ int pidref_safe_fork_full( (void) sigprocmask(SIG_SETMASK, &ss, NULL); } - r = wait_for_terminate_and_check(name, pid, (flags & FORK_LOG ? WAIT_LOG : 0)); + r = pidref_wait_for_terminate_and_check( + name, + &PIDREF_MAKE_FROM_PID(pid), + FLAGS_SET(flags, FORK_LOG) ? WAIT_LOG : 0); if (r < 0) return r; if (r != EXIT_SUCCESS) /* exit status > 0 should be treated as failure, too */