[Nbd] [PATCH] nbd-client: do not leave child processes in the zombie state
- To: nbd-general@lists.sourceforge.net
- Subject: [Nbd] [PATCH] nbd-client: do not leave child processes in the zombie state
- From: "Dmitry V. Levin" <ldv@...1147...>
- Date: Sat, 16 Jun 2012 03:43:23 +0400
- Message-id: <20120615234323.GB9699@...1147...>
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@...1147...>
---
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
Reply to: