From ba2722004a60281c4682f4b36093c4249f9b37f4 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 3 Nov 2014 23:25:23 +0100 Subject: [PATCH 1/2] libnm: Watch for AC removal in case of AddAndActivateConnection() as well This does the very same thing as 42b9e8283 does for plain ActivateConnection(). --- libnm/nm-manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index 11c4db9f3b..bbb9331305 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -952,6 +952,9 @@ add_activate_cb (GObject *object, G_CALLBACK (activation_cancelled), info); } + g_signal_connect (info->manager, "active-connection-removed", + G_CALLBACK (active_removed), info); + recheck_pending_activations (info->manager); } else { g_dbus_error_strip_remote_error (error); From 7d80a1763188da6fbd11d8a8a2fadb8f125f515d Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 14 Nov 2014 18:29:36 +0100 Subject: [PATCH 2/2] 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. --- clients/cli/devices.c | 38 ++++++++++++-------------------------- 1 file 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); } }