aboutsummaryrefslogtreecommitdiffstats
path: root/src/sig_handlers.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-30 19:50:38 +0100
committerMax Kellermann <max@duempel.org>2008-12-30 19:50:38 +0100
commitd196ffdf3a3ca4391b644b730f93c34b38ab1520 (patch)
tree4b0fe91f92be313f9786415bca514d01b16a87e5 /src/sig_handlers.c
parentd40cf1652ddbab662c753217a61c8bfba03d07ce (diff)
downloadmpd-d196ffdf3a3ca4391b644b730f93c34b38ab1520.tar.gz
mpd-d196ffdf3a3ca4391b644b730f93c34b38ab1520.tar.xz
mpd-d196ffdf3a3ca4391b644b730f93c34b38ab1520.zip
sig_handlers: call g_main_loop_quit() in SIGTERM handler
We don't need to use asynchronous events to quit MPD, we can just call g_main_loop_quit() inside the handler.
Diffstat (limited to 'src/sig_handlers.c')
-rw-r--r--src/sig_handlers.c29
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);
}