From 9fb316a6db16cd8cddba719d7acbdf068f9238ee Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Wed, 11 Sep 2013 14:29:00 +0200 Subject: [PATCH] lib/drmtest: clean up children in an exit handler Also be a bit more careful with killing them in general. Signed-off-by: Daniel Vetter --- lib/drmtest.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index 969854c..f2590d7 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -967,8 +967,10 @@ static void fork_helper_exit_handler(int sig) /* Someone forgot to fill up the array? */ assert(pid != 0); - kill(pid, SIGQUIT); - waitpid(pid, &status, 0); + assert(kill(pid, SIGQUIT) == 0); + while (waitpid(pid, &status, 0) == -1 && + errno == -EINTR) + ; helper_process_count--; } } @@ -1023,7 +1025,7 @@ void igt_stop_helper(struct igt_helper_process *proc) assert(proc->running); - kill(proc->pid, SIGQUIT); + assert(kill(proc->pid, SIGQUIT) == 0); waitpid(proc->pid, &status, 0); proc->running = false; @@ -1032,11 +1034,29 @@ void igt_stop_helper(struct igt_helper_process *proc) helper_process_count--; } +static void children_exit_handler(int sig) +{ + assert(!test_child); + + for (int nc = 0; nc < num_test_children; nc++) { + int status = -1; + assert(kill(test_children[nc], SIGQUIT) == 0); + + while (waitpid(test_children[nc], &status, 0) == -1 && + errno == -EINTR) + ; + } + + num_test_children = 0; +} + bool __igt_fork(void) { assert(!test_with_subtests || in_subtest); assert(!test_child); + igt_install_exit_handler(children_exit_handler); + if (num_test_children >= test_children_sz) { if (!test_children_sz) test_children_sz = 4; -- 2.7.4