summaryrefslogtreecommitdiff
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
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>
-rw-r--r--man/NetworkManager.conf.xml14
-rw-r--r--src/config/nm-config.c13
-rw-r--r--src/config/nm-config.h1
-rw-r--r--src/main.c34
4 files changed, 62 insertions, 0 deletions
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.</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><varname>debug</varname></term>
+ <listitem><para>Comma separated list of options to aid
+ debugging. This value will be combined with the environment
+ variable <literal>NM_DEBUG</literal>. Currently the following
+ values are supported:</para>
+ <para>
+ <literal>RLIMIT_CORE</literal>: set ulimit -c unlimited
+ to write out core dumps.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
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;
@@ -132,6 +134,14 @@ nm_config_get_log_domains (NMConfig *config)
}
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)
{
g_return_val_if_fail (config != NULL, NULL);
@@ -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 <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);