[evolution] Bug 650524 - Use g_unix_signal_add_watch_full() for SIGTERM



commit 82b7348f1964dca50519140e3cfc062baa2996ef
Author: Colin Walters <walters verbum org>
Date:   Sat May 21 22:48:51 2011 -0400

    Bug 650524 - Use g_unix_signal_add_watch_full() for SIGTERM
    
    We can't call anything safely except write() inside a signal handler,
    g_unix_signal_add_watch_full() handles this for us nicely.

 shell/main.c |   41 +++++++++++++++++++----------------------
 1 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/shell/main.c b/shell/main.c
index cab5ab9..e1b7681 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -26,6 +26,12 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 
+#ifdef G_OS_UNIX
+#if GLIB_CHECK_VERSION(2,29,5)
+#include <glib-unix.h>
+#endif
+#endif
+
 #if HAVE_CLUTTER
 #include <clutter-gtk/clutter-gtk.h>
 #include <mx/mx.h>
@@ -264,38 +270,23 @@ idle_cb (gchar **uris)
 	return FALSE;
 }
 
-#ifndef G_OS_WIN32
-
-static void
-term_signal (gint sig)
+#ifdef G_OS_UNIX
+#if GLIB_CHECK_VERSION(2,29,5)
+static gboolean
+handle_term_signal (gpointer data)
 {
 	EShell *shell;
 
-	g_return_if_fail (sig == SIGTERM);
-
 	g_print ("Received terminate signal...\n");
 
 	shell = e_shell_get_default ();
 
 	if (shell != NULL)
 		e_shell_quit (shell, E_SHELL_QUIT_OPTION);
-}
-
-static void
-setup_term_signal (void)
-{
-	struct sigaction sa, osa;
-
-	sigaction (SIGTERM, NULL, &osa);
 
-	sa.sa_flags = 0;
-	sigemptyset (&sa.sa_mask);
-	sa.sa_handler = term_signal;
-	sigaction (SIGTERM, &sa, NULL);
+	return FALSE;
 }
-
-#else
-#define setup_term_signal() (void)0
+#endif
 #endif
 
 static GOptionEntry entries[] = {
@@ -621,7 +612,13 @@ main (gint argc, gchar **argv)
 		gconf_client_set_bool (client, key, FALSE, NULL);
 	}
 
-	setup_term_signal ();
+#ifdef G_OS_UNIX
+#if GLIB_CHECK_VERSION(2,29,5)
+	g_unix_signal_add_watch_full (
+		SIGTERM, G_PRIORITY_DEFAULT,
+		handle_term_signal, NULL, NULL);
+#endif
+#endif
 
 	if (evolution_debug_log) {
 		gint fd;



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