summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-05-24 22:01:50 +0200
committerThomas Haller <thaller@redhat.com>2017-05-25 10:59:15 +0200
commitcd6449f1621d8b346b25ac573cad2261a7e0d9b2 (patch)
treed695694f34c089aac8aeb4589968469488e3f820
parent4f69c1e85e58d024fedcfde641b3dbfcbf3e834c (diff)
downloadNetworkManager-cd6449f1621d8b346b25ac573cad2261a7e0d9b2.tar.gz
cli: change check_activated() to ensure we don't miss a deactivation
In the previous code it is not clear to me that there won't be a situation where we don't react on a state change, waiting for a device-state-change that never comes. Now, only wait for a better device-state reason if: - we have a device - and the ac-reason is unspecific (NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED) - and the device still references the current active connection - and the device state is not yet FAILED or DISCONNECTED. The most important change is that we only wait longer, if the device's active-connection is still the same as our current active connection. I don't think this commit is really necessary, but I cannot understand the previous logic. See-also: 57a26fd2aae9c38e56a05f1994feff6774eeba37
-rw-r--r--clients/cli/connections.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index d4a955b238..983a9587dd 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -2096,8 +2096,9 @@ check_activated (ActivateConnectionInfo *info)
NMDevice *device = info->device;
NMActiveConnection *active = info->active;
NMActiveConnectionStateReason ac_reason;
- NMDeviceState dev_state;
- NMDeviceStateReason dev_reason;
+ NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN;
+ NMDeviceStateReason dev_reason = NM_DEVICE_STATE_REASON_UNKNOWN;
+ const char *reason;
ac_reason = nm_active_connection_get_state_reason (active);
@@ -2117,20 +2118,33 @@ check_activated (ActivateConnectionInfo *info)
break;
case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED:
- if ( device
- && ac_reason == NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED) {
- if (dev_state == NM_DEVICE_STATE_FAILED || dev_state == NM_DEVICE_STATE_DISCONNECTED) {
- g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"),
- nmc_device_reason_to_string (dev_reason));
- nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
- activate_connection_info_finish (info);
- } else {
- /* Just wait for the device to go failed. We'll get a better error message. */
- return;
- }
+
+ if ( !device
+ || ac_reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED
+ || nm_device_get_active_connection (device) != active) {
+ /* (1)
+ * - we have no device,
+ * - or, @ac_reason is specific
+ * - or, @device no longer references the current @active
+ * >> we complete with @ac_reason. */
+ reason = active_connection_state_reason_to_string (ac_reason);
+ } else if ( dev_state <= NM_DEVICE_STATE_DISCONNECTED
+ || dev_state >= NM_DEVICE_STATE_FAILED) {
+ /* (2)
+ * - not (1)
+ * - and, the device is no longer in an activated state,
+ * >> we complete with @dev_reason. */
+ reason = nmc_device_reason_to_string (dev_reason);
} else {
+ /* (3)
+ * we wait for the device go disconnect. We will get a better
+ * failure reason from the device (2). */
+ reason = NULL;
+ }
+
+ if (reason) {
g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"),
- active_connection_state_reason_to_string (ac_reason));
+ reason);
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
activate_connection_info_finish (info);
}