[gnome-settings-daemon/gnome-3-10] main: modernize code for handling SIGTERM



commit 8dc5fd5e1d67eeae5196d38cb54964a0b803423d
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Feb 3 00:58:04 2014 +0100

    main: modernize code for handling SIGTERM
    
    Let's use glib's builtin facilities for signals instead of
    our own pipe.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707790

 gnome-settings-daemon/main.c |   39 +++------------------------------------
 1 files changed, 3 insertions(+), 36 deletions(-)
---
diff --git a/gnome-settings-daemon/main.c b/gnome-settings-daemon/main.c
index b6b86bb..72fdeab 100644
--- a/gnome-settings-daemon/main.c
+++ b/gnome-settings-daemon/main.c
@@ -30,6 +30,7 @@
 
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
+#include <glib-unix.h>
 #include <gtk/gtk.h>
 #include <libnotify/notify.h>
 
@@ -44,7 +45,6 @@
 static gboolean   replace      = FALSE;
 static gboolean   debug        = FALSE;
 static gboolean   do_timed_exit = FALSE;
-static int        term_signal_pipe_fds[2];
 static guint      name_id      = 0;
 static GnomeSettingsManager *manager = NULL;
 
@@ -276,12 +276,8 @@ register_with_gnome_session (GDBusProxy *proxy)
 }
 
 static gboolean
-on_term_signal_pipe_closed (GIOChannel *source,
-                            GIOCondition condition,
-                            gpointer data)
+on_term_signal (gpointer user_data)
 {
-        term_signal_pipe_fds[0] = -1;
-
         g_debug ("Received SIGTERM - shutting down");
         /* Got SIGTERM, time to clean up and get out
          */
@@ -291,35 +287,6 @@ on_term_signal_pipe_closed (GIOChannel *source,
 }
 
 static void
-on_term_signal (int signal)
-{
-        /* Wake up main loop to tell it to shutdown */
-        close (term_signal_pipe_fds[1]);
-        term_signal_pipe_fds[1] = -1;
-}
-
-static void
-watch_for_term_signal (GnomeSettingsManager *manager)
-{
-        GIOChannel *channel;
-
-        if (-1 == pipe (term_signal_pipe_fds) ||
-            -1 == fcntl (term_signal_pipe_fds[0], F_SETFD, FD_CLOEXEC) ||
-            -1 == fcntl (term_signal_pipe_fds[1], F_SETFD, FD_CLOEXEC)) {
-                g_error ("Could not create pipe: %s", g_strerror (errno));
-                exit (EXIT_FAILURE);
-        }
-
-        channel = g_io_channel_unix_new (term_signal_pipe_fds[0]);
-        g_io_channel_set_encoding (channel, NULL, NULL);
-        g_io_channel_set_buffered (channel, FALSE);
-        g_io_add_watch (channel, G_IO_HUP, on_term_signal_pipe_closed, manager);
-        g_io_channel_unref (channel);
-
-        signal (SIGTERM, on_term_signal);
-}
-
-static void
 name_acquired_handler (GDBusConnection *connection,
                        const gchar *name,
                        gpointer user_data)
@@ -335,7 +302,7 @@ name_acquired_handler (GDBusConnection *connection,
 #endif
         start_settings_manager ();
         register_with_gnome_session (proxy);
-        watch_for_term_signal (manager);
+        g_unix_signal_add (SIGTERM, on_term_signal, manager);
 }
 
 static void


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