summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-08 14:03:03 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-09-08 14:03:03 +0200
commitfbd64de6be923e339675667525fcd1a294d9b172 (patch)
tree4c30880f12f0ff368bc9164e66393dcc1eb2aa18 /lib/drmtest.c
parentb3dadedd2e899a8e3dd916aa8b0df6481e724d5a (diff)
lib/drmtest: Avoid calling exit handlers multiple times
- reset the count when forking - don't add the same handler multiple times - don't restore the exit signal handlers in the forked helper process - reset the exit handler count once called to make sure we don't call it multiple times when dying - don't wait for the signal helper if it's gone already Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 37a0e221..fe4b1a81 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -589,6 +589,8 @@ off_t prime_get_size(int dma_buf_fd)
/* signal interrupt helpers */
static bool igt_only_list_subtests(void);
+static int exit_handler_count;
+
static pid_t signal_helper = -1;
long long int sig_stat;
static void __attribute__((noreturn)) signal_helper_process(pid_t pid)
@@ -624,11 +626,13 @@ void igt_fork_signal_helper(void)
signal(SIGUSR1, sig_handler);
oldsig = signal(SIGQUIT, SIG_DFL);
pid = fork();
- signal(SIGQUIT, oldsig);
if (pid == 0) {
+ exit_handler_count = 0;
+
signal_helper_process(getppid());
return;
}
+ signal(SIGQUIT, oldsig);
signal_helper = pid;
}
@@ -640,6 +644,8 @@ void igt_stop_signal_helper(void)
if (signal_helper != -1) {
kill(signal_helper, SIGQUIT);
wait(&exitcode);
+
+ signal_helper = -1;
} else
return;
@@ -988,6 +994,8 @@ bool __igt_fork(void)
igt_assert(0);
case 0:
test_child = true;
+ exit_handler_count = 0;
+
return true;
default:
return false;
@@ -1629,7 +1637,6 @@ static struct {
} orig_sig[MAX_SIGNALS];
static igt_exit_handler_t exit_handler_fn[MAX_EXIT_HANDLERS];
-static int exit_handler_count;
static bool exit_handler_disabled;
static sigset_t saved_sig_mask;
static const int handled_signals[] =
@@ -1672,6 +1679,9 @@ static void call_exit_handlers(int sig)
for (i = exit_handler_count - 1; i >= 0; i--)
exit_handler_fn[i](sig);
+
+ /* ensure we don't get called twice */
+ exit_handler_count = 0;
}
static void igt_atexit_handler(void)
@@ -1710,6 +1720,10 @@ int igt_install_exit_handler(igt_exit_handler_t fn)
{
int i;
+ for (i = 0; i < exit_handler_count; i++)
+ if (exit_handler_fn[i] == fn)
+ return 0;
+
if (exit_handler_count == MAX_EXIT_HANDLERS)
return -1;