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 <ldv@altlinux.org>
Signed-off-by: Wouter Verhelst <w@uter.be>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/mman.h>
+#include <signal.h>
#include <errno.h>
#include <getopt.h>
#include <stdarg.h>
#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