From 4a22cefc6cff7d5beb351fc72095738bc8cd844e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2014 22:04:44 +0100 Subject: 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 --- src/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/main.c') 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 #include #include +#include #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); -- cgit v1.2.1