timeout: ensure we terminate command upon abnormal exit

* src/timeout.c (main): Use PR_SET_PDEATHSIG to ensure the
child is terminated even if the parent terminates abnormally.
* tests/timeout/timeout-group.sh: Add a case to ensure sending
SIGKILL results in the termination of the monitored command.
* NEWS: Mention the improvement.
This commit is contained in:
Pádraig Brady committed 2025-11-29 12:17:27 +00:00
1 parent d1d311e7a2
commit fc5c7b2e47
3 files changed
+30 -1

No files matched your search

+8
View File
@@ -592,6 +592,14 @@ main (int argc, char **argv)
}
else if (monitored_pid == 0) /* child */
{
#if HAVE_PRCTL
/* Add protection if the parent dies without signalling child. */
prctl (PR_SET_PDEATHSIG, term_signal);
#endif
/* If we're already reparented to init, don't proceed. */
if (getppid () == 1)
return EXIT_CANCELED;
/* Restore signal mask for child. */
if (sigprocmask (SIG_SETMASK, &orig_set, nullptr) != 0)
{