summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-01-06 20:16:10 +0100
committerThomas Haller <thaller@redhat.com>2015-02-03 13:01:53 +0100
commit56f5fba72353e55db554c359af00376d3959009d (patch)
tree097f53c4b4310c3d760119faa5e79c04b5497877
parent699b12ddc9ca502ad75077722d4af4f675377b40 (diff)
downloadNetworkManager-56f5fba72353e55db554c359af00376d3959009d.tar.gz
config: move main_file and description to NMConfigData
Every reload might change the main_file and description. Move those properties to NMConfigData.
-rw-r--r--src/main.c2
-rw-r--r--src/nm-config-data.c58
-rw-r--r--src/nm-config-data.h9
-rw-r--r--src/nm-config.c57
-rw-r--r--src/nm-config.h3
-rw-r--r--src/settings/plugins/example/plugin.c2
-rw-r--r--src/settings/plugins/ifupdown/plugin.c2
-rw-r--r--src/settings/plugins/keyfile/plugin.c2
-rw-r--r--src/tests/config/test-config.c6
9 files changed, 104 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index e1d2805a5c..11ecffca98 100644
--- a/src/main.c
+++ b/src/main.c
@@ -387,7 +387,7 @@ main (int argc, char *argv[])
nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting...");
success = FALSE;
- nm_log_info (LOGD_CORE, "Read config: %s", nm_config_get_config_description (config));
+ nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config)));
nm_log_info (LOGD_CORE, "WEXT support is %s",
#if HAVE_WEXT
"enabled"
diff --git a/src/nm-config-data.c b/src/nm-config-data.c
index a4799f76c6..03d3811065 100644
--- a/src/nm-config-data.c
+++ b/src/nm-config-data.c
@@ -22,6 +22,9 @@
#include "nm-config-data.h"
typedef struct {
+ char *config_main_file;
+ char *config_description;
+
struct {
char *uri;
char *response;
@@ -32,6 +35,8 @@ typedef struct {
enum {
PROP_0,
+ PROP_CONFIG_MAIN_FILE,
+ PROP_CONFIG_DESCRIPTION,
PROP_CONNECTIVITY_URI,
PROP_CONNECTIVITY_INTERVAL,
PROP_CONNECTIVITY_RESPONSE,
@@ -46,6 +51,22 @@ G_DEFINE_TYPE (NMConfigData, nm_config_data, G_TYPE_OBJECT)
/************************************************************************/
const char *
+nm_config_data_get_config_main_file (const NMConfigData *self)
+{
+ g_return_val_if_fail (self, NULL);
+
+ return NM_CONFIG_DATA_GET_PRIVATE (self)->config_main_file;
+}
+
+const char *
+nm_config_data_get_config_description (const NMConfigData *self)
+{
+ g_return_val_if_fail (self, NULL);
+
+ return NM_CONFIG_DATA_GET_PRIVATE (self)->config_description;
+}
+
+const char *
nm_config_data_get_connectivity_uri (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
@@ -81,6 +102,12 @@ get_property (GObject *object,
NMConfigData *self = NM_CONFIG_DATA (object);
switch (prop_id) {
+ case PROP_CONFIG_MAIN_FILE:
+ g_value_set_string (value, nm_config_data_get_config_main_file (self));
+ break;
+ case PROP_CONFIG_DESCRIPTION:
+ g_value_set_string (value, nm_config_data_get_config_description (self));
+ break;
case PROP_CONNECTIVITY_URI:
g_value_set_string (value, nm_config_data_get_connectivity_uri (self));
break;
@@ -107,6 +134,12 @@ set_property (GObject *object,
/* This type is immutable. All properties are construct only. */
switch (prop_id) {
+ case PROP_CONFIG_MAIN_FILE:
+ priv->config_main_file = g_value_dup_string (value);
+ break;
+ case PROP_CONFIG_DESCRIPTION:
+ priv->config_description = g_value_dup_string (value);
+ break;
case PROP_CONNECTIVITY_URI:
priv->connectivity.uri = g_value_dup_string (value);
break;
@@ -132,6 +165,9 @@ finalize (GObject *gobject)
{
NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (gobject);
+ g_free (priv->config_main_file);
+ g_free (priv->config_description);
+
g_free (priv->connectivity.uri);
g_free (priv->connectivity.response);
@@ -144,7 +180,9 @@ nm_config_data_init (NMConfigData *self)
}
NMConfigData *
-nm_config_data_new (GKeyFile *keyfile)
+nm_config_data_new (const char *config_main_file,
+ const char *config_description,
+ GKeyFile *keyfile)
{
char *connectivity_uri, *connectivity_response;
guint connectivity_interval;
@@ -155,6 +193,8 @@ nm_config_data_new (GKeyFile *keyfile)
connectivity_response = g_key_file_get_value (keyfile, "connectivity", "response", NULL);
config_data = g_object_new (NM_TYPE_CONFIG_DATA,
+ NM_CONFIG_DATA_CONFIG_MAIN_FILE, config_main_file,
+ NM_CONFIG_DATA_CONFIG_DESCRIPTION, config_description,
NM_CONFIG_DATA_CONNECTIVITY_URI, connectivity_uri,
NM_CONFIG_DATA_CONNECTIVITY_INTERVAL, connectivity_interval,
NM_CONFIG_DATA_CONNECTIVITY_RESPONSE, connectivity_response,
@@ -178,6 +218,22 @@ nm_config_data_class_init (NMConfigDataClass *config_class)
object_class->set_property = set_property;
g_object_class_install_property
+ (object_class, PROP_CONFIG_MAIN_FILE,
+ g_param_spec_string (NM_CONFIG_DATA_CONFIG_MAIN_FILE, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
+ (object_class, PROP_CONFIG_DESCRIPTION,
+ g_param_spec_string (NM_CONFIG_DATA_CONFIG_DESCRIPTION, "", "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
(object_class, PROP_CONNECTIVITY_URI,
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_URI, "", "",
NULL,
diff --git a/src/nm-config-data.h b/src/nm-config-data.h
index 042ce98164..c690f08b97 100644
--- a/src/nm-config-data.h
+++ b/src/nm-config-data.h
@@ -36,6 +36,8 @@ G_BEGIN_DECLS
#define NM_CONFIG_DATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONFIG_DATA, NMConfigDataClass))
+#define NM_CONFIG_DATA_CONFIG_MAIN_FILE "config-main-file"
+#define NM_CONFIG_DATA_CONFIG_DESCRIPTION "config-description"
#define NM_CONFIG_DATA_CONNECTIVITY_URI "connectivity-uri"
#define NM_CONFIG_DATA_CONNECTIVITY_INTERVAL "connectivity-interval"
#define NM_CONFIG_DATA_CONNECTIVITY_RESPONSE "connectivity-response"
@@ -50,7 +52,12 @@ typedef struct {
GType nm_config_data_get_type (void);
-NMConfigData *nm_config_data_new (GKeyFile *keyfile);
+NMConfigData *nm_config_data_new (const char *config_main_file,
+ const char *config_description,
+ GKeyFile *keyfile);
+
+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);
const char *nm_config_data_get_connectivity_uri (const NMConfigData *config_data);
const guint nm_config_data_get_connectivity_interval (const NMConfigData *config_data);
diff --git a/src/nm-config.c b/src/nm-config.c
index 4573b7c050..6fb7335133 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -59,9 +59,7 @@ typedef struct {
NMConfigData *config_data;
NMConfigData *config_data_orig;
- char *config_main_file;
char *config_dir;
- char *config_description;
char *no_auto_default_file;
GKeyFile *keyfile;
@@ -159,22 +157,6 @@ nm_config_get_data_orig (NMConfig *config)
return NM_CONFIG_GET_PRIVATE (config)->config_data_orig;
}
-const char *
-nm_config_get_config_main_file (NMConfig *config)
-{
- g_return_val_if_fail (config != NULL, NULL);
-
- return NM_CONFIG_GET_PRIVATE (config)->config_main_file;
-}
-
-const char *
-nm_config_get_config_description (NMConfig *config)
-{
- g_return_val_if_fail (config != NULL, NULL);
-
- return NM_CONFIG_GET_PRIVATE (config)->config_description;
-}
-
const char **
nm_config_get_plugins (NMConfig *config)
{
@@ -729,14 +711,14 @@ nm_config_reload (NMConfig *self)
&config_main_file,
&config_description,
&error);
- g_free (config_main_file);
- g_free (config_description);
if (!keyfile) {
nm_log_err (LOGD_CORE, "Failed to reload the configuration: %s", error->message);
g_clear_error (&error);
return;
}
- new_data = nm_config_data_new (keyfile);
+ new_data = nm_config_data_new (config_main_file, config_description, keyfile);
+ g_free (config_main_file);
+ g_free (config_description);
g_key_file_free (keyfile);
@@ -753,12 +735,33 @@ nm_config_reload (NMConfig *self)
g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONNECTIVITY, NULL);
}
+ if ( g_strcmp0 (nm_config_data_get_config_main_file (old_data), nm_config_data_get_config_main_file (new_data)) != 0
+ || g_strcmp0 (nm_config_data_get_config_description (old_data), nm_config_data_get_config_description (new_data)) != 0) {
+ nm_log_dbg (LOGD_CORE, "config: reload: change '" NM_CONFIG_CHANGES_CONFIG_FILES "'");
+ g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONFIG_FILES, NULL);
+ }
+
if (!g_hash_table_size (changes)) {
g_hash_table_destroy (changes);
g_object_unref (new_data);
return;
}
+ if (nm_logging_enabled (LOGL_INFO, LOGD_CORE)) {
+ GString *str = g_string_new (NULL);
+ GHashTableIter iter;
+ const char *key;
+
+ g_hash_table_iter_init (&iter, changes);
+ while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL)) {
+ if (str->len)
+ g_string_append (str, ",");
+ g_string_append (str, key);
+ }
+ nm_log_info (LOGD_CORE, "config: update %s (%s)", nm_config_data_get_config_description (new_data), str->str);
+ g_string_free (str, TRUE);
+ }
+
priv->config_data = new_data;
g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0, new_data, changes, old_data);
g_object_unref (old_data);
@@ -793,6 +796,8 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
NMConfigPrivate *priv = NULL;
NMConfig *self;
GKeyFile *keyfile;
+ char *config_main_file = NULL;
+ char *config_description = NULL;
self = NM_CONFIG (g_object_new (NM_TYPE_CONFIG,
NM_CONFIG_CMD_LINE_OPTIONS, cli,
@@ -806,8 +811,8 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
keyfile = read_entire_config (&priv->cli,
priv->config_dir,
- &priv->config_main_file,
- &priv->config_description,
+ &config_main_file,
+ &config_description,
error);
if (!keyfile) {
g_object_unref (self);
@@ -844,7 +849,7 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
priv->configure_and_quit = _get_bool_value (priv->keyfile, "main", "configure-and-quit", FALSE);
- priv->config_data_orig = nm_config_data_new (priv->keyfile);
+ priv->config_data_orig = nm_config_data_new (config_main_file, config_description, priv->keyfile);
/* Initialize mutable members. */
@@ -853,6 +858,8 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
priv->no_auto_default = g_strdupv (priv->no_auto_default_orig);
merge_no_auto_default_state (self);
+ g_free (config_main_file);
+ g_free (config_description);
return self;
}
@@ -871,9 +878,7 @@ finalize (GObject *gobject)
{
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (gobject);
- g_free (priv->config_main_file);
g_free (priv->config_dir);
- g_free (priv->config_description);
g_free (priv->no_auto_default_file);
g_clear_pointer (&priv->keyfile, g_key_file_unref);
g_strfreev (priv->plugins);
diff --git a/src/nm-config.h b/src/nm-config.h
index f4994a1f52..a961199499 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -43,6 +43,7 @@ G_BEGIN_DECLS
/* Signals */
#define NM_CONFIG_SIGNAL_CONFIG_CHANGED "config-changed"
+#define NM_CONFIG_CHANGES_CONFIG_FILES "config-files"
#define NM_CONFIG_CHANGES_CONNECTIVITY "connectivity"
typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions;
@@ -64,8 +65,6 @@ NMConfig *nm_config_get (void);
NMConfigData *nm_config_get_data (NMConfig *config);
NMConfigData *nm_config_get_data_orig (NMConfig *config);
-const char *nm_config_get_config_main_file (NMConfig *config);
-const char *nm_config_get_config_description (NMConfig *config);
const char **nm_config_get_plugins (NMConfig *config);
gboolean nm_config_get_monitor_connection_files (NMConfig *config);
gboolean nm_config_get_auth_polkit (NMConfig *config);
diff --git a/src/settings/plugins/example/plugin.c b/src/settings/plugins/example/plugin.c
index b93b1dfb46..0bcb38fcf3 100644
--- a/src/settings/plugins/example/plugin.c
+++ b/src/settings/plugins/example/plugin.c
@@ -847,7 +847,7 @@ nm_system_config_factory (void)
priv = SC_PLUGIN_EXAMPLE_GET_PRIVATE (singleton);
/* Cache the config file path */
- priv->conf_file = nm_config_get_config_main_file (nm_config_get ());
+ priv->conf_file = nm_config_data_get_config_main_file (nm_config_get_data (nm_config_get ()));
} else {
/* This function should never be called twice */
g_assert_not_reached ();
diff --git a/src/settings/plugins/ifupdown/plugin.c b/src/settings/plugins/ifupdown/plugin.c
index 61b9dcef07..fbd3dd2379 100644
--- a/src/settings/plugins/ifupdown/plugin.c
+++ b/src/settings/plugins/ifupdown/plugin.c
@@ -461,7 +461,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
&error);
if (error) {
nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: %s",
- nm_config_get_config_main_file (nm_config_get ()),
+ nm_config_data_get_config_main_file (nm_config_get_data (nm_config_get ())),
error->message);
} else {
gboolean manage_well_known;
diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c
index 869af6a1c5..edaa7d4566 100644
--- a/src/settings/plugins/keyfile/plugin.c
+++ b/src/settings/plugins/keyfile/plugin.c
@@ -843,7 +843,7 @@ nm_settings_keyfile_plugin_new (void)
singleton = SC_PLUGIN_KEYFILE (g_object_new (SC_TYPE_PLUGIN_KEYFILE, NULL));
priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (singleton);
- priv->conf_file = nm_config_get_config_main_file (nm_config_get ());
+ priv->conf_file = nm_config_data_get_config_main_file (nm_config_get_data (nm_config_get ()));
/* plugin_set_hostname() has to be called *after* priv->conf_file is set */
priv->hostname = plugin_get_hostname (singleton);
diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c
index a6f921c750..d63fff4613 100644
--- a/src/tests/config/test-config.c
+++ b/src/tests/config/test-config.c
@@ -93,7 +93,7 @@ test_config_simple (void)
config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "/no/such/dir", NULL);
- g_assert_cmpstr (nm_config_get_config_main_file (config), ==, SRCDIR "/NetworkManager.conf");
+ g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf");
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 100);
@@ -152,7 +152,7 @@ test_config_override (void)
"--connectivity-interval", "12",
NULL);
- g_assert_cmpstr (nm_config_get_config_main_file (config), ==, SRCDIR "/NetworkManager.conf");
+ g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf");
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 12);
@@ -233,7 +233,7 @@ test_config_confdir (void)
config = setup_config (NULL, SRCDIR "/NetworkManager.conf", SRCDIR "/conf.d", NULL);
- g_assert_cmpstr (nm_config_get_config_main_file (config), ==, SRCDIR "/NetworkManager.conf");
+ g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf");
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhcpcd");
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
g_assert_cmpstr (nm_config_get_log_domains (config), ==, "PLATFORM,DNS,WIFI");