From d471a58a97183bc7b620965249f63dcbd0fd9cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 29 Jul 2010 16:16:20 +0200 Subject: [PATCH] cli: wait a bit even when '--nowait' is specified; for permissions check (rh #614866) NetworkManager checks clients' permissions on requests, so nmcli mustn't quit too early to give NM a chance to reach it on D-Bus. --- cli/src/connections.c | 9 +++++++-- cli/src/devices.c | 7 +++++-- cli/src/nmcli.c | 1 + cli/src/nmcli.h | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index b0d9883cdd..9a20753391 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1288,7 +1289,7 @@ activate_connection_cb (gpointer user_data, const char *path, GError *error) printf (_("Active connection state: %s\n"), active_connection_state_to_string (state)); printf (_("Active connection path: %s\n"), orig_path); - if (!orig_nmc->should_wait || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + if (orig_nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { /* don't want to wait or already activated */ quit (); } else { @@ -1415,7 +1416,10 @@ do_connection_up (NmCli *nmc, int argc, char **argv) goto error; } - nmc->should_wait = wait; + /* Use nowait_flag instead of should_wait because exitting has to be postponed till active_connection_state_cb() + * is called, giving NM time to check our permissions */ + nmc->nowait_flag = !wait; + nmc->should_wait = TRUE; nm_client_activate_connection (nmc->client, is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS, con_path, @@ -1504,6 +1508,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv) else { fprintf (stderr, _("Warning: Connection not active\n")); } + sleep (1); /* Don't quit immediatelly and give NM time to check our permissions */ error: nmc->should_wait = FALSE; diff --git a/cli/src/devices.c b/cli/src/devices.c index e2ce91e358..7c9dcc5210 100644 --- a/cli/src/devices.c +++ b/cli/src/devices.c @@ -929,7 +929,7 @@ disconnect_device_cb (NMDevice *device, GError *error, gpointer user_data) state = nm_device_get_state (device); printf (_("Device state: %d (%s)\n"), state, device_state_to_string (state)); - if (!nmc->should_wait || state == NM_DEVICE_STATE_DISCONNECTED) { + if (nmc->nowait_flag || state == NM_DEVICE_STATE_DISCONNECTED) { /* Don't want to wait or device already disconnected */ quit (); } else { @@ -1015,7 +1015,10 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv) goto error; } - nmc->should_wait = wait; + /* Use nowait_flag instead of should_wait because exitting has to be postponed till disconnect_device_cb() + * is called, giving NM time to check our permissions */ + nmc->nowait_flag = !wait; + nmc->should_wait = TRUE; nm_device_disconnect (device, disconnect_device_cb, nmc); error: diff --git a/cli/src/nmcli.c b/cli/src/nmcli.c index 328a6d8ee5..d416952c6c 100644 --- a/cli/src/nmcli.c +++ b/cli/src/nmcli.c @@ -286,6 +286,7 @@ nmc_init (NmCli *nmc) nmc->user_connections = NULL; nmc->should_wait = FALSE; + nmc->nowait_flag = TRUE; nmc->print_output = NMC_PRINT_NORMAL; nmc->multiline_output = FALSE; nmc->mode_specified = FALSE; diff --git a/cli/src/nmcli.h b/cli/src/nmcli.h index b4e4562bfe..9788ef086c 100644 --- a/cli/src/nmcli.h +++ b/cli/src/nmcli.h @@ -102,6 +102,7 @@ typedef struct _NmCli { GSList *user_connections; /* List of user connections */ gboolean should_wait; /* Indication that nmcli should not end yet */ + gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */ NMCPrintOutput print_output; /* Output mode */ gboolean multiline_output; /* Multiline output instead of default tabular */ gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */