process-util: introduce new FORK_FREEZE flag for safe_fork()

Often we want to fork off a process that just hangs until we kill it,
let's add a simple flag to create one of this type, and use it at
various places.
This commit is contained in:
Lennart Poettering
2025-01-16 11:55:21 +01:00
parent 8110b34b64
commit 6eeeef9f66
4 changed files with 14 additions and 32 deletions
+4 -20
View File
@@ -159,12 +159,8 @@ TEST(pidref_new_from_pid) {
TEST(pidref_kill) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
siginfo_t si;
int r;
r = pidref_safe_fork("(test-pidref-kill)", FORK_DEATHSIG_SIGKILL, &pidref);
assert_se(r >= 0);
if (r == 0)
freeze();
ASSERT_OK_POSITIVE(pidref_safe_fork("(test-pidref-kill)", FORK_DEATHSIG_SIGKILL|FORK_FREEZE, &pidref));
assert_se(pidref_kill(&pidref, SIGKILL) >= 0);
assert_se(pidref_wait_for_terminate(&pidref, &si) >= 0);
@@ -174,12 +170,8 @@ TEST(pidref_kill) {
TEST(pidref_kill_and_sigcont) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
siginfo_t si;
int r;
r = pidref_safe_fork("(test-pidref-kill-and-sigcont)", FORK_DEATHSIG_SIGTERM, &pidref);
assert_se(r >= 0);
if (r == 0)
freeze();
ASSERT_OK_POSITIVE(pidref_safe_fork("(test-pidref-kill-and-sigcont)", FORK_DEATHSIG_SIGTERM|FORK_FREEZE, &pidref));
assert_se(pidref_kill_and_sigcont(&pidref, SIGTERM) >= 0);
assert_se(pidref_wait_for_terminate(&pidref, &si) >= 0);
@@ -189,12 +181,8 @@ TEST(pidref_kill_and_sigcont) {
TEST(pidref_sigqueue) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
siginfo_t si;
int r;
r = pidref_safe_fork("(test-pidref-sigqueue)", FORK_DEATHSIG_SIGTERM, &pidref);
assert_se(r >= 0);
if (r == 0)
freeze();
ASSERT_OK_POSITIVE(pidref_safe_fork("(test-pidref-sigqueue)", FORK_DEATHSIG_SIGTERM|FORK_FREEZE, &pidref));
assert_se(pidref_sigqueue(&pidref, SIGTERM, 42) >= 0);
assert_se(pidref_wait_for_terminate(&pidref, &si) >= 0);
@@ -203,12 +191,8 @@ TEST(pidref_sigqueue) {
TEST(pidref_done_sigkill_wait) {
_cleanup_(pidref_done_sigkill_wait) PidRef pidref = PIDREF_NULL;
int r;
r = pidref_safe_fork("(test-pidref-done-sigkill-wait)", FORK_DEATHSIG_SIGKILL, &pidref);
assert_se(r >= 0);
if (r == 0)
freeze();
ASSERT_OK_POSITIVE(pidref_safe_fork("(test-pidref-done-sigkill-wait)", FORK_DEATHSIG_SIGKILL|FORK_FREEZE, &pidref));
}
TEST(pidref_verify) {