[network-manager-openvpn/th/vpn-plugin-debug-bgo766816: 1/4] service: interpret environment variables NM_VPN_LOG_LEVEL and NM_VPN_LOG_SYSLOG
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/th/vpn-plugin-debug-bgo766816: 1/4] service: interpret environment variables NM_VPN_LOG_LEVEL and NM_VPN_LOG_SYSLOG
- Date: Mon, 23 May 2016 17:10:30 +0000 (UTC)
commit c10c54a7983f430e18fa1a07b93d35a663b9fbd8
Author: Thomas Haller <thaller redhat com>
Date: Mon May 23 10:37:23 2016 +0200
service: interpret environment variables NM_VPN_LOG_LEVEL and NM_VPN_LOG_SYSLOG
src/nm-openvpn-service.c | 32 ++++++++++++++++++++++++++------
1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 85dc0ba..6f4c334 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -44,9 +44,11 @@
#include <locale.h>
#include <pwd.h>
#include <grp.h>
-#include "glib-unix.h"
+#include <syslog.h>
+#include <glib-unix.h>
#include "utils.h"
+#include "nm-utils/nm-shared-utils.h"
#if !defined(DIST_VERSION)
# define DIST_VERSION VERSION
@@ -54,6 +56,8 @@
static struct {
gboolean debug;
+ int log_level;
+ bool log_syslog;
GSList *pids_pending_list;
} gl/*obal*/;
@@ -167,7 +171,7 @@ static ValidProperty valid_secrets[] = {
static gboolean
_LOG_d_enabled (void)
{
- return gl.debug;
+ return gl.log_level >= LOG_INFO;
}
#define _LOG_d(...) _LOG(FALSE, G_LOG_LEVEL_INFO, __VA_ARGS__)
@@ -1418,11 +1422,19 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
add_openvpn_arg (args, "0");
}
- if (gl.debug) {
+ if (gl.log_level > 0) {
add_openvpn_arg (args, "--verb");
- add_openvpn_arg (args, "10");
+ if (gl.log_level >= LOG_DEBUG)
+ add_openvpn_arg (args, "10");
+ else if (gl.log_level >= LOG_INFO)
+ add_openvpn_arg (args, "5");
+ else
+ add_openvpn_arg (args, "2");
} else {
- /* Syslog */
+ /* the default level is already "--verb 1", which is fine for us. */
+ }
+
+ if (gl.log_syslog) {
add_openvpn_arg (args, "--syslog");
add_openvpn_arg (args, "nm-openvpn");
}
@@ -1473,7 +1485,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");
g_object_get (plugin, NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, &bus_name, NULL);
- stmp = g_strdup_printf ("%s%s --bus-name %s %s --", NM_OPENVPN_HELPER_PATH, gl.debug ? "
--helper-debug" : "",
+ stmp = g_strdup_printf ("%s%s --bus-name %s %s --", NM_OPENVPN_HELPER_PATH, _LOG_d_enabled () ? "
--helper-debug" : "",
bus_name, dev_type_is_tap ? "--tap" : "--tun");
add_openvpn_arg (args, stmp);
g_free (stmp);
@@ -2031,6 +2043,14 @@ main (int argc, char *argv[])
}
g_option_context_free (opt_ctx);
+ gl.log_level = _nm_utils_ascii_str_to_int64 (getenv ("NM_VPN_LOG_LEVEL"),
+ 10, 0, LOG_DEBUG,
+ gl.debug ? LOG_DEBUG : 0);
+
+ gl.log_syslog = _nm_utils_ascii_str_to_int64 (getenv ("NM_VPN_LOG_SYSLOG"),
+ 10, 0, 1,
+ gl.debug ? 0 : 1);
+
_LOG_d ("nm-openvpn-service (version " DIST_VERSION ") starting...");
if ( !g_file_test ("/sys/class/misc/tun", G_FILE_TEST_EXISTS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]