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>
This commit is contained in:
Mark Stapp 2020-09-02 16:25:00 -04:00
parent d878460c8c
commit 976c5cc134
2 changed files with 36 additions and 0 deletions

View 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)
{

View 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);