diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-02 18:50:19 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-08 12:35:10 +0100 |
commit | bb0536fc0052a4b50794fdfad1cfd1936da80009 (patch) | |
tree | 3191d31773f5b0de27a74157b7a7a0a4e8d25c7e /src | |
parent | baa0d95c95c48ed1b46464e1da4e369e5cf0951a (diff) | |
download | NetworkManager-bb0536fc0052a4b50794fdfad1cfd1936da80009.tar.gz |
policy: refactor auto_activate_device() to return early
(cherry picked from commit a7ef46eaaad6e7eabc3f5ee9d6bde69321c112bd)
Diffstat (limited to 'src')
-rw-r--r-- | src/nm-policy.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index 95bf5a03e7..0eb5db9993 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1213,6 +1213,9 @@ auto_activate_device (NMPolicy *self, gs_free char *specific_object = NULL; gs_free NMSettingsConnection **connections = NULL; guint i, len; + GError *error = NULL; + NMAuthSubject *subject; + NMActiveConnection *ac; nm_assert (NM_IS_POLICY (self)); nm_assert (NM_IS_DEVICE (device)); @@ -1260,46 +1263,43 @@ auto_activate_device (NMPolicy *self, } } - if (best_connection) { - GError *error = NULL; - NMAuthSubject *subject; - NMActiveConnection *ac; - - _LOGI (LOGD_DEVICE, "auto-activating connection '%s'", - nm_settings_connection_get_id (best_connection)); - subject = nm_auth_subject_new_internal (); - ac = nm_manager_activate_connection (priv->manager, - best_connection, - NULL, - specific_object, - device, - subject, - NM_ACTIVATION_TYPE_MANAGED, - &error); - if (!ac) { - _LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: (%d) %s", - nm_settings_connection_get_id (best_connection), - error->code, - error->message); - g_error_free (error); - nm_settings_connection_autoconnect_blocked_reason_set (best_connection, - NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED); - schedule_activate_check (self, device); - return; - } + if (!best_connection) + return; - /* Subscribe to AC state-changed signal to detect when the - * activation fails in early stages without changing device - * state. - */ - if (nm_g_hash_table_add (priv->pending_active_connections, ac)) { - g_signal_connect (ac, NM_ACTIVE_CONNECTION_STATE_CHANGED, - G_CALLBACK (pending_ac_state_changed), g_object_ref (self)); - g_object_weak_ref (G_OBJECT (ac), (GWeakNotify) pending_ac_gone, self); - } + _LOGI (LOGD_DEVICE, "auto-activating connection '%s'", + nm_settings_connection_get_id (best_connection)); + subject = nm_auth_subject_new_internal (); + ac = nm_manager_activate_connection (priv->manager, + best_connection, + NULL, + specific_object, + device, + subject, + NM_ACTIVATION_TYPE_MANAGED, + &error); + if (!ac) { + _LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: (%d) %s", + nm_settings_connection_get_id (best_connection), + error->code, + error->message); + g_error_free (error); + nm_settings_connection_autoconnect_blocked_reason_set (best_connection, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED); + schedule_activate_check (self, device); + return; + } - g_object_unref (subject); + /* Subscribe to AC state-changed signal to detect when the + * activation fails in early stages without changing device + * state. + */ + if (nm_g_hash_table_add (priv->pending_active_connections, ac)) { + g_signal_connect (ac, NM_ACTIVE_CONNECTION_STATE_CHANGED, + G_CALLBACK (pending_ac_state_changed), g_object_ref (self)); + g_object_weak_ref (G_OBJECT (ac), (GWeakNotify) pending_ac_gone, self); } + + g_object_unref (subject); } static gboolean |