[network-manager-openvpn] core: add --debug command-line option



commit 1711d04b1893fdb5763ce69561a2e6235a51e251
Author: Dan Williams <dcbw redhat com>
Date:   Tue Aug 10 12:30:15 2010 -0500

    core: add --debug command-line option

 configure.ac             |    8 ++++++++
 src/nm-openvpn-service.c |   44 ++++++++++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3212d70..7a44662 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,6 +115,14 @@ case $with_tests in
         ;;
 esac
 
+dnl
+dnl Distribution version string
+dnl
+AC_ARG_WITH(dist-version, AS_HELP_STRING([--with-dist-version=<dist-version>], [Define the custom version (like distribution package name and revision)]), ac_distver=$withval, ac_distver="")
+if ! test x"$ac_distver" = x""; then
+  AC_DEFINE_UNQUOTED(DIST_VERSION, "$ac_distver", [Define the distribution version string])
+fi
+
 AC_CONFIG_FILES([
 Makefile
 src/Makefile
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index d2c0f4b..b242243 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -2,7 +2,7 @@
 /* nm-openvpn-service - openvpn integration with NetworkManager
  *
  * Copyright (C) 2005 - 2008 Tim Niemueller <tim niemueller de>
- * Copyright (C) 2005 - 2008 Dan Williams <dcbw redhat com>
+ * Copyright (C) 2005 - 2010 Dan Williams <dcbw redhat com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -54,6 +54,12 @@
 #include "nm-utils.h"
 #include "common/utils.h"
 
+#if !defined(DIST_VERSION)
+# define DIST_VERSION VERSION
+#endif
+
+static gboolean debug = FALSE;
+
 #define NM_OPENVPN_HELPER_PATH		LIBEXECDIR"/nm-openvpn-service-openvpn-helper"
 
 G_DEFINE_TYPE (NMOpenvpnPlugin, nm_openvpn_plugin, NM_TYPE_VPN_PLUGIN)
@@ -815,7 +821,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 		}
 	}
 
-	if (getenv ("OPENVPN_DEBUG")) {
+	if (debug) {
 		add_openvpn_arg (args, "--verb");
 		add_openvpn_arg (args, "10");
 	} else {
@@ -869,7 +875,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 
 	/* Up script, called when connection has been established or has been restarted */
 	add_openvpn_arg (args, "--up");
-	if (getenv ("OPENVPN_DEBUG"))
+	if (debug)
 		add_openvpn_arg (args, NM_OPENVPN_HELPER_PATH " --helper-debug");
 	else
 		add_openvpn_arg (args, NM_OPENVPN_HELPER_PATH);
@@ -1248,9 +1254,36 @@ main (int argc, char *argv[])
 {
 	NMOpenvpnPlugin *plugin;
 	GMainLoop *main_loop;
+	gboolean persist = FALSE;
+	GOptionContext *opt_ctx = NULL;
+
+	GOptionEntry options[] = {
+		{ "persist", 0, 0, G_OPTION_ARG_NONE, &persist, "Don't quit when VPN connection terminates", NULL },
+		{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Enable verbose debug logging (may expose passwords)", NULL },
+		{NULL}
+	};
 
 	g_type_init ();
 
+	/* Parse options */
+	opt_ctx = g_option_context_new ("");
+	g_option_context_set_translation_domain (opt_ctx, "UTF-8");
+	g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
+	g_option_context_set_help_enabled (opt_ctx, TRUE);
+	g_option_context_add_main_entries (opt_ctx, options, NULL);
+
+	g_option_context_set_summary (opt_ctx,
+		"nm-vpnc-service provides integrated OpenVPN capability to NetworkManager.");
+
+	g_option_context_parse (opt_ctx, &argc, &argv, NULL);
+	g_option_context_free (opt_ctx);
+
+	if (getenv ("OPENVPN_DEBUG"))
+		debug = TRUE;
+
+	if (debug)
+		g_message ("nm-openvpn-service (version " DIST_VERSION ") starting...");
+
 	if (system ("/sbin/modprobe tun") == -1)
 		exit (EXIT_FAILURE);
 
@@ -1260,9 +1293,8 @@ main (int argc, char *argv[])
 
 	main_loop = g_main_loop_new (NULL, FALSE);
 
-	g_signal_connect (plugin, "quit",
-				   G_CALLBACK (quit_mainloop),
-				   main_loop);
+	if (!persist)
+		g_signal_connect (plugin, "quit", G_CALLBACK (quit_mainloop), main_loop);
 
 	g_main_loop_run (main_loop);
 



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