diff options
author | Dan Williams <dcbw@redhat.com> | 2013-02-12 15:48:39 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2013-02-12 15:48:39 -0600 |
commit | 2d700043abc5686faa54d215ffe60c92f4d0c00e (patch) | |
tree | 9667d6ef22d7d2a4cdd21f74ce87748ff8891025 /src | |
parent | 625e1c4884215bb9989dad6c9868c06ba76a4d94 (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.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 38 | ||||
-rw-r--r-- | src/mm-log.c | 5 | ||||
-rw-r--r-- | src/mm-log.h | 2 |
3 files changed, 11 insertions, 34 deletions
@@ -22,6 +22,7 @@ #include <stdlib.h> #include <gio/gio.h> +#include <glib-unix.h> #include "ModemManager.h" @@ -39,33 +40,15 @@ static GMainLoop *loop; static MMManager *manager; -static void -mm_signal_handler (int signo) +static gboolean +quit_cb (gpointer user_data) { - 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); - } -} - -static void -setup_signals (void) -{ - struct sigaction action; - sigset_t mask; - - sigemptyset (&mask); - 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); + mm_info ("Caught signal, shutting down..."); + if (loop) + g_idle_add ((GSourceFunc) g_main_loop_quit, loop); + else + _exit (0); + return FALSE; } static void @@ -139,7 +122,8 @@ main (int argc, char *argv[]) exit (1); } - setup_signals (); + g_unix_signal_add (SIGTERM, quit_cb, NULL); + g_unix_signal_add (SIGINT, quit_cb, NULL); mm_info ("ModemManager (version " MM_DIST_VERSION ") starting..."); diff --git a/src/mm-log.c b/src/mm-log.c index 607454f8..30289514 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -247,11 +247,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 b39baf40..2576c1c5 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -56,8 +56,6 @@ gboolean mm_log_setup (const char *level, gboolean debug_func_loc, GError **error); -void mm_log_usr1 (void); - void mm_log_shutdown (void); #endif /* MM_LOG_H */ |