[PATCH] coreutils/timeout: send signals to all processes in a group
Alakesh Haloi
alakesh.haloi at gmail.com
Fri Dec 11 21:28:43 UTC 2020
In current implementation of busybox timeout utility, when a signal
is sent to the process that needs to timeout, it does not affect the
children. To fix this we set the process group id of the process that
the signal is sent, same as it's pid, making it the process group
leader. When sending signal, we sent it to negative pid number as per
man page and signal is received by all children.
Signed-off-by: Alakesh Haloi <alakesh.haloi at gmail.com>
---
coreutils/timeout.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/coreutils/timeout.c b/coreutils/timeout.c
index 2a628b71d..3a5367718 100644
--- a/coreutils/timeout.c
+++ b/coreutils/timeout.c
@@ -95,6 +95,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
if (pid == 0) {
/* Child: spawn grandchild and exit */
parent = getppid();
+ /* Set parent as process group leader */
+ setpgid(parent, 0);
#if !BB_MMU
argv[optind] = xasprintf("-p%u", parent);
argv[optind + 1] = NULL;
@@ -113,7 +115,9 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
return EXIT_SUCCESS;
}
}
- kill(parent, signo);
+
+ /* send signal to process group */
+ kill(-parent, signo);
return EXIT_SUCCESS;
}
--
2.17.1
More information about the busybox
mailing list