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
+4 -1
View File
@@ -1026,7 +1026,10 @@ 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= */ NULL);
r = pidref_safe_fork(
"(sd-setresuid)",
FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_WAIT,
/* ret= */ NULL);
if (r < 0)
return r;
if (r == 0) {
+1 -1
View File
@@ -26,7 +26,7 @@ static void test_bus_fork(void) {
assert_se(bus->n_ref == 1);
/* Check that after a fork the cleanup functions return NULL */
r = safe_fork("(bus-fork-test)", FORK_WAIT|FORK_LOG, NULL);
r = pidref_safe_fork("(bus-fork-test)", FORK_WAIT|FORK_LOG, NULL);
if (r == 0) {
assert_se(bus);
ASSERT_RETURN_EXPECTED_SE(sd_bus_is_ready(bus) == -ECHILD);
+4 -1
View File
@@ -39,7 +39,10 @@ TEST(mdio_bus) {
if (running_in_chroot() > 0)
return (void) log_tests_skipped("Running in chroot");
ASSERT_OK(r = safe_fork("(mdio_bus)", FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_REOPEN_LOG|FORK_LOG|FORK_WAIT|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE, NULL));
r = ASSERT_OK(pidref_safe_fork(
"(mdio_bus)",
FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_REOPEN_LOG|FORK_LOG|FORK_WAIT|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE,
NULL));
if (r == 0) {
const char *syspath = "/sys/bus/mdio_bus/drivers/Qualcomm Atheros AR8031!AR8033";
const char *id = "+drivers:mdio_bus:Qualcomm Atheros AR8031!AR8033";
+1 -1
View File
@@ -851,7 +851,7 @@ TEST(fork) {
ASSERT_OK_ZERO(sd_event_prepare(e));
/* Check that after a fork the cleanup functions return NULL */
r = safe_fork("(bus-fork-test)", FORK_WAIT|FORK_LOG, NULL);
r = pidref_safe_fork("(bus-fork-test)", FORK_WAIT|FORK_LOG, NULL);
if (r == 0) {
ASSERT_NOT_NULL(e);
ASSERT_NULL(sd_event_ref(e));
@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
assert_se(sd_journal_seek_head(j) == 0);
assert_se(j->current_location.type == LOCATION_HEAD);
r = safe_fork("(journal-fork-test)", FORK_WAIT|FORK_LOG, NULL);
r = pidref_safe_fork("(journal-fork-test)", FORK_WAIT|FORK_LOG, NULL);
if (r == 0) {
assert_se(j);
ASSERT_RETURN_EXPECTED_SE(sd_journal_get_realtime_usec(j, NULL) == -ECHILD);