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>
This commit is contained in:
Thomas Haller 2014-03-06 22:04:44 +01:00
parent f5b82f49dd
commit 4a22cefc6c
4 changed files with 62 additions and 0 deletions

View file

@ -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>

View file

@ -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);

View file

@ -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);

View file

@ -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);