mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 01:10:08 +01:00
config: move main_file and description to NMConfigData
Every reload might change the main_file and description.
Move those properties to NMConfigData.
(cherry picked from commit 56f5fba723)
This commit is contained in:
parent
30a4786468
commit
0ca82739d5
9 changed files with 104 additions and 37 deletions
|
|
@ -424,7 +424,7 @@ main (int argc, char *argv[])
|
|||
*/
|
||||
dbus_glib_global_set_disable_legacy_property_access ();
|
||||
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -45,6 +50,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)
|
||||
{
|
||||
|
|
@ -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,
|
||||
|
|
@ -177,6 +217,22 @@ nm_config_data_class_init (NMConfigDataClass *config_class)
|
|||
object_class->get_property = get_property;
|
||||
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, "", "",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -731,14 +713,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);
|
||||
|
||||
|
||||
|
|
@ -755,12 +737,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);
|
||||
|
|
@ -795,6 +798,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,
|
||||
|
|
@ -808,8 +813,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);
|
||||
|
|
@ -846,7 +851,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. */
|
||||
|
||||
|
|
@ -855,6 +860,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;
|
||||
}
|
||||
|
||||
|
|
@ -873,9 +880,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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,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);
|
||||
|
|
@ -156,7 +156,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);
|
||||
|
|
@ -237,7 +237,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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue