Markus Gothe wrote:
Without this fix it will create zombies that might cause deadlocks,
especially when respawned from the inittab and it dies because of a signal (e.g. ‘killall -9 runsvdir').

Installing a simple SIGCHLD-handler makes the problem go away.

Signed-off-by: Markus Gothe <nietzs...@lysator.liu.se <mailto:nietzs...@lysator.liu.se>>

diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index 11ab40a..dca2232 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -232,6 +232,15 @@ static NOINLINE int do_rescan(void)
return need_rescan;
 }


+static void signal_child(int sig UNUSED_PARAM){
+/* reap children if we die */
+for (;;) {
+pid_t pid = wait_any_nohang(NULL);
+if (pid <= 0)
+break;
+}
+}
+
 int runsvdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int runsvdir_main(int argc UNUSED_PARAM, char **argv)
 {
@@ -269,6 +278,11 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
*/
| (i_am_init ? ((1 << SIGUSR1) | (1 << SIGUSR2) | (1 << SIGINT)) : 0)
, record_signo);
+
+/* Install child-handler for reaping children. */
+bb_signals(0
++ (1 << SIGCHLD)
+, signal_child);
svdir = *argv++;


 #if ENABLE_FEATURE_RUNSVDIR_LOG
@@ -369,12 +383,14 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
 #endif
{
unsigned deadline = (need_rescan ? 1 : 5);
+sig_block(SIGCHLD);
 #if ENABLE_FEATURE_RUNSVDIR_LOG
if (rplog)
poll(pfd, 1, deadline*1000);
else
 #endif
sleep(deadline);
+sig_unblock(SIGCHLD);
}


 #if ENABLE_FEATURE_RUNSVDIR_LOG
According to your previous email, the testcase is this: 'killall runsvdir'.
So how does installing a handler for SIGCHLD have an effect on the behavior of the program when it receives a SIGTERM? Why should there be children some terminated children when runsvdir is killed? And what exactly is the testcase besides 'killall runsvdir'? Can you run strace on runsvdir and the child and show what happens? So far you have proposed a patch, but it's not clear what problem it is supposed to fix.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to