From fb2ca0ce3dadae8154d2ad8b611538323be137ac Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 28 Sep 2016 17:31:34 +0200 Subject: [PATCH 1/3] config: don't set default plugins in nm-config keyfile Like all other keys that can have a default value, substitute the default only when needed. In this way, we can tell later if the value comes from configuration file or if it's the default value. Also, rename CONFIG_PLUGINS_DEFAULT to NM_CONFIG_PLUGINS_DEFAULT. --- configure.ac | 2 +- src/nm-config.c | 10 +--------- src/settings/nm-settings.c | 10 +++++++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 570aae398..79b9a1075 100644 --- a/configure.ac +++ b/configure.ac @@ -134,7 +134,7 @@ test "$enable_ifupdown" = "yes" && distro_plugins="$distro_plugins,ifu test "$enable_ifnet" = "yes" && distro_plugins="$distro_plugins,ifnet" distro_plugins="${distro_plugins#,}" -AC_DEFINE_UNQUOTED(CONFIG_PLUGINS_DEFAULT, "$config_plugins_default", [Default configuration option for main.plugins setting]) +AC_DEFINE_UNQUOTED(NM_CONFIG_PLUGINS_DEFAULT, "$config_plugins_default", [Default configuration option for main.plugins setting]) if test "${enable_config_plugin_ibft}" = yes; then AC_DEFINE(WITH_SETTINGS_PLUGIN_IBFT, 1, [Whether compilation of ibft setting plugin is enabled]) else diff --git a/src/nm-config.c b/src/nm-config.c index 0ef7fc209..9615353bd 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -512,7 +512,7 @@ nm_config_cmd_line_options_add_to_entries (NMConfigCmdLineOptions *cli, { "intern-config", 0, 0, G_OPTION_ARG_FILENAME, &cli->intern_config_file, N_("Internal config file location"), N_(DEFAULT_INTERN_CONFIG_FILE) }, { "state-file", 0, 0, G_OPTION_ARG_FILENAME, &cli->state_file, N_("State file location"), N_(DEFAULT_STATE_FILE) }, { "no-auto-default", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &cli->no_auto_default_file, N_("State file for no-auto-default devices"), N_(DEFAULT_NO_AUTO_DEFAULT_FILE) }, - { "plugins", 0, 0, G_OPTION_ARG_STRING, &cli->plugins, N_("List of plugins separated by ','"), N_(CONFIG_PLUGINS_DEFAULT) }, + { "plugins", 0, 0, G_OPTION_ARG_STRING, &cli->plugins, N_("List of plugins separated by ','"), N_(NM_CONFIG_PLUGINS_DEFAULT) }, { "configure-and-quit", 0, 0, G_OPTION_ARG_NONE, &cli->configure_and_quit, N_("Quit after initial configuration"), NULL }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &cli->is_debug, N_("Don't become a daemon, and log to stderr"), NULL }, @@ -947,7 +947,6 @@ read_entire_config (const NMConfigCmdLineOptions *cli, guint i; gs_free char *o_config_main_file = NULL; GString *str; - char **plugins_default; g_return_val_if_fail (config_dir, NULL); g_return_val_if_fail (system_config_dir, NULL); @@ -958,11 +957,6 @@ read_entire_config (const NMConfigCmdLineOptions *cli, /* create a default configuration file. */ keyfile = nm_config_create_keyfile (); - plugins_default = g_strsplit (CONFIG_PLUGINS_DEFAULT, ",", -1); - if (plugins_default && plugins_default[0]) - nm_config_keyfile_set_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", (const char *const*) plugins_default, -1); - g_strfreev (plugins_default); - system_confs = _get_config_dir_files (system_config_dir); confs = _get_config_dir_files (config_dir); @@ -2305,8 +2299,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) priv->plugins = _nm_utils_strv_cleanup (g_key_file_get_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL), TRUE, TRUE, TRUE); - if (!priv->plugins) - priv->plugins = g_new0 (char *, 1); priv->monitor_connection_files = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "monitor-connection-files", FALSE); diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 3f2e38c3a..aafb54375 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -2292,11 +2292,19 @@ nm_settings_start (NMSettings *self, GError **error) GDBusProxy *proxy; GVariant *variant; GError *local_error = NULL; + const char **plugins; + gs_strfreev char **plugins_default = NULL; priv = NM_SETTINGS_GET_PRIVATE (self); /* Load the plugins; fail if a plugin is not found. */ - if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) { + plugins = nm_config_get_plugins (priv->config); + if (!plugins) { + plugins_default = g_strsplit (NM_CONFIG_PLUGINS_DEFAULT, ",", -1); + plugins = (const char **) plugins_default; + } + + if (!load_plugins (self, plugins, error)) { g_object_unref (self); return FALSE; } From 63ceab3a480ac958c6db46fd2389139cfd3a6f20 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 28 Sep 2016 17:54:42 +0200 Subject: [PATCH 2/3] config: pass default auth-polkit value as string instead of boolean It is less efficient, but allows us to easily print the default value. --- configure.ac | 9 ++++----- src/nm-config.c | 6 +++--- src/nm-config.h | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 79b9a1075..6f067c20d 100644 --- a/configure.ac +++ b/configure.ac @@ -579,18 +579,17 @@ AC_ARG_ENABLE(polkit, AS_HELP_STRING([--enable-polkit=yes|no|disabled], [set def [enable_polkit=${enableval}], [enable_polkit=yes]) if (test "${enable_polkit}" != "no" -a "${enable_polkit}" != "disabled"); then enable_polkit=yes - AC_DEFINE(NM_CONFIG_DEFAULT_AUTH_POLKIT, TRUE, [The default value of the auth-polkit configuration option]) - NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT='true' + AC_DEFINE(NM_CONFIG_DEFAULT_AUTH_POLKIT, "true", [The default value of the auth-polkit configuration option]) + AC_SUBST(NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT, true) else - AC_DEFINE(NM_CONFIG_DEFAULT_AUTH_POLKIT, FALSE, [The default value of the auth-polkit configuration option]) - NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT='false' + AC_DEFINE(NM_CONFIG_DEFAULT_AUTH_POLKIT, "false", [The default value of the auth-polkit configuration option]) + AC_SUBST(NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT, false) fi if (test "${enable_polkit}" != "disabled"); then AC_DEFINE(WITH_POLKIT, 1, [whether to compile polkit support]) else AC_DEFINE(WITH_POLKIT, 0, [whether to compile polkit support]) fi -AC_SUBST(NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT) PKG_CHECK_MODULES(POLKIT, [polkit-agent-1 >= 0.97], [have_pk_agent=yes],[have_pk_agent=no]) AC_ARG_ENABLE(polkit-agent, AS_HELP_STRING([--enable-polkit-agent], [enable polkit agent for clients]), diff --git a/src/nm-config.c b/src/nm-config.c index 9615353bd..535d6ea7d 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -285,7 +285,7 @@ nm_config_get_monitor_connection_files (NMConfig *config) gboolean nm_config_get_auth_polkit (NMConfig *config) { - g_return_val_if_fail (NM_IS_CONFIG (config), NM_CONFIG_DEFAULT_AUTH_POLKIT); + g_return_val_if_fail (NM_IS_CONFIG (config), NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL); return NM_CONFIG_GET_PRIVATE (config)->auth_polkit; } @@ -2302,7 +2302,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) priv->monitor_connection_files = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "monitor-connection-files", FALSE); - priv->auth_polkit = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT); + priv->auth_polkit = nm_config_keyfile_get_boolean (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "auth-polkit", NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL); priv->dhcp_client = nm_strstrip (g_key_file_get_string (keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "dhcp", NULL)); @@ -2343,7 +2343,7 @@ nm_config_init (NMConfig *config) { NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config); - priv->auth_polkit = NM_CONFIG_DEFAULT_AUTH_POLKIT; + priv->auth_polkit = NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL; } NMConfig * diff --git a/src/nm-config.h b/src/nm-config.h index 1b80e96da..bfa23e112 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -182,6 +182,7 @@ extern char *_nm_config_match_env; /*****************************************************************************/ #define NM_CONFIG_DEVICE_STATE_DIR ""NMRUNDIR"/devices" +#define NM_CONFIG_DEFAULT_AUTH_POLKIT_BOOL (nm_streq0 (NM_CONFIG_DEFAULT_AUTH_POLKIT, "true")) typedef enum { NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN = -1, From a8e02899bcfd0a96db65bd50e41c52f11e81500d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 28 Sep 2016 18:06:19 +0200 Subject: [PATCH 3/3] 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];