summaryrefslogtreecommitdiff
path: root/lib/sigevent.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-09-02 16:25:00 -0400
committerMark Stapp <mjs@voltanet.io>2020-10-26 16:46:40 -0400
commit976c5cc134bb96f309479d281d771d70dbe41f13 (patch)
treec1ec4e9566e8844566afa1e220b52257a415e500 /lib/sigevent.c
parentd878460c8cc9a60200843f127b2d22cebfb42229 (diff)
lib: add sigevent_check api
Add an api that blocks application-handled signals (SIGINT, SIGTERM, e.g.) then tests whether any signals have been received. This helps to manage a race between signal reception and the poll call in the main event loop. Signed-off-by: Mark Stapp <mjs@voltanet.io>
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)
{