mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 18:20:29 +01:00
main: add argument --print-config to NetworkManager
This commit is contained in:
parent
c2831875e3
commit
e1ea4b725e
6 changed files with 65 additions and 11 deletions
|
|
@ -360,6 +360,12 @@
|
|||
for more information.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--print-config</option></term>
|
||||
<listitem><para>
|
||||
Print the NetworkMangager configuration to stdout and exit.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
|
|
|||
34
src/main.c
34
src/main.c
|
|
@ -64,6 +64,7 @@ static gboolean configure_and_quit = FALSE;
|
|||
|
||||
static struct {
|
||||
gboolean show_version;
|
||||
gboolean print_config;
|
||||
gboolean become_daemon;
|
||||
gboolean g_fatal_warnings;
|
||||
gboolean run_from_build_dir;
|
||||
|
|
@ -211,6 +212,28 @@ manager_configure_quit (NMManager *manager, gpointer user_data)
|
|||
configure_and_quit = TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
print_config (NMConfigCmdLineOptions *config_cli)
|
||||
{
|
||||
gs_unref_object NMConfig *config = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
NMConfigData *config_data;
|
||||
|
||||
nm_logging_setup ("OFF", "ALL", NULL, NULL);
|
||||
|
||||
config = nm_config_new (config_cli, NULL, &error);
|
||||
if (config == NULL) {
|
||||
fprintf (stderr, _("Failed to read configuration: %s\n"),
|
||||
(error && error->message) ? error->message : _("unknown"));
|
||||
return 7;
|
||||
}
|
||||
|
||||
config_data = nm_config_get_data (config);
|
||||
fprintf (stdout, "# NetworkManager configuration: %s\n", nm_config_data_get_config_description (config_data));
|
||||
nm_config_data_log (config_data, "", "", stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli)
|
||||
{
|
||||
|
|
@ -225,6 +248,7 @@ do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli)
|
|||
{ "pid-file", 'p', 0, G_OPTION_ARG_FILENAME, &global_opt.pidfile, N_("Specify the location of a PID file"), N_(NM_DEFAULT_PID_FILE) },
|
||||
{ "state-file", 0, 0, G_OPTION_ARG_FILENAME, &global_opt.state_file, N_("State file location"), N_(NM_DEFAULT_SYSTEM_STATE_FILE) },
|
||||
{ "run-from-build-dir", 0, 0, G_OPTION_ARG_NONE, &global_opt.run_from_build_dir, "Run from build directory", NULL },
|
||||
{ "print-config", 0, 0, G_OPTION_ARG_NONE, &global_opt.print_config, N_("Print NetworkManager configuration and exit"), NULL },
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
|
@ -279,6 +303,14 @@ main (int argc, char *argv[])
|
|||
exit (0);
|
||||
}
|
||||
|
||||
if (global_opt.print_config) {
|
||||
int result;
|
||||
|
||||
result = print_config (config_cli);
|
||||
nm_config_cmd_line_options_free (config_cli);
|
||||
exit (result);
|
||||
}
|
||||
|
||||
nm_main_utils_ensure_root ();
|
||||
|
||||
nm_main_utils_ensure_not_running_pidfile (global_opt.pidfile);
|
||||
|
|
@ -397,7 +429,7 @@ main (int argc, char *argv[])
|
|||
g_clear_error (&error);
|
||||
|
||||
nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config)));
|
||||
nm_config_data_log (nm_config_get_data (config), "CONFIG: ");
|
||||
nm_config_data_log (nm_config_get_data (config), "CONFIG: ", " ", NULL);
|
||||
nm_log_dbg (LOGD_CORE, "WEXT support is %s",
|
||||
#if HAVE_WEXT
|
||||
"enabled"
|
||||
|
|
|
|||
|
|
@ -495,22 +495,34 @@ _nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy)
|
|||
}
|
||||
|
||||
void
|
||||
nm_config_data_log (const NMConfigData *self, const char *prefix)
|
||||
nm_config_data_log (const NMConfigData *self,
|
||||
const char *prefix,
|
||||
const char *key_prefix,
|
||||
/* FILE* */ gpointer print_stream)
|
||||
{
|
||||
NMConfigDataPrivate *priv;
|
||||
gs_strfreev char **groups = NULL;
|
||||
gsize ngroups;
|
||||
guint g, k;
|
||||
FILE *stream = print_stream;
|
||||
|
||||
g_return_if_fail (NM_IS_CONFIG_DATA (self));
|
||||
|
||||
if (!nm_logging_enabled (LOGL_DEBUG, LOGD_CORE))
|
||||
if (!stream && !nm_logging_enabled (LOGL_DEBUG, LOGD_CORE))
|
||||
return;
|
||||
|
||||
if (!prefix)
|
||||
prefix = "";
|
||||
if (!key_prefix)
|
||||
key_prefix = "";
|
||||
|
||||
#define _LOG(...) _nm_log (LOGL_DEBUG, LOGD_CORE, 0, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__), prefix _NM_UTILS_MACRO_REST (__VA_ARGS__))
|
||||
#define _LOG(stream, prefix, ...) \
|
||||
G_STMT_START { \
|
||||
if (!stream) \
|
||||
_nm_log (LOGL_DEBUG, LOGD_CORE, 0, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__)"%s", prefix _NM_UTILS_MACRO_REST (__VA_ARGS__), ""); \
|
||||
else \
|
||||
fprintf (stream, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__)"%s", prefix _NM_UTILS_MACRO_REST (__VA_ARGS__), "\n"); \
|
||||
} G_STMT_END
|
||||
|
||||
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
|
||||
|
||||
|
|
@ -525,7 +537,8 @@ nm_config_data_log (const NMConfigData *self, const char *prefix)
|
|||
NULL);
|
||||
}
|
||||
|
||||
_LOG ("config-data[%p]: %lu groups", self, (unsigned long) ngroups);
|
||||
if (!stream)
|
||||
_LOG (stream, prefix, "config-data[%p]: %lu groups", self, (unsigned long) ngroups);
|
||||
|
||||
for (g = 0; g < ngroups; g++) {
|
||||
const char *group = groups[g];
|
||||
|
|
@ -534,8 +547,8 @@ nm_config_data_log (const NMConfigData *self, const char *prefix)
|
|||
|
||||
is_atomic = nm_config_data_is_intern_atomic_group (self, group);
|
||||
|
||||
_LOG ("");
|
||||
_LOG ("[%s]%s", group, is_atomic ? "*" : "");
|
||||
_LOG (stream, prefix, "");
|
||||
_LOG (stream, prefix, "[%s]%s", group, is_atomic && !stream ? " # atomic section" : "");
|
||||
|
||||
keys = g_key_file_get_keys (priv->keyfile, group, NULL, NULL);
|
||||
for (k = 0; keys && keys[k]; k++) {
|
||||
|
|
@ -543,7 +556,7 @@ nm_config_data_log (const NMConfigData *self, const char *prefix)
|
|||
gs_free char *value = NULL;
|
||||
|
||||
value = g_key_file_get_value (priv->keyfile, group, key, NULL);
|
||||
_LOG (" %s=%s", key, value);
|
||||
_LOG (stream, prefix, "%s%s=%s", key_prefix, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,10 @@ NMConfigData *nm_config_data_new_update_no_auto_default (const NMConfigData *bas
|
|||
|
||||
NMConfigChangeFlags nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data);
|
||||
|
||||
void nm_config_data_log (const NMConfigData *config_data, const char *prefix);
|
||||
void nm_config_data_log (const NMConfigData *self,
|
||||
const char *prefix,
|
||||
const char *key_prefix,
|
||||
/* FILE* */ gpointer print_stream);
|
||||
|
||||
const char *nm_config_data_get_config_main_file (const NMConfigData *config_data);
|
||||
const char *nm_config_data_get_config_description (const NMConfigData *config_data);
|
||||
|
|
|
|||
|
|
@ -1796,7 +1796,7 @@ _set_config_data (NMConfig *self, NMConfigData *new_data, int signal)
|
|||
if (new_data) {
|
||||
nm_log_info (LOGD_CORE, "config: update %s (%s)", nm_config_data_get_config_description (new_data),
|
||||
(log_str = nm_config_change_flags_to_string (changes)));
|
||||
nm_config_data_log (new_data, "CONFIG: ");
|
||||
nm_config_data_log (new_data, "CONFIG: ", " ", NULL);
|
||||
priv->config_data = new_data;
|
||||
} else if (had_new_data)
|
||||
nm_log_info (LOGD_CORE, "config: signal %s (no changes from disk)", (log_str = nm_config_change_flags_to_string (changes)));
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ test_config_confdir (void)
|
|||
g_assert_cmpstr (value, ==, "VAL5");
|
||||
g_free (value);
|
||||
|
||||
nm_config_data_log (nm_config_get_data_orig (config), ">>> TEST: ");
|
||||
nm_config_data_log (nm_config_get_data_orig (config), ">>> TEST: ", " ", NULL);
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue