aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2013-02-12 15:54:55 -0600
committerDan Williams <dcbw@redhat.com>2013-02-12 15:54:55 -0600
commit034279f26960fe009816d1474473b6fbcfcd67bf (patch)
tree9e7fc84a51e4e145fcd23de818b0ace1784b4f54
parenta277e835796c881fd43a7fcc265ccc1f6655e67b (diff)
core: use g_unix_signal_add() for more reliable Unix signal handling
There were a few problems with MM's existing signal handling, first of which was that calling g_main_loop_quit() from a signal handler only works 50% of the time due to severe restrictions on what you can do from the handler. This caused INT or TERM to sometimes be ignored by MM. Instead, use the glib signal functions which ensure that the handler is run in the right context, where we can do anything we want.
-rw-r--r--src/main.c39
-rw-r--r--src/mm-log.c5
-rw-r--r--src/mm-log.h2
3 files changed, 29 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index 0f8119ee..584ece82 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,18 +32,37 @@
static GMainLoop *loop = NULL;
+#if GLIB_CHECK_VERSION(2,30,0)
+#include <glib-unix.h>
+
+static gboolean
+quit_cb (gpointer user_data)
+{
+ mm_info ("Caught signal, shutting down...");
+ if (loop)
+ g_idle_add ((GSourceFunc) g_main_loop_quit, loop);
+ else
+ _exit (0);
+ return FALSE;
+}
+
+static void
+setup_signals (void)
+{
+ g_unix_signal_add (SIGTERM, quit_cb, NULL);
+ g_unix_signal_add (SIGINT, quit_cb, NULL);
+}
+
+#else
+
static void
mm_signal_handler (int signo)
{
- if (signo == SIGUSR1)
- mm_log_usr1 ();
- else if (signo == SIGINT || signo == SIGTERM) {
- mm_info ("Caught signal %d, shutting down...", signo);
- if (loop)
- g_main_loop_quit (loop);
- else
- _exit (0);
- }
+ mm_info ("Caught signal %d, shutting down...", signo);
+ if (loop)
+ g_main_loop_quit (loop);
+ else
+ _exit (0);
}
static void
@@ -56,10 +75,10 @@ setup_signals (void)
action.sa_handler = mm_signal_handler;
action.sa_mask = mask;
action.sa_flags = 0;
- sigaction (SIGUSR1, &action, NULL);
sigaction (SIGTERM, &action, NULL);
sigaction (SIGINT, &action, NULL);
}
+#endif
static void
destroy_cb (DBusGProxy *proxy, gpointer user_data)
diff --git a/src/mm-log.c b/src/mm-log.c
index f99f51f5..5e02ff9b 100644
--- a/src/mm-log.c
+++ b/src/mm-log.c
@@ -221,11 +221,6 @@ mm_log_setup (const char *level,
}
void
-mm_log_usr1 (void)
-{
-}
-
-void
mm_log_shutdown (void)
{
if (logfd < 0)
diff --git a/src/mm-log.h b/src/mm-log.h
index 6024c08f..729cf226 100644
--- a/src/mm-log.h
+++ b/src/mm-log.h
@@ -55,8 +55,6 @@ gboolean mm_log_setup (const char *level,
gboolean rel_ts,
GError **error);
-void mm_log_usr1 (void);
-
void mm_log_shutdown (void);
#endif /* MM_LOG_H */