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.
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <netinet/ether.h>
|
#include <netinet/ether.h>
|
||||||
@@ -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 state: %s\n"), active_connection_state_to_string (state));
|
||||||
printf (_("Active connection path: %s\n"), orig_path);
|
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 */
|
/* don't want to wait or already activated */
|
||||||
quit ();
|
quit ();
|
||||||
} else {
|
} else {
|
||||||
@@ -1415,7 +1416,10 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||||||
goto error;
|
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,
|
nm_client_activate_connection (nmc->client,
|
||||||
is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
|
is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
|
||||||
con_path,
|
con_path,
|
||||||
@@ -1504,6 +1508,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
fprintf (stderr, _("Warning: Connection not active\n"));
|
fprintf (stderr, _("Warning: Connection not active\n"));
|
||||||
}
|
}
|
||||||
|
sleep (1); /* Don't quit immediatelly and give NM time to check our permissions */
|
||||||
|
|
||||||
error:
|
error:
|
||||||
nmc->should_wait = FALSE;
|
nmc->should_wait = FALSE;
|
||||||
|
@@ -929,7 +929,7 @@ disconnect_device_cb (NMDevice *device, GError *error, gpointer user_data)
|
|||||||
state = nm_device_get_state (device);
|
state = nm_device_get_state (device);
|
||||||
printf (_("Device state: %d (%s)\n"), state, device_state_to_string (state));
|
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 */
|
/* Don't want to wait or device already disconnected */
|
||||||
quit ();
|
quit ();
|
||||||
} else {
|
} else {
|
||||||
@@ -1015,7 +1015,10 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
|
|||||||
goto error;
|
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);
|
nm_device_disconnect (device, disconnect_device_cb, nmc);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@@ -286,6 +286,7 @@ nmc_init (NmCli *nmc)
|
|||||||
nmc->user_connections = NULL;
|
nmc->user_connections = NULL;
|
||||||
|
|
||||||
nmc->should_wait = FALSE;
|
nmc->should_wait = FALSE;
|
||||||
|
nmc->nowait_flag = TRUE;
|
||||||
nmc->print_output = NMC_PRINT_NORMAL;
|
nmc->print_output = NMC_PRINT_NORMAL;
|
||||||
nmc->multiline_output = FALSE;
|
nmc->multiline_output = FALSE;
|
||||||
nmc->mode_specified = FALSE;
|
nmc->mode_specified = FALSE;
|
||||||
|
@@ -102,6 +102,7 @@ typedef struct _NmCli {
|
|||||||
GSList *user_connections; /* List of user connections */
|
GSList *user_connections; /* List of user connections */
|
||||||
|
|
||||||
gboolean should_wait; /* Indication that nmcli should not end yet */
|
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 */
|
NMCPrintOutput print_output; /* Output mode */
|
||||||
gboolean multiline_output; /* Multiline output instead of default tabular */
|
gboolean multiline_output; /* Multiline output instead of default tabular */
|
||||||
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
|
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
|
||||||
|
Reference in New Issue
Block a user