mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-01 20:36:38 -05:00
Add fallback to kill(pid, sig) when process group signaling returns ESRCH in os_term and os_kill
This commit is contained in:
parent
6b46e08a1f
commit
b3fdc8d6a5
1 changed files with 22 additions and 2 deletions
24
os/unix.c
24
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
|
* This ensures that SnapRAID and any programs it may have spawned are
|
||||||
* terminated together, preventing orphaned worker processes.
|
* 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)
|
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 */
|
/* 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)
|
int os_spawn_and_wait(const char** argv)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue