From 124b905f97aeb6a82c9bb03076fa58464c7e8ead Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 22 Nov 2017 17:03:22 +0100 Subject: [PATCH] policy: move setting autoconnect retries to a separate function Note that for the if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NO_SECRETS) case we no longer do the if (nm_settings_connection_autoconnect_retries_get (connection) == 0) check. But that is fine, because we only skip schedling a reset_connections_retries() action. But note, that that previously we also would never actually scheudle a new timeout, because - either nm_settings_connection_autoconnect_retries_get (connection) != 0 - or the retries count was zero, in which case we already have a reset_connections_retries action pending (from the time when we set it to zero. So, there is no change in behavior at all except dropping of a redundant logging line. --- src/nm-policy.c | 36 ++++++++++++++++++--------- src/settings/nm-settings-connection.c | 4 +-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index 121ef877dd..1d90844ee4 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1529,6 +1529,29 @@ reset_connections_retries (gpointer user_data) return FALSE; } +static void +_connection_autoconnect_retries_set (NMPolicy *self, + NMSettingsConnection *connection, + int tries) +{ + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); + + nm_assert (NM_IS_SETTINGS_CONNECTION (connection)); + nm_assert (tries >= 0); + + nm_settings_connection_autoconnect_retries_set (connection, tries); + + if (tries == 0) { + /* Schedule a handler to reset retries count */ + if (!priv->reset_retries_id) { + gint32 retry_time = nm_settings_connection_autoconnect_retries_blocked_until (connection); + + g_warn_if_fail (retry_time != 0); + priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self); + } + } +} + static void activate_slave_connections (NMPolicy *self, NMDevice *device) { @@ -1723,24 +1746,13 @@ device_state_changed (NMDevice *device, if (tries > 0) { _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left", nm_settings_connection_get_id (connection), tries); - nm_settings_connection_autoconnect_retries_set (connection, --tries); + _connection_autoconnect_retries_set (self, connection, tries - 1); } else { _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; infinite tries left", nm_settings_connection_get_id (connection)); } } - if (nm_settings_connection_autoconnect_retries_get (connection) == 0) { - _LOGI (LOGD_DEVICE, "disabling autoconnect for connection '%s'.", - nm_settings_connection_get_id (connection)); - /* Schedule a handler to reset retries count */ - if (!priv->reset_retries_id) { - gint32 retry_time = nm_settings_connection_autoconnect_retries_blocked_until (connection); - - g_warn_if_fail (retry_time != 0); - priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self); - } - } nm_connection_clear_secrets (NM_CONNECTION (connection)); } break; diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index ec937f989b..3babbf9b76 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -2577,8 +2577,8 @@ nm_settings_connection_autoconnect_retries_set (NMSettingsConnection *self, else { /* XXX: the blocked time must be identical for all connections, otherwise * the tracking of resetting the retry count in NMPolicy needs adjustment - * (as it would need to re-evaluate the next-timeout everytime a - * connection gets blocked). */ + * in _connection_autoconnect_retries_set() (as it would need to re-evaluate + * the next-timeout everytime a connection gets blocked). */ priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER; } }