network-manager-applet r475 - in trunk: . src



Author: dcbw
Date: Fri Jan 25 16:56:48 2008
New Revision: 475
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=475&view=rev

Log:
2008-01-25  Dan Williams  <dcbw redhat com>

	* src/main.c
		- (main, setup_signals, signal_handler): trap SIGTERM and SIGINT and
			exit cleanly



Modified:
   trunk/ChangeLog
   trunk/src/main.c

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Fri Jan 25 16:56:48 2008
@@ -27,11 +27,37 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <signal.h>
+
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 
 #include "applet.h"
 
+static GMainLoop *loop = NULL;
+
+static void
+signal_handler (int signo)
+{
+	if (signo == SIGINT || signo == SIGTERM) {
+		g_message ("Caught signal %d, shutting down...", signo);
+		g_main_loop_quit (loop);
+	}
+}
+
+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);
+}
 
 int main (int argc, char *argv[])
 {
@@ -46,9 +72,12 @@
 	if (applet == NULL)
 		exit (1);
 
-	gtk_main ();
+	loop = g_main_loop_new (NULL, FALSE);
+	setup_signals ();
+	g_main_loop_run (loop);
 
-	g_object_unref (applet);
+	g_object_unref (G_OBJECT (applet));
 
 	exit (0);
 }
+



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