diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-07 18:42:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-07 18:52:12 +0200 |
commit | d0836be0ebb3faa1aaf8f4ac0ec7b52fed011cc2 (patch) | |
tree | 1a5e746aa9e7e2beb708dffe81233975ebd249c1 | |
parent | e3a30665d72e82cc8f9b67becfdd85c000235824 (diff) | |
download | NetworkManager-d0836be0ebb3faa1aaf8f4ac0ec7b52fed011cc2.tar.gz |
core: rename nm_config_run_state* to nm_config_state*
After all, this state is stored persistently to /var/lib/NetworkManager,
and not to volatile storage in /var/run. Hence the name is better.
It's also shorter, so rename it.
The commit is mostly trivial, including update of code comments
and logging messages.
Fixes: 1b43c880ba43260fe551b0ac923826f16737484f
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/nm-config.c | 144 | ||||
-rw-r--r-- | src/nm-config.h | 24 | ||||
-rw-r--r-- | src/nm-manager.c | 23 | ||||
-rw-r--r-- | src/tests/config/test-config.c | 16 |
5 files changed, 108 insertions, 105 deletions
diff --git a/src/main.c b/src/main.c index 41f4eda275..b60ec84eb3 100644 --- a/src/main.c +++ b/src/main.c @@ -335,8 +335,8 @@ main (int argc, char *argv[]) nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config))); nm_config_data_log (nm_config_get_data (config), "CONFIG: ", " ", NULL); - /* the first access to RunState causes the file to be read (and possibly print a warning) */ - nm_config_run_state_get (config); + /* the first access to State causes the file to be read (and possibly print a warning) */ + nm_config_state_get (config); nm_log_dbg (LOGD_CORE, "WEXT support is %s", #if HAVE_WEXT @@ -400,7 +400,7 @@ done: nm_manager_stop (nm_manager_get ()); - nm_config_run_state_set (config, TRUE, TRUE); + nm_config_state_set (config, TRUE, TRUE); if (global_opt.pidfile && wrote_pidfile) unlink (global_opt.pidfile); diff --git a/src/nm-config.c b/src/nm-config.c index b9f5e6a816..669812c40a 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -73,8 +73,8 @@ struct NMConfigCmdLineOptions { }; typedef struct { - NMConfigRunState p; -} RunState; + NMConfigState p; +} State; typedef struct { NMConfigCmdLineOptions cli; @@ -101,15 +101,18 @@ typedef struct { char **atomic_section_prefixes; - /* The run-state. This is actually a mutable data member and it makes sense: - * The regular config is immutable (NMConfigData) which allows atomic updates - * which is handy during reload. Also, we invoke a config-changed signal when - * the config changes. + /* The state. This is actually a mutable data member and it makes sense: + * The regular config is immutable (NMConfigData) and can old be swapped + * as a whole (via nm_config_set_values() or during reload). Thus, it can + * be changed, but it is still immutable and is swapped atomically as a + * whole. Also, we emit a config-changed signal on that occasion. * - * For run-state, there are no events. You can query it and set it. - * It only gets read once at startup, and later is cached and only written - * out to disk. Hence, no need for the immutable dance here. */ - RunState *run_state; + * For state, there are no events. You can query it and set it. + * It only gets read *once* at startup, and later is cached and only + * written out to disk. Hence, no need for the immutable dance here + * because the state changes only on explicit actions from the daemon + * itself. */ + State *state; } NMConfigPrivate; enum { @@ -1678,76 +1681,75 @@ nm_config_set_values (NMConfig *self, } /****************************************************************************** - * RunState + * State ******************************************************************************/ static const char * -run_state_get_filename (const NMConfigCmdLineOptions *cli) +state_get_filename (const NMConfigCmdLineOptions *cli) { /* For an empty filename, we assume the user wants to disable - * persistent run-state. NMConfig will not try to read it nor - * write it out. */ + * state. NMConfig will not try to read it nor write it out. */ if (!cli->state_file) return DEFAULT_STATE_FILE; return cli->state_file[0] ? cli->state_file : NULL; } -static RunState * -run_state_new (void) +static State * +state_new (void) { - RunState *run_state; + State *state; - run_state = g_slice_new0 (RunState); - run_state->p.net_enabled = TRUE; - run_state->p.wifi_enabled = TRUE; - run_state->p.wwan_enabled = TRUE; + state = g_slice_new0 (State); + state->p.net_enabled = TRUE; + state->p.wifi_enabled = TRUE; + state->p.wwan_enabled = TRUE; - return run_state; + return state; } static void -run_state_free (RunState *run_state) +state_free (State *state) { - if (!run_state) + if (!state) return; - g_slice_free (RunState, run_state); + g_slice_free (State, state); } -static RunState * -run_state_new_from_file (const char *filename) +static State * +state_new_from_file (const char *filename) { GKeyFile *keyfile; gs_free_error GError *error = NULL; - RunState *run_state; + State *state; - run_state = run_state_new (); + state = state_new (); if (!filename) - return run_state; + return state; keyfile = g_key_file_new (); g_key_file_set_list_separator (keyfile, ','); if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error)) { if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) - _LOGD ("run-state: missing state file \"%s\": %s", filename, error->message); + _LOGD ("state: missing state file \"%s\": %s", filename, error->message); else - _LOGW ("run-state: error reading state file \"%s\": %s", filename, error->message); + _LOGW ("state: error reading state file \"%s\": %s", filename, error->message); goto out; } - _LOGD ("run-state: successfully read state file \"%s\"", filename); + _LOGD ("state: successfully read state file \"%s\"", filename); - run_state->p.net_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "NetworkingEnabled", run_state->p.net_enabled); - run_state->p.wifi_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "WirelessEnabled", run_state->p.wifi_enabled); - run_state->p.wwan_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "WWANEnabled", run_state->p.wwan_enabled); + state->p.net_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "NetworkingEnabled", state->p.net_enabled); + state->p.wifi_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "WirelessEnabled", state->p.wifi_enabled); + state->p.wwan_enabled = nm_config_keyfile_get_boolean (keyfile, "main", "WWANEnabled", state->p.wwan_enabled); out: g_key_file_unref (keyfile); - return run_state; + return state; } -const NMConfigRunState * -nm_config_run_state_get (NMConfig *self) +const NMConfigState * +nm_config_state_get (NMConfig *self) { NMConfigPrivate *priv; @@ -1755,29 +1757,31 @@ nm_config_run_state_get (NMConfig *self) priv = NM_CONFIG_GET_PRIVATE (self); - if (G_UNLIKELY (!priv->run_state)) { - /* read the runstate from file lazy on first access. The reason is that - * we want to log a failure to read the file via nm-logging. But during - * construction of NMConfig, nm-logging is not yet configured. + if (G_UNLIKELY (!priv->state)) { + /* read the state from file lazy on first access. The reason is that + * we want to log a failure to read the file via nm-logging. + * + * So we cannot read the state during construction of NMConfig, + * because at that time nm-logging is not yet configured. */ - priv->run_state = run_state_new_from_file (run_state_get_filename (&priv->cli)); + priv->state = state_new_from_file (state_get_filename (&priv->cli)); } - return &priv->run_state->p; + return &priv->state->p; } static void -run_state_write (NMConfig *self) +state_write (NMConfig *self) { NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (self); const char *filename; GString *str; GError *error = NULL; - filename = run_state_get_filename (&priv->cli); + filename = state_get_filename (&priv->cli); if (!filename) { - priv->run_state->p.dirty = FALSE; + priv->state->p.dirty = FALSE; return; } @@ -1786,31 +1790,31 @@ run_state_write (NMConfig *self) /* Let's construct the keyfile data by hand. */ g_string_append (str, "[main]\n"); - g_string_append_printf (str, "NetworkingEnabled=%s\n", priv->run_state->p.net_enabled ? "true" : "false"); - g_string_append_printf (str, "WirelessEnabled=%s\n", priv->run_state->p.wifi_enabled ? "true" : "false"); - g_string_append_printf (str, "WWANEnabled=%s\n", priv->run_state->p.wwan_enabled ? "true" : "false"); + g_string_append_printf (str, "NetworkingEnabled=%s\n", priv->state->p.net_enabled ? "true" : "false"); + g_string_append_printf (str, "WirelessEnabled=%s\n", priv->state->p.wifi_enabled ? "true" : "false"); + g_string_append_printf (str, "WWANEnabled=%s\n", priv->state->p.wwan_enabled ? "true" : "false"); if (!g_file_set_contents (filename, str->str, str->len, &error)) { - _LOGD ("run-state: error writing state file \"%s\": %s", filename, error->message); + _LOGD ("state: error writing state file \"%s\": %s", filename, error->message); g_clear_error (&error); /* we leave the state dirty. That potentally means, that we try to * write the file over and over again, although it isn't possible. */ - priv->run_state->p.dirty = TRUE; + priv->state->p.dirty = TRUE; } else - priv->run_state->p.dirty = FALSE; + priv->state->p.dirty = FALSE; - _LOGT ("run-state: success writing state file \"%s\"", filename); + _LOGT ("state: success writing state file \"%s\"", filename); g_string_free (str, TRUE); } void -_nm_config_run_state_set (NMConfig *self, - gboolean allow_persist, - gboolean force_persist, - ...) +_nm_config_state_set (NMConfig *self, + gboolean allow_persist, + gboolean force_persist, + ...) { NMConfigPrivate *priv; va_list ap; @@ -1827,18 +1831,18 @@ _nm_config_run_state_set (NMConfig *self, * Larger would be a problem, also, because we want that "0" is a valid sentinel. */ G_STATIC_ASSERT_EXPR (sizeof (NMConfigRunStatePropertyType) <= sizeof (int)); - while ((property_type = va_arg (ap, int)) != NM_CONFIG_RUN_STATE_PROPERTY_NONE) { + while ((property_type = va_arg (ap, int)) != NM_CONFIG_STATE_PROPERTY_NONE) { bool *p_bool, v_bool; switch (property_type) { - case NM_CONFIG_RUN_STATE_PROPERTY_NETWORKING_ENABLED: - p_bool = &priv->run_state->p.net_enabled; + case NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED: + p_bool = &priv->state->p.net_enabled; goto handle_p_bool; - case NM_CONFIG_RUN_STATE_PROPERTY_WIFI_ENABLED: - p_bool = &priv->run_state->p.wifi_enabled; + case NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED: + p_bool = &priv->state->p.wifi_enabled; goto handle_p_bool; - case NM_CONFIG_RUN_STATE_PROPERTY_WWAN_ENABLED: - p_bool = &priv->run_state->p.wwan_enabled; + case NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED: + p_bool = &priv->state->p.wwan_enabled; goto handle_p_bool; default: break; @@ -1851,14 +1855,14 @@ handle_p_bool: if (*p_bool == v_bool) continue; *p_bool = v_bool; - priv->run_state->p.dirty = TRUE; + priv->state->p.dirty = TRUE; } va_end (ap); if ( allow_persist - && (force_persist || priv->run_state->p.dirty)) - run_state_write (self); + && (force_persist || priv->state->p.dirty)) + state_write (self); } /*****************************************************************************/ @@ -2134,7 +2138,7 @@ finalize (GObject *gobject) { NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (gobject); - run_state_free (priv->run_state); + state_free (priv->state); g_free (priv->config_dir); g_free (priv->system_config_dir); diff --git a/src/nm-config.h b/src/nm-config.h index 36007fa895..82e3a00481 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -84,12 +84,12 @@ G_BEGIN_DECLS typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions; typedef enum { - NM_CONFIG_RUN_STATE_PROPERTY_NONE, + NM_CONFIG_STATE_PROPERTY_NONE, /* 1 set-argument: (gboolean enabled) */ - NM_CONFIG_RUN_STATE_PROPERTY_NETWORKING_ENABLED, - NM_CONFIG_RUN_STATE_PROPERTY_WIFI_ENABLED, - NM_CONFIG_RUN_STATE_PROPERTY_WWAN_ENABLED, + NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED, + NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED, + NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED, } NMConfigRunStatePropertyType; typedef struct { @@ -99,7 +99,7 @@ typedef struct { /* Whether the runstate is modified and not saved to disk. */ bool dirty; -} NMConfigRunState; +} NMConfigState; struct _NMConfig { GObject parent; @@ -149,14 +149,14 @@ NMConfig *nm_config_new (const NMConfigCmdLineOptions *cli, char **atomic_sectio NMConfig *nm_config_setup (const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error); void nm_config_reload (NMConfig *config, int signal); -const NMConfigRunState *nm_config_run_state_get (NMConfig *config); +const NMConfigState *nm_config_state_get (NMConfig *config); -void _nm_config_run_state_set (NMConfig *config, - gboolean allow_persist, - gboolean force_persist, - ...); -#define nm_config_run_state_set(config, allow_persist, force_persist, ...) \ - _nm_config_run_state_set (config, allow_persist, force_persist, ##__VA_ARGS__, 0) +void _nm_config_state_set (NMConfig *config, + gboolean allow_persist, + gboolean force_persist, + ...); +#define nm_config_state_set(config, allow_persist, force_persist, ...) \ + _nm_config_state_set (config, allow_persist, force_persist, ##__VA_ARGS__, 0) gint nm_config_parse_boolean (const char *str, gint default_value); diff --git a/src/nm-manager.c b/src/nm-manager.c index bf5c6a190b..e0ef86a97a 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -4011,9 +4011,8 @@ _internal_enable (NMManager *self, gboolean enable) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - /* Update "NetworkingEnabled" key in state file */ - nm_config_run_state_set (priv->config, TRUE, FALSE, - NM_CONFIG_RUN_STATE_PROPERTY_NETWORKING_ENABLED, enable); + nm_config_state_set (priv->config, TRUE, FALSE, + NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED, enable); _LOGI (LOGD_SUSPEND, "%s requested (sleeping: %s enabled: %s)", enable ? "enable" : "disable", @@ -4964,8 +4963,8 @@ manager_radio_user_toggled (NMManager *self, } /* Update enabled key in state file */ - nm_config_run_state_set (priv->config, TRUE, FALSE, - rstate->key, enabled); + nm_config_state_set (priv->config, TRUE, FALSE, + rstate->key, enabled); /* When the user toggles the radio, their request should override any * daemon (like ModemManager) enabled state that can be changed. For WWAN @@ -5064,7 +5063,7 @@ constructed (GObject *object) NMManager *self = NM_MANAGER (object); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMConfigData *config_data; - const NMConfigRunState *run_state; + const NMConfigState *state; G_OBJECT_CLASS (nm_manager_parent_class)->constructed (object); @@ -5107,12 +5106,12 @@ constructed (GObject *object) g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_STATE, G_CALLBACK (connectivity_changed), self); - run_state = nm_config_run_state_get (priv->config); + state = nm_config_state_get (priv->config); - priv->net_enabled = run_state->net_enabled; + priv->net_enabled = state->net_enabled; - priv->radio_states[RFKILL_TYPE_WLAN].user_enabled = run_state->wifi_enabled; - priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = run_state->wwan_enabled; + priv->radio_states[RFKILL_TYPE_WLAN].user_enabled = state->wifi_enabled; + priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = state->wwan_enabled; priv->rfkill_mgr = nm_rfkill_manager_new (); g_signal_connect (priv->rfkill_mgr, @@ -5140,14 +5139,14 @@ nm_manager_init (NMManager *self) memset (priv->radio_states, 0, sizeof (priv->radio_states)); priv->radio_states[RFKILL_TYPE_WLAN].user_enabled = TRUE; - priv->radio_states[RFKILL_TYPE_WLAN].key = NM_CONFIG_RUN_STATE_PROPERTY_WIFI_ENABLED; + priv->radio_states[RFKILL_TYPE_WLAN].key = NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED; priv->radio_states[RFKILL_TYPE_WLAN].prop = NM_MANAGER_WIRELESS_ENABLED; priv->radio_states[RFKILL_TYPE_WLAN].hw_prop = NM_MANAGER_WIRELESS_HARDWARE_ENABLED; priv->radio_states[RFKILL_TYPE_WLAN].desc = "WiFi"; priv->radio_states[RFKILL_TYPE_WLAN].rtype = RFKILL_TYPE_WLAN; priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = TRUE; - priv->radio_states[RFKILL_TYPE_WWAN].key = NM_CONFIG_RUN_STATE_PROPERTY_WWAN_ENABLED; + priv->radio_states[RFKILL_TYPE_WWAN].key = NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED; priv->radio_states[RFKILL_TYPE_WWAN].prop = NM_MANAGER_WWAN_ENABLED; priv->radio_states[RFKILL_TYPE_WWAN].hw_prop = NM_MANAGER_WWAN_HARDWARE_ENABLED; priv->radio_states[RFKILL_TYPE_WWAN].desc = "WWAN"; diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c index 08f33f813f..9d39c69a80 100644 --- a/src/tests/config/test-config.c +++ b/src/tests/config/test-config.c @@ -934,7 +934,7 @@ static void test_config_state_file (void) { NMConfig *config; - const NMConfigRunState *state; + const NMConfigState *state; gs_unref_object GFile *src = NULL, *dst = NULL; const char *tmp_file = BUILDDIR "/tmp.state"; GError *error = NULL; @@ -952,19 +952,19 @@ test_config_state_file (void) "--state-file", tmp_file, NULL); g_assert (config); - state = nm_config_run_state_get (config); + state = nm_config_state_get (config); g_assert (state); g_assert_cmpint (state->net_enabled, ==, TRUE); g_assert_cmpint (state->wifi_enabled, ==, TRUE); g_assert_cmpint (state->wwan_enabled, ==, TRUE); - nm_config_run_state_set (config, TRUE, TRUE, - NM_CONFIG_RUN_STATE_PROPERTY_NETWORKING_ENABLED, FALSE, - NM_CONFIG_RUN_STATE_PROPERTY_WIFI_ENABLED, TRUE, - NM_CONFIG_RUN_STATE_PROPERTY_WWAN_ENABLED, FALSE); + nm_config_state_set (config, TRUE, TRUE, + NM_CONFIG_STATE_PROPERTY_NETWORKING_ENABLED, FALSE, + NM_CONFIG_STATE_PROPERTY_WIFI_ENABLED, TRUE, + NM_CONFIG_STATE_PROPERTY_WWAN_ENABLED, FALSE); - state = nm_config_run_state_get (config); + state = nm_config_state_get (config); g_assert (state); g_assert_cmpint (state->net_enabled, ==, FALSE); @@ -978,7 +978,7 @@ test_config_state_file (void) "--state-file", tmp_file, NULL); g_assert (config); - state = nm_config_run_state_get (config); + state = nm_config_state_get (config); g_assert (state); g_assert_cmpint (state->net_enabled, ==, FALSE); |