summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-12-08 15:54:42 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-12-15 15:23:49 +0100
commit5e7cf761b86059f9328ac0a2ca52922c269492ba (patch)
tree7beca6717b835c0f71b6e5891873bd6415bec95d
parent9ec818ac2c5b89315d6f126ba6355a8817098931 (diff)
downloadNetworkManager-jk/libnm-cli-fixes2.tar.gz
cli: monitor device when activating connections to capture errorsjk/libnm-cli-fixes2
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 6a532b5852..e3f93a25c5 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -1739,6 +1739,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)
{
@@ -1755,10 +1784,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.
@@ -2107,6 +2135,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;
}