Re: [PATCH] coreutils/timeout: send signals to all processes in a group

2020-12-12 Thread Laurent Bercot

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.


 That is a very disruptive change that modifies the semantics of
'timeout' entirely, and that leads to unintuitive behaviour for
instance wrt ^C when used in a terminal.
 Well-behaved programs should never need signals sent to the process
group, and when a utility does that it should be *very obvious*.

 At the very least, if the functionality is implemented, it needs to
be configurable via a command-line option.

--
 Laurent

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] coreutils/timeout: send signals to all processes in a group

2020-12-11 Thread Alakesh Haloi
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 
---
 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

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox