Commit 447dc874 authored by Thomas Haller's avatar Thomas Haller
Browse files

config: remove nm_config_data_get_value_cached()

It has almost no callers, and it is a bit of a strange API. Let's
not cache the last accessed value inside NMConfigData. Instead, free
it right after use. It was not reused anyway, it only hangs around
as convenience for the caller.
parent 262159be
...@@ -357,11 +357,15 @@ main (int argc, char *argv[]) ...@@ -357,11 +357,15 @@ main (int argc, char *argv[])
/* Set up unix signal handling - before creating threads, but after daemonizing! */ /* Set up unix signal handling - before creating threads, but after daemonizing! */
nm_main_utils_setup_signals (main_loop); nm_main_utils_setup_signals (main_loop);
nm_logging_syslog_openlog (nm_config_data_get_value_cached (NM_CONFIG_GET_DATA_ORIG, {
NM_CONFIG_KEYFILE_GROUP_LOGGING, gs_free char *v = NULL;
NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY), v = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
nm_config_get_is_debug (config)); NM_CONFIG_KEYFILE_GROUP_LOGGING,
NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
nm_logging_syslog_openlog (v, nm_config_get_is_debug (config));
}
nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting... (%s)", nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting... (%s)",
nm_config_get_first_start (config) ? "for the first time" : "after a restart"); nm_config_get_first_start (config) ? "for the first time" : "after a restart");
......
...@@ -108,9 +108,6 @@ typedef struct { ...@@ -108,9 +108,6 @@ typedef struct {
char *rc_manager; char *rc_manager;
NMGlobalDnsConfig *global_dns; NMGlobalDnsConfig *global_dns;
/* mutable field */
char *value_cached;
} NMConfigDataPrivate; } NMConfigDataPrivate;
struct _NMConfigData { struct _NMConfigData {
...@@ -171,22 +168,6 @@ nm_config_data_get_value (const NMConfigData *self, const char *group, const cha ...@@ -171,22 +168,6 @@ nm_config_data_get_value (const NMConfigData *self, const char *group, const cha
return nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, flags); return nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, flags);
} }
const char *nm_config_data_get_value_cached (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
{
const NMConfigDataPrivate *priv;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
g_return_val_if_fail (group && *group, NULL);
g_return_val_if_fail (key && *key, NULL);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
/* we modify @value_cached. In C++ jargon, the field is mutable. */
g_free (((NMConfigDataPrivate *) priv)->value_cached);
((NMConfigDataPrivate *) priv)->value_cached = nm_config_keyfile_get_value (priv->keyfile, group, key, flags);
return priv->value_cached;
}
gboolean gboolean
nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags) nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
{ {
...@@ -1658,8 +1639,6 @@ finalize (GObject *gobject) ...@@ -1658,8 +1639,6 @@ finalize (GObject *gobject)
g_key_file_unref (priv->keyfile_intern); g_key_file_unref (priv->keyfile_intern);
G_OBJECT_CLASS (nm_config_data_parent_class)->finalize (gobject); G_OBJECT_CLASS (nm_config_data_parent_class)->finalize (gobject);
g_free (priv->value_cached);
} }
static void static void
......
...@@ -156,7 +156,6 @@ const char *nm_config_data_get_config_description (const NMConfigData *config_da ...@@ -156,7 +156,6 @@ const char *nm_config_data_get_config_description (const NMConfigData *config_da
gboolean nm_config_data_has_group (const NMConfigData *self, const char *group); gboolean nm_config_data_has_group (const NMConfigData *self, const char *group);
gboolean nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags); gboolean nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags);
char *nm_config_data_get_value (const NMConfigData *config_data, const char *group, const char *key, NMConfigGetValueFlags flags); char *nm_config_data_get_value (const NMConfigData *config_data, const char *group, const char *key, NMConfigGetValueFlags flags);
const char *nm_config_data_get_value_cached (const NMConfigData *config_data, const char *group, const char *key, NMConfigGetValueFlags flags);
gint nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, const char *key, gint default_value); gint nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, const char *key, gint default_value);
gint64 nm_config_data_get_value_int64 (const NMConfigData *self, const char *group, const char *key, guint base, gint64 min, gint64 max, gint64 fallback); gint64 nm_config_data_get_value_int64 (const NMConfigData *self, const char *group, const char *key, guint base, gint64 min, gint64 max, gint64 fallback);
......
...@@ -2548,13 +2548,13 @@ platform_query_devices (NMManager *self) ...@@ -2548,13 +2548,13 @@ platform_query_devices (NMManager *self)
gs_unref_ptrarray GPtrArray *links = NULL; gs_unref_ptrarray GPtrArray *links = NULL;
int i; int i;
gboolean guess_assume; gboolean guess_assume;
const char *order; gs_free char *order = NULL;
guess_assume = nm_config_get_first_start (nm_config_get ()); guess_assume = nm_config_get_first_start (nm_config_get ());
order = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA, order = nm_config_data_get_value (NM_CONFIG_GET_DATA,
NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER, NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER,
NM_CONFIG_GET_VALUE_STRIP); NM_CONFIG_GET_VALUE_STRIP);
links = nm_platform_link_get_all (priv->platform, !nm_streq0 (order, "index")); links = nm_platform_link_get_all (priv->platform, !nm_streq0 (order, "index"));
if (!links) if (!links)
return; return;
...@@ -3139,14 +3139,15 @@ autoconnect_slaves (NMManager *self, ...@@ -3139,14 +3139,15 @@ autoconnect_slaves (NMManager *self,
if (should_connect_slaves (NM_CONNECTION (master_connection), master_device)) { if (should_connect_slaves (NM_CONNECTION (master_connection), master_device)) {
gs_free SlaveConnectionInfo *slaves = NULL; gs_free SlaveConnectionInfo *slaves = NULL;
guint i, n_slaves = 0; guint i, n_slaves = 0;
const char *value;
slaves = find_slaves (self, master_connection, master_device, &n_slaves); slaves = find_slaves (self, master_connection, master_device, &n_slaves);
if (n_slaves > 1) { if (n_slaves > 1) {
value = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA, gs_free char *value = NULL;
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER, value = nm_config_data_get_value (NM_CONFIG_GET_DATA,
NM_CONFIG_GET_VALUE_STRIP); NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_SLAVES_ORDER,
NM_CONFIG_GET_VALUE_STRIP);
g_qsort_with_data (slaves, n_slaves, sizeof (slaves[0]), g_qsort_with_data (slaves, n_slaves, sizeof (slaves[0]),
compare_slaves, compare_slaves,
GINT_TO_POINTER (!nm_streq0 (value, "index"))); GINT_TO_POINTER (!nm_streq0 (value, "index")));
......
...@@ -2547,7 +2547,6 @@ nm_settings_connection_autoconnect_retries_get (NMSettingsConnection *self) ...@@ -2547,7 +2547,6 @@ nm_settings_connection_autoconnect_retries_get (NMSettingsConnection *self)
if (G_UNLIKELY (priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET)) { if (G_UNLIKELY (priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET)) {
NMSettingConnection *s_con; NMSettingConnection *s_con;
int retries = -1; int retries = -1;
const char *value;
s_con = nm_connection_get_setting_connection ((NMConnection *) self); s_con = nm_connection_get_setting_connection ((NMConnection *) self);
if (s_con) if (s_con)
...@@ -2555,14 +2554,11 @@ nm_settings_connection_autoconnect_retries_get (NMSettingsConnection *self) ...@@ -2555,14 +2554,11 @@ nm_settings_connection_autoconnect_retries_get (NMSettingsConnection *self)
/* -1 means 'default' */ /* -1 means 'default' */
if (retries == -1) { if (retries == -1) {
value = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA, retries = nm_config_data_get_value_int64 (NM_CONFIG_GET_DATA,
NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_GROUP_MAIN,
"autoconnect-retries-default", "autoconnect-retries-default",
NM_CONFIG_GET_VALUE_STRIP); 10, 0, G_MAXINT32,
AUTOCONNECT_RETRIES_DEFAULT);
retries = _nm_utils_ascii_str_to_int64 (value,
10, 0, G_MAXINT32,
AUTOCONNECT_RETRIES_DEFAULT);
} }
/* 0 means 'forever', which is translated to a retry count of -1 */ /* 0 means 'forever', which is translated to a retry count of -1 */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment