[gnome-user-share] main: Better signal handling



commit bfc848805ab32ad4d945b7ae810312ea0d9ab000
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 7 19:20:38 2013 +0100

    main: Better signal handling
    
    Using g_unix_signal_add() instead of signal(). This avoids trying
    to do nasty things in signal handlers.

 src/user_share.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/src/user_share.c b/src/user_share.c
index 7dd4499..dd9366d 100644
--- a/src/user_share.c
+++ b/src/user_share.c
@@ -28,6 +28,7 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gio/gio.h>
+#include <glib-unix.h>
 #include <X11/Xlib.h>
 
 #include "user_share.h"
@@ -258,14 +259,11 @@ setttings_changed (GSettings *settings,
 #endif /* HAVE_BLUETOOTH */
 }
 
-static void
-cleanup_handler (int sig)
+static gboolean
+signal_handler (gpointer user_data)
 {
-       http_down ();
-#ifdef HAVE_BLUETOOTH
-       obex_agent_down ();
-#endif
-       _exit (2);
+       gtk_main_quit ();
+       return FALSE;
 }
 
 static int
@@ -298,9 +296,9 @@ main (int argc, char **argv)
        }
 
        signal (SIGPIPE, SIG_IGN);
-       signal (SIGINT, cleanup_handler);
-       signal (SIGHUP, cleanup_handler);
-       signal (SIGTERM, cleanup_handler);
+       g_unix_signal_add (SIGINT, signal_handler, NULL);
+       g_unix_signal_add (SIGHUP, signal_handler, NULL);
+       g_unix_signal_add (SIGTERM, signal_handler, NULL);
 
        xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
        if (xdisplay == NULL) {
@@ -364,7 +362,12 @@ main (int argc, char **argv)
 #endif /* HAVE_BLUETOOTH */
 
        gtk_main ();
+
        g_object_unref (settings);
+       http_down ();
+#ifdef HAVE_BLUETOOTH
+       obex_agent_down ();
+#endif
 
        return 0;
 }


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