diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 6a7a4b9fd0..65c22a1a4a 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -207,6 +207,20 @@ Copyright (C) 2010 - 2013 Red Hat, Inc. modify resolv.conf. + + + debug + Comma separated list of options to aid + debugging. This value will be combined with the environment + variable NM_DEBUG. Currently the following + values are supported: + + RLIMIT_CORE: set ulimit -c unlimited + to write out core dumps. + + + + diff --git a/src/config/nm-config.c b/src/config/nm-config.c index e241b74754..f6688b75da 100644 --- a/src/config/nm-config.c +++ b/src/config/nm-config.c @@ -51,6 +51,8 @@ typedef struct { char *log_level; char *log_domains; + char *debug; + char *connectivity_uri; gint connectivity_interval; char *connectivity_response; @@ -131,6 +133,14 @@ nm_config_get_log_domains (NMConfig *config) return NM_CONFIG_GET_PRIVATE (config)->log_domains; } +const char * +nm_config_get_debug (NMConfig *config) +{ + g_return_val_if_fail (config != NULL, NULL); + + return NM_CONFIG_GET_PRIVATE (config)->debug; +} + const char * nm_config_get_connectivity_uri (NMConfig *config) { @@ -519,6 +529,8 @@ nm_config_new (GError **error) priv->log_level = g_key_file_get_value (priv->keyfile, "logging", "level", NULL); priv->log_domains = g_key_file_get_value (priv->keyfile, "logging", "domains", NULL); + priv->debug = g_key_file_get_value (priv->keyfile, "main", "debug", NULL); + if (cli_connectivity_uri && cli_connectivity_uri[0]) g_key_file_set_value (priv->keyfile, "connectivity", "uri", cli_connectivity_uri); priv->connectivity_uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL); @@ -562,6 +574,7 @@ finalize (GObject *gobject) g_free (priv->dns_mode); g_free (priv->log_level); g_free (priv->log_domains); + g_free (priv->debug); g_free (priv->connectivity_uri); g_free (priv->connectivity_response); g_strfreev (priv->no_auto_default); diff --git a/src/config/nm-config.h b/src/config/nm-config.h index 14635d8d67..2e335c7165 100644 --- a/src/config/nm-config.h +++ b/src/config/nm-config.h @@ -56,6 +56,7 @@ const char *nm_config_get_dhcp_client (NMConfig *config); const char *nm_config_get_dns_mode (NMConfig *config); const char *nm_config_get_log_level (NMConfig *config); const char *nm_config_get_log_domains (NMConfig *config); +const char *nm_config_get_debug (NMConfig *config); const char *nm_config_get_connectivity_uri (NMConfig *config); const guint nm_config_get_connectivity_interval (NMConfig *config); const char *nm_config_get_connectivity_response (NMConfig *config); 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);