Commit 084a1f7d authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: setup sigchld handler after starting the test

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 74c3cc19
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment