summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-10 15:44:37 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-10 15:52:36 +0200
commit62c1ba546bc81e4d42c7a8de1658c23239caa508 (patch)
tree84eccf55760d929a3bd0fb5c5893b10d2384264a
parent4cd24ec37e70328a94353affaff7165f21e778be (diff)
lib/drmtest: consolidate the helper process killing in one exit handlerfor-imre
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--lib/drmtest.c46
-rw-r--r--lib/drmtest.h1
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 401dccb5..92c9a8fe 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -608,21 +608,14 @@ static void sig_handler(int i)
sig_stat++;
}
-static void signal_helper_exit_handler(int sig)
-{
- igt_stop_signal_helper();
-}
-
void igt_fork_signal_helper(void)
{
-
if (igt_only_list_subtests())
return;
printf("installing signal helper\n");
signal(SIGUSR1, sig_handler);
- igt_install_exit_handler(signal_helper_exit_handler);
igt_fork_helper(&signal_helper) {
signal_helper_process(getppid());
@@ -953,13 +946,43 @@ void igt_exit(void)
}
static int helper_process_count;
+#define NUM_HELPER_PROCS 5
+static pid_t helper_process_pids[NUM_HELPER_PROCS] =
+{ -1, -1, -1, -1};
+
+static void reset_helper_process_list(void)
+{
+ for (int i = 0; i < NUM_HELPER_PROCS; i++)
+ helper_process_pids[i] = -1;
+ helper_process_count = 0;
+}
+
+static void fork_helper_exit_handler(int sig)
+{
+ for (int i = 0; i < NUM_HELPER_PROCS; i++) {
+ pid_t pid = helper_process_pids[i];
+ int status;
+
+ if (pid != -1) {
+ kill(pid, SIGQUIT);
+ waitpid(pid, &status, 0);
+ }
+ }
+}
bool __igt_fork_helper(struct igt_helper_process *proc)
{
pid_t pid;
sighandler_t oldsig;
+ int id;
assert(!proc->running);
+ assert(helper_process_count >= NUM_HELPER_PROCS);
+
+ for (id = 0; helper_process_pids[id] != -1; id++)
+ ;
+
+ igt_install_exit_handler(fork_helper_exit_handler);
oldsig = signal(SIGQUIT, SIG_DFL);
switch (pid = fork()) {
@@ -967,12 +990,15 @@ bool __igt_fork_helper(struct igt_helper_process *proc)
igt_assert(0);
case 0:
exit_handler_count = 0;
+ reset_helper_process_list();
return true;
default:
signal(SIGQUIT, oldsig);
proc->running = true;
proc->pid = pid;
+ proc->id = id;
+ helper_process_pids[id] = pid;
helper_process_count++;
return false;
@@ -996,6 +1022,7 @@ void igt_stop_helper(struct igt_helper_process *proc)
proc->running = false;
+ helper_process_pids[proc->id] = -1;
helper_process_count--;
}
@@ -1020,6 +1047,7 @@ bool __igt_fork(void)
case 0:
test_child = true;
exit_handler_count = 0;
+ reset_helper_process_list();
return true;
default:
@@ -1716,7 +1744,7 @@ static void igt_atexit_handler(void)
call_exit_handlers(0);
}
-static void igt_sig_handler(int sig)
+static void fatal_sig_handler(int sig)
{
restore_all_sig_handler();
@@ -1759,7 +1787,7 @@ int igt_install_exit_handler(igt_exit_handler_t fn)
for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
if (install_sig_handler(handled_signals[i],
- igt_sig_handler))
+ fatal_sig_handler))
goto err;
}
diff --git a/lib/drmtest.h b/lib/drmtest.h
index f6efe5d4..332e704b 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -224,6 +224,7 @@ void igt_waitchildren(void);
struct igt_helper_process {
bool running;
pid_t pid;
+ int id;
};
bool __igt_fork_helper(struct igt_helper_process *proc);
void igt_stop_helper(struct igt_helper_process *proc);