Skip to content

Commit

Permalink
loop: don't override external signal handlers
Browse files Browse the repository at this point in the history
qb_loop_signal_add() used to set any signals it wasn't managing
back to SIG_DFL. This is unfriendly behaviour in a library.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Pokorný <jpokorny@redhat.com>
  • Loading branch information
chrissie-c committed Feb 24, 2017
1 parent afdff97 commit c751993
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/loop_poll.c
Expand Up @@ -643,8 +643,6 @@ _adjust_sigactions_(struct qb_signal_source *s)
if (needed) {
sigaddset(&s->signal_superset, i);
sigaction(i, &sa, NULL);
} else {
(void)signal(i, SIG_DFL);
}
}
}
Expand Down Expand Up @@ -775,6 +773,7 @@ qb_loop_signal_del(qb_loop_t * lp, qb_loop_signal_handle handle)
}

qb_list_del(&sig->item.list);
signal(sig->signal, SIG_DFL);
free(sig);
_adjust_sigactions_(s);
return 0;
Expand Down
31 changes: 31 additions & 0 deletions tests/check_loop.c
Expand Up @@ -605,6 +605,36 @@ START_TEST(test_loop_sig_handling)
}
END_TEST

/* Globals for this test only */
static int our_signal_called = 0;
static qb_loop_t *this_l;
static void handle_nonqb_signal(int num)
{
our_signal_called = 1;
qb_loop_job_add(this_l, QB_LOOP_LOW, NULL, job_stop);
}

START_TEST(test_loop_dont_override_other_signals)
{
qb_loop_signal_handle handle;

this_l = qb_loop_create();
fail_if(this_l == NULL);

signal(SIGUSR1, handle_nonqb_signal);

qb_loop_signal_add(this_l, QB_LOOP_HIGH, SIGINT,
this_l, sig_handler, &handle);
kill(getpid(), SIGUSR1);
qb_loop_run(this_l);

ck_assert_int_eq(our_signal_called, 1);

qb_loop_destroy(this_l);
}
END_TEST


START_TEST(test_loop_sig_only_get_one)
{
int res;
Expand Down Expand Up @@ -706,6 +736,7 @@ loop_signal_suite(void)
add_tcase(s, tc, test_loop_sig_handling, 10);
add_tcase(s, tc, test_loop_sig_only_get_one);
add_tcase(s, tc, test_loop_sig_delete);
add_tcase(s, tc, test_loop_dont_override_other_signals);

return s;
}
Expand Down

0 comments on commit c751993

Please sign in to comment.