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
+5 -13
View File
@@ -5540,7 +5540,6 @@ int unit_set_exec_params(Unit *u, ExecParameters *p) {
int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, ForkFlags flags, PidRef *ret) {
CGroupRuntime *crt = NULL;
pid_t pid;
int r;
assert(u);
@@ -5548,8 +5547,8 @@ int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, F
assert(ret);
/* Forks off a helper process and makes sure it is a member of the unit's cgroup, if configured to
* do so. Returns == 0 in the child, and > 0 in the parent. The pid parameter is always filled in
* with the child's PID. */
* do so. Returns == 0 in the child, and > 0 in the parent. The pidref parameter is always filled in
* with the child's PID reference. */
if (into_cgroup) {
r = unit_realize_cgroup(u);
@@ -5559,19 +5558,11 @@ int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, F
crt = unit_get_cgroup_runtime(u);
}
r = safe_fork(name, FORK_REOPEN_LOG|FORK_DEATHSIG_SIGTERM|flags, &pid);
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
r = pidref_safe_fork(name, FORK_REOPEN_LOG|FORK_DEATHSIG_SIGTERM|flags, &pidref);
if (r < 0)
return r;
if (r > 0) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
int q;
/* Parent */
q = pidref_set_pid(&pidref, pid);
if (q < 0)
return q;
*ret = TAKE_PIDREF(pidref);
return r;
}
@@ -5589,6 +5580,7 @@ int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, F
}
}
*ret = TAKE_PIDREF(pidref);
return 0;
}