Change SIGCHLD handler to SIG_DFL with SA_NOCLDWAIT flag set, to avoid transforming child processes into zombies when they terminate. Since the main process is inevitably blocked in NBD_DO_IT ioctl at the time when child processes terminate, this is the simplest way to get rid of zombie processes.
Signed-off-by: Dmitry V. Levin <[email protected]> --- nbd-client.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/nbd-client.c b/nbd-client.c index 7a526b9..2321e7b 100644 --- a/nbd-client.c +++ b/nbd-client.c @@ -35,6 +35,7 @@ #include <stdlib.h> #include <sys/mount.h> #include <sys/mman.h> +#include <signal.h> #include <errno.h> #include <getopt.h> #include <stdarg.h> @@ -571,6 +572,16 @@ int main(int argc, char *argv[]) { #endif do { #ifndef NOFORK +#ifdef SA_NOCLDWAIT + struct sigaction sa; + + sa.sa_handler = SIG_DFL; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_NOCLDWAIT; + if (sigaction(SIGCHLD, &sa, NULL) < 0) + err("sigaction: %m"); +#endif + if (!fork()) { /* Due to a race, the kernel NBD driver cannot * call for a reread of the partition table -- ldv ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Nbd-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nbd-general
