summaryrefslogtreecommitdiff
path: root/lib/sigevent.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2020-10-28 19:29:29 -0400
committerGitHub <noreply@github.com>2020-10-28 19:29:29 -0400
commit502dd27af98c46d20f82c43a3e2d80db53128782 (patch)
treee0076c169894210ff2836a38fb06fa0e184fbbbb /lib/sigevent.c
parent4220c2cc9b69d221e8a5d0f546dd64af4f588a15 (diff)
parentd81ca9a3faabe54f57b11acf87585e48d3a44480 (diff)
Merge pull request #7045 from mjstapp/fix_signals
lib: Resolve signal handling race in event loop
Diffstat (limited to 'lib/sigevent.c')
-rw-r--r--lib/sigevent.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sigevent.c b/lib/sigevent.c
index 04fcc814ef..de9e1f5410 100644
--- a/lib/sigevent.c
+++ b/lib/sigevent.c
@@ -63,6 +63,33 @@ static void quagga_signal_handler(int signo)
sigmaster.caught = 1;
}
+/*
+ * Check whether any signals have been received and are pending. This is done
+ * with the application's key signals blocked. The complete set of signals
+ * is returned in 'setp', so the caller can restore them when appropriate.
+ * If there are pending signals, returns 'true', 'false' otherwise.
+ */
+bool frr_sigevent_check(sigset_t *setp)
+{
+ sigset_t blocked;
+ int i;
+ bool ret;
+
+ sigemptyset(setp);
+ sigemptyset(&blocked);
+
+ /* Set up mask of application's signals */
+ for (i = 0; i < sigmaster.sigc; i++)
+ sigaddset(&blocked, sigmaster.signals[i].signal);
+
+ pthread_sigmask(SIG_BLOCK, &blocked, setp);
+
+ /* Now that the application's signals are blocked, test. */
+ ret = (sigmaster.caught != 0);
+
+ return ret;
+}
+
/* check if signals have been caught and run appropriate handlers */
int quagga_sigevent_process(void)
{