summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-11-26 13:23:07 -0600
committerDan Williams <dcbw@redhat.com>2014-11-26 13:23:07 -0600
commit6ffbd5ed3e4c52091195304af19a1afe95fd7270 (patch)
tree3b3fcb98a259f2f1ac15ec1f5c747c2f631931f2
parent382906c39130b1943c179643980645c71cd0d4a1 (diff)
downloadNetworkManager-dcbw/cli-down-wait-bgo740775.tar.gz
cli: wait for "con down" to deactivate the connection (bgo #740775) (rh #1168383)dcbw/cli-down-wait-bgo740775
nmcli currently does not wait for the connection to fully deactivate, which can take some time due to dispatcher scripts or cleanup operations like DCB. Change it to wait until the connection is deactivated, or until a short timeout has expired. The user can adjust the timeout with "--wait" if they want. https://bugzilla.gnome.org/show_bug.cgi?id=740775 https://bugzilla.redhat.com/show_bug.cgi?id=1168383
-rw-r--r--clients/cli/connections.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 70f20e7f6e..eadfe8b7d1 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -2235,6 +2235,47 @@ error:
return nmc->return_value;
}
+typedef struct {
+ NmCli *nmc;
+ NMActiveConnection *active;
+} DeactivateConnectionInfo;
+
+static void
+deactivate_connection_info_free (gpointer user_data)
+{
+ DeactivateConnectionInfo *info = user_data;
+
+ g_object_unref (info->active);
+ g_slice_free (DeactivateConnectionInfo, info);
+}
+
+static gboolean
+down_timeout_cb (gpointer user_data)
+{
+ DeactivateConnectionInfo *info = user_data;
+
+ timeout_cb (info->nmc);
+ deactivate_connection_info_free (info);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+down_active_connection_state_cb (NMActiveConnection *active,
+ GParamSpec *pspec,
+ DeactivateConnectionInfo *info)
+{
+ if (nm_active_connection_get_state (active) < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
+ return;
+
+ if (info->nmc->print_output == NMC_PRINT_PRETTY)
+ nmc_terminal_erase_line ();
+ g_print (_("Connection successfully deactivated (D-Bus active path: %s)\n"),
+ nm_object_get_path (NM_OBJECT (info->active)));
+
+ deactivate_connection_info_free (info);
+ quit ();
+}
+
static NMCResultCode
do_connection_down (NmCli *nmc, int argc, char **argv)
{
@@ -2259,6 +2300,9 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
}
}
+ if (nmc->timeout == -1)
+ nmc->timeout = 10;
+
/* Get active connections */
active_cons = nm_client_get_active_connections (nmc->client);
while (arg_num > 0) {
@@ -2279,7 +2323,25 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
active = find_active_connection (active_cons, nmc->connections, selector, *arg_ptr, &idx);
if (active) {
+ DeactivateConnectionInfo *info;
+
nm_client_deactivate_connection (nmc->client, active, NULL, NULL);
+
+ if (nmc->timeout == 0)
+ break;
+
+ info = g_slice_new0 (DeactivateConnectionInfo);
+ info->nmc = nmc;
+ info->active = g_object_ref (active);
+
+ /* Wait for ActiveConnection to deactivate */
+ nmc->should_wait = TRUE;
+ g_timeout_add_seconds (nmc->timeout, down_timeout_cb, info);
+ g_signal_connect (active,
+ "notify::" NM_ACTIVE_CONNECTION_STATE,
+ G_CALLBACK (down_active_connection_state_cb),
+ info);
+ break;
} else {
g_string_printf (nmc->return_text, _("Error: '%s' is not an active connection."), *arg_ptr);
nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND;
@@ -2290,9 +2352,8 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
next_arg (&arg_num, &arg_ptr);
}
- // FIXME: do something better then sleep()
- /* Don't quit immediatelly and give NM time to check our permissions */
- sleep (1);
+ g_strfreev (arg_arr);
+ return nmc->return_value;
error:
nmc->should_wait = FALSE;