From 0e159b6d641ae3a2568ba9dfcee95f4f2560fbaf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 21 Dec 2015 14:43:35 +0100 Subject: Terminate with the received signal --- src/fastd.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/fastd.c b/src/fastd.c index 603def1..8580cf2 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -71,8 +71,8 @@ fastd_context_t ctx = {}; static volatile bool sig_reload = false; /**< Is set to true when a SIGHUP is received */ static volatile bool sig_reset = false; /**< Is set to true when a SIGUSR2 is received */ -static volatile bool sig_terminate = false; /**< Is set to true when a SIGTERM, SIGQUIT or SIGINT is received */ static volatile bool sig_child = false; /**< Is set to true when a SIGCHLD is received */ +static volatile int sig_terminate = 0; /**< Holds the signal number when a SIGTERM, SIGQUIT or SIGINT is received */ /** Signal handler; just saves the signals to be handled later */ @@ -93,7 +93,7 @@ static void on_signal(int signo) { case SIGTERM: case SIGQUIT: case SIGINT: - sig_terminate = true; + sig_terminate = signo; break; default: @@ -683,6 +683,18 @@ static inline void cleanup(void) { fastd_config_release(); } +/** Terminates fastd by re-raising the received signal */ +static inline void terminate(void) { + struct sigaction action = {}; + sigemptyset(&action.sa_mask); + + action.sa_handler = SIG_DFL; + sigaction(sig_terminate, &action, NULL); + + pthread_sigmask(SIG_SETMASK, &action.sa_mask, NULL); + + kill(getpid(), sig_terminate); +} /** Main function */ int main(int argc, char *argv[]) { @@ -692,6 +704,8 @@ int main(int argc, char *argv[]) { run(); cleanup(); + terminate(); - return 0; + /* Should not be reached */ + return -1; } -- cgit v1.2.3