NetworkManager r3266 - in branches/NETWORKMANAGER_0_6_0_RELEASE: . test



Author: dcbw
Date: Thu Jan 24 03:06:28 2008
New Revision: 3266
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3266&view=rev

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

	* test/libnm_glib_test.c
		- (signal_handler, setup_signals): trap SIGINT and SIGTERM
		- (main): set up signal handlers; call libnm_glib_shutdown



Modified:
   branches/NETWORKMANAGER_0_6_0_RELEASE/ChangeLog
   branches/NETWORKMANAGER_0_6_0_RELEASE/test/libnm_glib_test.c

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/test/libnm_glib_test.c
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/test/libnm_glib_test.c	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/test/libnm_glib_test.c	Thu Jan 24 03:06:28 2008
@@ -23,6 +23,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
+
 #include "libnm_glib.h"
 
 
@@ -56,10 +58,33 @@
 	}
 }
 
+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[] )
 {
-	GMainLoop	*loop;
 	libnm_glib_ctx *ctx;
 	guint id;
 
@@ -79,7 +104,10 @@
 	fprintf (stderr, "Registered Callback with ID %d\n", id);
 
 	loop = g_main_loop_new (NULL, FALSE);
+	setup_signals ();
 	g_main_loop_run (loop);
 
+	libnm_glib_shutdown (ctx);
+
 	exit (0);
 }



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