]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add sigevent_check api
authorMark Stapp <mjs@voltanet.io>
Wed, 2 Sep 2020 20:25:00 +0000 (16:25 -0400)
committerMark Stapp <mjs@voltanet.io>
Mon, 26 Oct 2020 20:46:40 +0000 (16:46 -0400)
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>
lib/sigevent.c
lib/sigevent.h

index 04fcc814ef17f3ad00e6c950207c1ef001f1e0e0..de9e1f54100ad28a57a2ff5dd29aa9d061e9b925 100644 (file)
@@ -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)
 {
index a0ad88fcaaaa2b10026f19813cbdd42dd3b4b6b3..4a39b22889724d4c50144e684705b6d18ea16d59 100644 (file)
@@ -48,6 +48,15 @@ struct quagga_signal_t {
 extern void signal_init(struct thread_master *m, int sigc,
                        struct quagga_signal_t *signals);
 
+
+/*
+ * 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);
+
 /* check whether there are signals to handle, process any found */
 extern int quagga_sigevent_process(void);