From b3fdc8d6a5c2a097acbfc677a0bd251331a647ca Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 4 Aug 2026 11:46:35 +0200 Subject: [PATCH] Add fallback to kill(pid, sig) when process group signaling returns ESRCH in os_term and os_kill --- os/unix.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/os/unix.c b/os/unix.c index 7467c992..e575f895 100644 --- a/os/unix.c +++ b/os/unix.c @@ -1349,7 +1349,17 @@ int os_term(pid_t pid) * This ensures that SnapRAID and any programs it may have spawned are * terminated together, preventing orphaned worker processes. */ - return kill(-pid, SIGTERM); + int ret = kill(-pid, SIGTERM); + + /* + * If setpgid(0, 0) has not yet executed in the child, process group -pid + * does not exist and kill() returns ESRCH. Fallback to targeting the process directly. + */ + if (ret < 0 && errno == ESRCH) { + ret = kill(pid, SIGTERM); + } + + return ret; } int os_kill(pid_t pid) @@ -1360,7 +1370,17 @@ int os_kill(pid_t pid) } /* Send SIGKILL signal to the negative PID to target the entire Process Group */ - return kill(-pid, SIGKILL); + int ret = kill(-pid, SIGKILL); + + /* + * If setpgid(0, 0) has not yet executed in the child, process group -pid + * does not exist and kill() returns ESRCH. Fallback to targeting the process directly. + */ + if (ret < 0 && errno == ESRCH) { + ret = kill(pid, SIGKILL); + } + + return ret; } int os_spawn_and_wait(const char** argv)