Commit 368d7ac0 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: test_init exits, if all children died

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a9541201
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <sched.h> #include <sched.h>
#include <errno.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/param.h>
#define STACK_SIZE (8 * 4096) #define STACK_SIZE (8 * 4096)
#ifndef CLONE_NEWPID #ifndef CLONE_NEWPID
...@@ -24,8 +26,43 @@ int status_pipe[2]; ...@@ -24,8 +26,43 @@ int status_pipe[2];
static void sig_hand(int signo) static void sig_hand(int signo)
{ {
sig_received = signo; int status, len = 0;
pid_t pid;
char buf[128] = "";
if (signo == SIGTERM) {
sig_received = signo;
len = snprintf(buf, sizeof(buf), "Time to stop and check\n");
goto write_out;
}
while (1) {
pid = waitpid(-1, &status, WNOHANG);
if (pid == 0)
return;
if (pid == -1) {
if (errno == ECHILD) {
if (sig_received)
return;
sig_received = signo;
len = snprintf(buf, sizeof(buf),
"All test processes exited\n");
} else {
len = snprintf(buf, sizeof(buf),
"wait() failed: %m\n");
}
goto write_out;
}
if (status)
fprintf(stderr, "%d return %d\n", pid, status);
}
return;
write_out:
/* fprintf can't be used in a sighandler due to glibc locks */
write(STDERR_FILENO, buf, MAX(len, sizeof(buf)));
} }
void test_waitsig(void) void test_waitsig(void)
{ {
sigset_t mask, oldmask; sigset_t mask, oldmask;
...@@ -61,11 +98,17 @@ int fn(void *_arg) ...@@ -61,11 +98,17 @@ int fn(void *_arg)
} }
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sigaddset(&sa.sa_mask, SIGCHLD);
if (sigaction(SIGTERM, &sa, NULL)) { if (sigaction(SIGTERM, &sa, NULL)) {
fprintf(stderr, "Can't set SIGTERM handler: %m\n"); fprintf(stderr, "Can't set SIGTERM handler: %m\n");
exit(1); exit(1);
} }
if (sigaction(SIGCHLD, &sa, NULL)) {
fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
exit(1);
}
/* Start test */ /* Start test */
snprintf(cmd, sizeof(cmd), "make -C %s %s.pid", dir, name); snprintf(cmd, sizeof(cmd), "make -C %s %s.pid", dir, name);
......
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