From a8e02899bcfd0a96db65bd50e41c52f11e81500d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 28 Sep 2016 18:06:19 +0200 Subject: [PATCH] config: add default values to 'NM --print-config' output There isn't an easy way to determine the effective value of some configuration options as their default value can be set at build time; the user has to search in logs or look at the manual page when available. This adds those default values that can be changed at build time to the output of 'NetworkManager --print-config': [main] # plugins=ifcfg-rh,ifupdown,ifnet,ibft # rc-manager=symlink # auth-polkit=true dns=dnsmasq ... [logging] # backend=journal ... --- src/nm-config-data.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 6f83e6656..73427d2a8 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -535,6 +535,17 @@ _nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy) return 0; } +static struct { + const char *group; + const char *key; + const char *value; +} default_values[] = { + { NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_PLUGINS_DEFAULT }, + { NM_CONFIG_KEYFILE_GROUP_MAIN, "rc-manager", NM_CONFIG_DEFAULT_DNS_RC_MANAGER }, + { NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT }, + { NM_CONFIG_KEYFILE_GROUP_LOGGING, "backend", NM_CONFIG_LOGGING_BACKEND_DEFAULT }, +}; + void nm_config_data_log (const NMConfigData *self, const char *prefix, @@ -544,7 +555,7 @@ nm_config_data_log (const NMConfigData *self, const NMConfigDataPrivate *priv; gs_strfreev char **groups = NULL; gsize ngroups; - guint g, k; + guint g, k, i; FILE *stream = print_stream; g_return_if_fail (NM_IS_CONFIG_DATA (self)); @@ -591,6 +602,15 @@ nm_config_data_log (const NMConfigData *self, _LOG (stream, prefix, ""); _LOG (stream, prefix, "[%s]%s", group, is_atomic && !stream ? " # atomic section" : ""); + /* Print default values as comments */ + for (i = 0; i < G_N_ELEMENTS (default_values); i++) { + if ( nm_streq (default_values[i].group, group) + && !g_key_file_has_key (priv->keyfile, group, default_values[i].key, NULL)) { + _LOG (stream, prefix, "%s# %s=%s", key_prefix, default_values[i].key, + default_values[i].value); + } + } + keys = g_key_file_get_keys (priv->keyfile, group, NULL, NULL); for (k = 0; keys && keys[k]; k++) { const char *key = keys[k];