diff options
-rw-r--r-- | src/sig_handlers.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 833843d0e..5fefb82a0 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -21,18 +21,28 @@ #include "command.h" #include "signal_check.h" #include "log.h" +#include "main.h" + +#include <glib.h> #include <sys/signal.h> #include <errno.h> -#include <glib.h> +#include <string.h> -int handlePendingSignals(void) +static void exit_signal_handler(G_GNUC_UNUSED int signum) { - if (signal_is_pending(SIGINT) || signal_is_pending(SIGTERM)) { - DEBUG("main process got SIGINT or SIGTERM, exiting\n"); - return COMMAND_RETURN_KILL; - } + g_main_loop_quit(main_loop); +} +static void +x_sigaction(int signum, const struct sigaction *act) +{ + if (sigaction(signum, act, NULL) < 0) + g_error("sigaction() failed: %s", strerror(errno)); +} + +int handlePendingSignals(void) +{ if (signal_is_pending(SIGHUP)) { DEBUG("got SIGHUP, rereading DB\n"); signal_clear(SIGHUP); @@ -51,8 +61,11 @@ void initSigHandlers(void) sigemptyset(&sa.sa_mask); sa.sa_handler = SIG_IGN; while (sigaction(SIGPIPE, &sa, NULL) < 0 && errno == EINTR) ; + + sa.sa_handler = exit_signal_handler; + x_sigaction(SIGINT, &sa); + x_sigaction(SIGTERM, &sa); + signal_handle(SIGUSR1); - signal_handle(SIGINT); - signal_handle(SIGTERM); signal_handle(SIGHUP); } |