]> The Tcpdump Group git mirrors - tcpdump/commitdiff
child_cleanup: reap as many child processes as possible
authorDominique Martinet <[email protected]>
Fri, 21 Jan 2022 01:27:07 +0000 (10:27 +0900)
committerFrancois-Xavier Le Bail <[email protected]>
Thu, 12 Oct 2023 12:26:08 +0000 (14:26 +0200)
Under load it's possible multiple child processes have been killed before
we start processing the SIGCHILD signal, leaving zombie processes behind
everytime we miss a process.
Reap as many processes as possible instead of assuming one handler
call = one process like we currently did.

Can be reproduced by running the following commands in parallel:
 - tcpdump -i lo -w /tmp/test -C 1 -z /usr/bin/true
 - iperf3 -s
 - iperf3 -c localhost

(cherry picked from commit b5f0be2196d897c76144a5b90b168836df54d6fa)

tcpdump.c

index c98265f404b6184ff9607c43a149a1a2406bdb0f..b7d0a3636356d91e72d35b65c025d17e8cf85840 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -2780,7 +2780,7 @@ cleanup(int signo _U_)
 static void
 child_cleanup(int signo _U_)
 {
-  wait(NULL);
+  while (waitpid(-1, NULL, WNOHANG) >= 0);
 }
 #endif /* HAVE_FORK && HAVE_VFORK */