summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-03-06 22:04:44 +0100
committerThomas Haller <thaller@redhat.com>2014-05-02 11:08:14 +0200
commit4a22cefc6cff7d5beb351fc72095738bc8cd844e (patch)
tree5a917853efba280dce243f0014ffb3599a8e6b3d /src/main.c
parentf5b82f49ddfb2ecbf2e865b914d639ddca5a28c8 (diff)
downloadNetworkManager-4a22cefc6cff7d5beb351fc72095738bc8cd844e.tar.gz
core: add configuration main.debug and interpret environment variable NM_DEBUG
Interpret the configuration option main.debug and the environment variable NM_DEBUG as a comma separated list of debugging options (parsed with g_parse_debug_string()). Currently only the option "RLIMIT_CORE" is supported, to set the core dump size to unlimited. Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 16a124c14f..15ac6a9e33 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@
#include <glib/gi18n.h>
#include <gmodule.h>
#include <string.h>
+#include <sys/resource.h>
#include "libgsystem.h"
#include "NetworkManager.h"
@@ -293,6 +294,37 @@ parse_state_file (const char *filename,
return TRUE;
}
+static void
+_init_nm_debug (const char *debug)
+{
+ const guint D_RLIMIT_CORE = 1;
+ GDebugKey keys[] = {
+ { "RLIMIT_CORE", D_RLIMIT_CORE },
+ };
+ guint flags = 0;
+ const char *env = getenv ("NM_DEBUG");
+
+ if (env && strcasecmp (env, "help") != 0) {
+ /* g_parse_debug_string() prints options to stderr if the variable
+ * is set to "help". Don't allow that. */
+ flags = g_parse_debug_string (env, keys, G_N_ELEMENTS (keys));
+ }
+
+ if (debug && strcasecmp (debug, "help") != 0)
+ flags |= g_parse_debug_string (debug, keys, G_N_ELEMENTS (keys));
+
+ if (flags & D_RLIMIT_CORE) {
+ /* only enable this, if explicitly requested, because it might
+ * expose sensitive data. */
+
+ struct rlimit limit = {
+ .rlim_cur = RLIM_INFINITY,
+ .rlim_max = RLIM_INFINITY,
+ };
+ setrlimit (RLIMIT_CORE, &limit);
+ }
+}
+
/*
* main
*
@@ -516,6 +548,8 @@ main (int argc, char *argv[])
wrote_pidfile = TRUE;
}
+ _init_nm_debug (nm_config_get_debug (config));
+
/* Set up unix signal handling - before creating threads, but after daemonizing! */
if (!setup_signals ())
exit (1);