Blob Blame History Raw
commit c751993c901805cc5cd02622c8672bbc7f8d6849
Author: Christine Caulfield <ccaulfie@redhat.com>
Date:   Fri Feb 24 16:23:43 2017 +0000

    loop: don't override external signal handlers
    
    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>

diff --git a/lib/loop_poll.c b/lib/loop_poll.c
index 5c75748..386cae6 100644
--- a/lib/loop_poll.c
+++ b/lib/loop_poll.c
@@ -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);
 		}
 	}
 }
@@ -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;
diff --git a/tests/check_loop.c b/tests/check_loop.c
index ff7f10a..0be5c21 100644
--- a/tests/check_loop.c
+++ b/tests/check_loop.c
@@ -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;
@@ -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;
 }