[CRIU] [PATCH] zdtm: setup sigchld handler after starting the test

Andrey Vagin avagin at openvz.org
Tue Feb 4 07:54:26 PST 2014


When a process is started in a new pid namespace, the init process must
colleck zombies.

But before this the init process must waits the root test process, which
returns a status of preparation stage.

Currently these two operation can race, because the both ones call waitpid().

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/lib/ns.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index fb2ac11..29e9e9e 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -199,10 +199,6 @@ int ns_init(int argc, char **argv)
 		fprintf(stderr, "Can't set SIGTERM handler: %m\n");
 		exit(1);
 	}
-	if (sigaction(SIGCHLD, &sa, NULL)) {
-		fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
-		exit(1);
-	}
 
 	/* Start test */
 	pid = fork();
@@ -229,6 +225,25 @@ int ns_init(int argc, char **argv)
 	} else if (pid > 0)
 		waitpid(pid, NULL, 0);
 
+	if (sigaction(SIGCHLD, &sa, NULL)) {
+		fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
+		exit(1);
+	}
+
+	while (1) {
+		int status;
+
+		pid = waitpid(-1, &status, WNOHANG);
+		if (pid == 0)
+			break;
+		if (pid < 0) {
+			fprintf(stderr, "waitpid() failed: %m\n");
+			exit (1);
+		}
+		if (status)
+			fprintf(stderr, "%d return %d\n", pid, status);
+	}
+
 	/* Daemonize */
 	write(status_pipe, &ret, sizeof(ret));
 	close(status_pipe);
-- 
1.8.5.3



More information about the CRIU mailing list