summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-12-08 15:54:42 +0100
committerJiří Klimeš <jklimes@redhat.com>2015-12-15 15:07:19 +0100
commit497fc9db2055fae4d2da1fc748fa08a129c0a626 (patch)
tree748db78173cc138e2e31e200760f9280f83e1d61
parent8233206c0e35cce3c5431cef5ee9eb2e3b0ac4f2 (diff)
downloadNetworkManager-jk/libnm-cli-fixes-bgo741336.tar.gz
cli: monitor device when activating connections to capture errorsjk/libnm-cli-fixes-bgo741336
This allows us better reporting on failures. Example: $ nmcli con up my-wifi-missing-passwd will return "Error: Connection activation failed: Secrets were required, but not provided." instead of "Error: Connection activation failed."
-rw-r--r--clients/cli/connections.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 31b01d4912..7bcc7b8940 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -1975,6 +1975,35 @@ device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
}
}
+static const char *nmc_activate_error = NULL;
+
+static void
+store_device_error_cb (NMDevice *device,
+ NMDeviceState new_state,
+ NMDeviceState old_state,
+ NMDeviceStateReason reason)
+{
+ /* Store the failure error message */
+ if ((new_state == NM_DEVICE_STATE_FAILED || new_state == NM_DEVICE_STATE_DEACTIVATING))
+ nmc_activate_error = nmc_device_reason_to_string (reason);
+}
+
+static gboolean
+deactivated_idle_func (NmCli *nmc)
+{
+ static int counter = 5;
+
+ counter--;
+ if (nmc_activate_error || counter == 0) {
+ g_string_printf (nmc->return_text, _("Error: Connection activation failed%s%s."),
+ nmc_activate_error ? ": " : "", nmc_activate_error ? nmc_activate_error : "");
+ nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
+ quit ();
+ return FALSE;
+ }
+ return TRUE;
+}
+
static void
active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpointer user_data)
{
@@ -1991,10 +2020,9 @@ active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpoin
g_object_unref (active);
quit ();
} else if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
- g_string_printf (nmc->return_text, _("Error: Connection activation failed."));
- nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
g_object_unref (active);
- quit ();
+ /* Postpone quit so that we can obtain the error. */
+ g_timeout_add (100, (GSourceFunc) deactivated_idle_func, nmc);
} else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) {
/* activating master connection does not automatically activate any slaves, so their
* active connection state will not progress beyond ACTIVATING state.
@@ -2343,6 +2371,9 @@ nmc_activate_connection (NmCli *nmc,
NULL,
callback,
info);
+ if (device)
+ g_signal_connect (device, "state-changed", G_CALLBACK (store_device_error_cb), NULL);
+
return TRUE;
}