core: add "fatal-warnings" option to NM_DEBUG
NM already understands the command line argument --g-fatal-warnings which causes setting of g_log_set_always_fatal(). Also interpret the "fatal-warnings" token in NM_DEBUG environment variable and in main.debug configuration setting. Usage hint: either set $ export NM_DEBUG=RLIMIT_CORE,fatal-warnings or add the following section to NetworkManager.conf [main] debug=RLIMIT_CORE,fatal-warnings https://mail.gnome.org/archives/networkmanager-list/2015-March/msg00093.html
This commit is contained in:
@@ -261,7 +261,13 @@ no-auto-default=*
|
|||||||
values are supported:</para>
|
values are supported:</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>RLIMIT_CORE</literal>: set ulimit -c unlimited
|
<literal>RLIMIT_CORE</literal>: set ulimit -c unlimited
|
||||||
to write out core dumps.
|
to write out core dumps. Beware, that a core dump can contain
|
||||||
|
sensitive information such as passwords or configuration settings.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
<literal>fatal-warnings</literal>: set g_log_set_always_fatal()
|
||||||
|
to core dump on warning messages from glib. This is equivalent
|
||||||
|
to the --g-fatal-warnings command line option.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
25
src/main.c
25
src/main.c
@@ -159,12 +159,24 @@ parse_state_file (const char *filename,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_set_g_fatal_warnings ()
|
||||||
|
{
|
||||||
|
GLogLevelFlags fatal_mask;
|
||||||
|
|
||||||
|
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
||||||
|
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
||||||
|
g_log_set_always_fatal (fatal_mask);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_init_nm_debug (const char *debug)
|
_init_nm_debug (const char *debug)
|
||||||
{
|
{
|
||||||
const guint D_RLIMIT_CORE = 1;
|
const guint D_RLIMIT_CORE = 1;
|
||||||
|
const guint D_FATAL_WARNINGS = 2;
|
||||||
GDebugKey keys[] = {
|
GDebugKey keys[] = {
|
||||||
{ "RLIMIT_CORE", D_RLIMIT_CORE },
|
{ "RLIMIT_CORE", D_RLIMIT_CORE },
|
||||||
|
{ "fatal-warnings", D_FATAL_WARNINGS },
|
||||||
};
|
};
|
||||||
guint flags = 0;
|
guint flags = 0;
|
||||||
const char *env = getenv ("NM_DEBUG");
|
const char *env = getenv ("NM_DEBUG");
|
||||||
@@ -178,7 +190,7 @@ _init_nm_debug (const char *debug)
|
|||||||
if (debug && strcasecmp (debug, "help") != 0)
|
if (debug && strcasecmp (debug, "help") != 0)
|
||||||
flags |= g_parse_debug_string (debug, keys, G_N_ELEMENTS (keys));
|
flags |= g_parse_debug_string (debug, keys, G_N_ELEMENTS (keys));
|
||||||
|
|
||||||
if (flags & D_RLIMIT_CORE) {
|
if (NM_FLAGS_HAS (flags, D_RLIMIT_CORE)) {
|
||||||
/* only enable this, if explicitly requested, because it might
|
/* only enable this, if explicitly requested, because it might
|
||||||
* expose sensitive data. */
|
* expose sensitive data. */
|
||||||
|
|
||||||
@@ -188,6 +200,8 @@ _init_nm_debug (const char *debug)
|
|||||||
};
|
};
|
||||||
setrlimit (RLIMIT_CORE, &limit);
|
setrlimit (RLIMIT_CORE, &limit);
|
||||||
}
|
}
|
||||||
|
if (NM_FLAGS_HAS (flags, D_FATAL_WARNINGS))
|
||||||
|
_set_g_fatal_warnings ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -270,13 +284,8 @@ main (int argc, char *argv[])
|
|||||||
config_cli = nm_config_cmd_line_options_new ();
|
config_cli = nm_config_cmd_line_options_new ();
|
||||||
do_early_setup (&argc, &argv, config_cli);
|
do_early_setup (&argc, &argv, config_cli);
|
||||||
|
|
||||||
if (global_opt.g_fatal_warnings) {
|
if (global_opt.g_fatal_warnings)
|
||||||
GLogLevelFlags fatal_mask;
|
_set_g_fatal_warnings ();
|
||||||
|
|
||||||
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
||||||
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
||||||
g_log_set_always_fatal (fatal_mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global_opt.show_version) {
|
if (global_opt.show_version) {
|
||||||
fprintf (stdout, NM_DIST_VERSION "\n");
|
fprintf (stdout, NM_DIST_VERSION "\n");
|
||||||
|
Reference in New Issue
Block a user