tree-wide: Migrate to pidref_safe_fork()

Let's migrate all remaining callers of safe_fork()
to pidref_safe_fork() and get rid of safe_fork().
This commit is contained in:
Daan De Meyer
2026-01-02 20:08:41 +01:00
committed by DaanDeMeyer
parent e6703a9aa4
commit 52ecf376fa
60 changed files with 321 additions and 303 deletions
+7 -5
View File
@@ -18,6 +18,7 @@
#include "log.h"
#include "main-func.h"
#include "pidfd-util.h"
#include "pidref.h"
#include "pretty-print.h"
#include "process-util.h"
#include "socket-netlink.h"
@@ -238,7 +239,6 @@ static int exec_process(char * const *argv, int start_fd, size_t n_fds) {
static int fork_and_exec_process(char * const *argv, int fd) {
_cleanup_free_ char *joined = NULL;
pid_t child_pid;
int r;
assert(!strv_isempty(argv));
@@ -248,9 +248,11 @@ static int fork_and_exec_process(char * const *argv, int fd) {
if (!joined)
return log_oom();
r = safe_fork("(activate)",
FORK_RESET_SIGNALS | FORK_DEATHSIG_SIGTERM | FORK_RLIMIT_NOFILE_SAFE | FORK_LOG,
&child_pid);
_cleanup_(pidref_done) PidRef child_pidref = PIDREF_NULL;
r = pidref_safe_fork(
"(activate)",
FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG,
&child_pidref);
if (r < 0)
return r;
if (r == 0) {
@@ -259,7 +261,7 @@ static int fork_and_exec_process(char * const *argv, int fd) {
_exit(EXIT_FAILURE);
}
log_info("Spawned '%s' as PID " PID_FMT ".", joined, child_pid);
log_info("Spawned '%s' as PID " PID_FMT ".", joined, child_pidref.pid);
return 0;
}