summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2014-11-14 18:29:36 +0100
committerDan Williams <dcbw@redhat.com>2014-11-14 16:46:40 -0600
commit7d80a1763188da6fbd11d8a8a2fadb8f125f515d (patch)
tree1545df9b7ec89e23c4757876d4aea47d040ccccf
parentba2722004a60281c4682f4b36093c4249f9b37f4 (diff)
downloadNetworkManager-7d80a1763188da6fbd11d8a8a2fadb8f125f515d.tar.gz
cli: Finish waiting for the device activation when it disconnects
The device status alone is uninteresting as its changes can be due to deactivation of previously active connection. We should monitor the active connection changes instead of device state changes. However the device state changes is still interesting, as it contains the reason for the change, let's just ignore them while the connection is activating. Lastly, we need to handle failures as well. It should be noted that it's not sufficient to deal with NM_DEVICE_STATE_FAILED as the device will quickly draverse to NM_DEVICE_STATE_DISCONNECTED. This happens in case of a failure due to NM_DEVICE_STATE_REASON_NO_SECRETS as soon as the server makes sure it won't reconnect automatically.
-rw-r--r--clients/cli/devices.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 3703743957..3499834d38 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -1336,8 +1336,14 @@ connected_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
NMActiveConnection *active = (NMActiveConnection *) user_data;
NMDeviceState state;
+ NMDeviceStateReason reason;
+ NMActiveConnectionState ac_state;
state = nm_device_get_state (device);
+ ac_state = nm_active_connection_get_state (active);
+
+ if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING)
+ return;
if (state == NM_DEVICE_STATE_ACTIVATED) {
nmc_terminal_erase_line ();
@@ -1346,31 +1352,12 @@ connected_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
nm_active_connection_get_uuid (active));
g_object_unref (active);
quit ();
- }
-}
-
-static void
-monitor_device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
-{
- NmCli *nmc = (NmCli *) user_data;
- NMDeviceState state;
- NMDeviceStateReason reason;
-
- state = nm_device_get_state (device);
-
- if (state == NM_DEVICE_STATE_ACTIVATED) {
- NMActiveConnection *active = nm_device_get_active_connection (device);
-
- if (nmc->print_output == NMC_PRINT_PRETTY)
- nmc_terminal_erase_line ();
- g_print (_("Connection with UUID '%s' created and activated on device '%s'\n"),
- nm_active_connection_get_uuid (active), nm_device_get_iface (device));
- quit ();
- } else if (state == NM_DEVICE_STATE_FAILED) {
+ } else if ( state <= NM_DEVICE_STATE_DISCONNECTED
+ || state >= NM_DEVICE_STATE_DEACTIVATING) {
reason = nm_device_get_state_reason (device);
- g_string_printf (nmc->return_text, _("Error: Connection activation failed: (%d) %s."),
- reason, nmc_device_reason_to_string (reason));
- nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
+ g_print (_("Error: Connection activation failed: (%d) %s.\n"),
+ reason, nmc_device_reason_to_string (reason));
+ g_object_unref (active);
quit ();
}
}
@@ -1420,12 +1407,11 @@ add_and_activate_cb (GObject *client,
g_object_unref (active);
quit ();
} else {
- g_signal_connect (device, "notify::state", G_CALLBACK (monitor_device_state_cb), nmc);
+ g_signal_connect (device, "notify::state", G_CALLBACK (connected_state_cb), active);
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc); /* Exit if timeout expires */
if (nmc->print_output == NMC_PRINT_PRETTY)
progress_id = g_timeout_add (120, progress_cb, device);
- g_object_unref (active);
}
}