[network-manager-applet/dcbw/more-kill-dbus-glib-bgo649318: 3/3] editor: convert to GIO unix signal handling



commit 28d39edc8f2e6072146008d89320335fbd71912b
Author: Dan Williams <dcbw redhat com>
Date:   Thu Feb 18 14:36:36 2016 -0600

    editor: convert to GIO unix signal handling

 src/connection-editor/main.c |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)
---
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index 83b39cb..1595b28 100644
--- a/src/connection-editor/main.c
+++ b/src/connection-editor/main.c
@@ -31,6 +31,7 @@
 #include <glib/gi18n-lib.h>
 #include <glib.h>
 #include <glib-object.h>
+#include <glib-unix.h>
 
 #include "gsystem-local-alloc.h"
 #include "nm-connection-list.h"
@@ -273,25 +274,15 @@ try_existing_instance (GDBusConnection *bus,
        return TRUE;
 }
 
-static void
-signal_handler (int signo)
+static gboolean
+signal_handler (gpointer user_data)
 {
-       if (signo == SIGINT || signo == SIGTERM)
-               g_main_loop_quit (loop);
-}
+       int signo = GPOINTER_TO_INT (user_data);
 
-static void
-setup_signals (void)
-{
-       struct sigaction action;
-       sigset_t mask;
-
-       sigemptyset (&mask);
-       action.sa_handler = signal_handler;
-       action.sa_mask = mask;
-       action.sa_flags = 0;
-       sigaction (SIGTERM,  &action, NULL);
-       sigaction (SIGINT,  &action, NULL);
+       g_message ("Caught signal %d, shutting down...", signo);
+       g_main_loop_quit (loop);
+
+       return G_SOURCE_REMOVE;
 }
 
 int
@@ -364,7 +355,9 @@ main (int argc, char *argv[])
        if (handle_arguments (list, type, create, show, uuid, (create || show || uuid)))
                nm_connection_list_present (list);
 
-       setup_signals ();
+       g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM));
+       g_unix_signal_add (SIGINT, signal_handler, GINT_TO_POINTER (SIGINT));
+
        g_main_loop_run (loop);
        ret = 0;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]