cli: fix 'nmcli con delete' (rh #771258)

The command didn't delete the connection, because nmcli exited before NM could
check permissions (actually ConsoleKit didn't see the process).
Now nmcli waits for "Removed" signal or D-Bus return (error) message on "Delete"
method call.
This commit is contained in:
Jiří Klimeš
2012-01-10 16:18:27 +01:00
parent 32bbdc461b
commit 659c22ccf6
2 changed files with 39 additions and 5 deletions

View File

@@ -2013,6 +2013,27 @@ error:
return nmc->return_value; return nmc->return_value;
} }
static void
delete_cb (NMRemoteConnection *con, GError *err, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
if (err) {
g_string_printf (nmc->return_text, _("Error: Connection deletion failed: %s"), err->message);
nmc->return_value = NMC_RESULT_ERROR_CON_DEL;
}
quit ();
}
static void
connection_removed_cb (NMRemoteConnection *con, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
nmc->return_value = NMC_RESULT_SUCCESS;
quit ();
}
static NMCResultCode static NMCResultCode
do_connection_delete (NmCli *nmc, int argc, char **argv) do_connection_delete (NmCli *nmc, int argc, char **argv)
{ {
@@ -2021,8 +2042,6 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
const char *id = NULL; const char *id = NULL;
GError *error = NULL; GError *error = NULL;
nmc->should_wait = FALSE;
while (argc > 0) { while (argc > 0) {
if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) { if (strcmp (*argv, "id") == 0 || strcmp (*argv, "uuid") == 0) {
selector = *argv; selector = *argv;
@@ -2066,10 +2085,22 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
goto error; goto error;
} }
/* We need to wait a bit so that nmcli's permissions can be queried.
* We will exit either on "Removed" signal or when D-Bus return (error)
* message is received.
*/
nmc->should_wait = TRUE;
/* Connect to "Removed" signal to be able to exit when connection was removed */
g_signal_connect (connection, NM_REMOTE_CONNECTION_REMOVED, G_CALLBACK (connection_removed_cb), nmc);
/* Delete the connection */ /* Delete the connection */
nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), NULL, NULL); nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), delete_cb, nmc);
return nmc->return_value;
error: error:
nmc->should_wait = FALSE;
return nmc->return_value; return nmc->return_value;
} }

View File

@@ -48,11 +48,14 @@ typedef enum {
/* Error in device disconnect */ /* Error in device disconnect */
NMC_RESULT_ERROR_DEV_DISCONNECT = 6, NMC_RESULT_ERROR_DEV_DISCONNECT = 6,
/* Error in connection deletion */
NMC_RESULT_ERROR_CON_DEL = 7,
/* NetworkManager is not running */ /* NetworkManager is not running */
NMC_RESULT_ERROR_NM_NOT_RUNNING = 7, NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
/* nmcli and NetworkManager versions mismatch */ /* nmcli and NetworkManager versions mismatch */
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 8 NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9
} NMCResultCode; } NMCResultCode;
typedef enum { typedef enum {