From 82b7348f1964dca50519140e3cfc062baa2996ef Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 21 May 2011 22:48:51 -0400 Subject: 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 file changed, 19 insertions(+), 22 deletions(-) (limited to 'shell/main.c') diff --git a/shell/main.c b/shell/main.c index cab5ab9717..e1b768187d 100644 --- a/shell/main.c +++ b/shell/main.c @@ -26,6 +26,12 @@ #include #include +#ifdef G_OS_UNIX +#if GLIB_CHECK_VERSION(2,29,5) +#include +#endif +#endif + #if HAVE_CLUTTER #include #include @@ -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; -- cgit