[network-manager-openvpn] core: quit on Ctl+C when run in debug mode



commit 70819420b3451a47a6dbc88f3a169f410a4a2de5
Author: Dan Williams <dcbw redhat com>
Date:   Mon Sep 13 08:49:34 2010 -0500

    core: quit on Ctl+C when run in debug mode

 src/nm-openvpn-service.c |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 64409ba..1b0452f 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -59,6 +59,7 @@
 #endif
 
 static gboolean debug = FALSE;
+static GMainLoop *loop = NULL;
 
 #define NM_OPENVPN_HELPER_PATH		LIBEXECDIR"/nm-openvpn-service-openvpn-helper"
 
@@ -1316,6 +1317,27 @@ nm_openvpn_plugin_new (void)
 }
 
 static void
+signal_handler (int signo)
+{
+	if (signo == SIGINT || signo == SIGTERM)
+		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);
+}
+
+static void
 quit_mainloop (NMVPNPlugin *plugin, gpointer user_data)
 {
 	g_main_loop_quit ((GMainLoop *) user_data);
@@ -1325,7 +1347,6 @@ int
 main (int argc, char *argv[])
 {
 	NMOpenvpnPlugin *plugin;
-	GMainLoop *main_loop;
 	gboolean persist = FALSE;
 	GOptionContext *opt_ctx = NULL;
 
@@ -1363,14 +1384,15 @@ main (int argc, char *argv[])
 	if (!plugin)
 		exit (EXIT_FAILURE);
 
-	main_loop = g_main_loop_new (NULL, FALSE);
+	loop = g_main_loop_new (NULL, FALSE);
 
 	if (!persist)
-		g_signal_connect (plugin, "quit", G_CALLBACK (quit_mainloop), main_loop);
+		g_signal_connect (plugin, "quit", G_CALLBACK (quit_mainloop), loop);
 
-	g_main_loop_run (main_loop);
+	setup_signals ();
+	g_main_loop_run (loop);
 
-	g_main_loop_unref (main_loop);
+	g_main_loop_unref (loop);
 	g_object_unref (plugin);
 
 	exit (EXIT_SUCCESS);



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