diff --git a/clients/cli/agent.c b/clients/cli/agent.c index fc716b57f7..c4ff3f9efd 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -144,7 +144,7 @@ do_agent_secret (NmCli *nmc, int argc, char **argv) nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-agent"); if (nmc->secret_agent) { /* We keep running */ - nmc->should_wait = TRUE; + nmc->should_wait++; nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), NULL); g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc); @@ -171,7 +171,7 @@ do_agent_polkit (NmCli *nmc, int argc, char **argv) g_error_free (error); } else { /* We keep running */ - nmc->should_wait = TRUE; + nmc->should_wait++; g_print (_("nmcli successfully registered as a polkit agent.\n")); } diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 7483e1ac7e..08c2ea8eea 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1535,8 +1535,6 @@ do_connections_show (NmCli *nmc, gboolean active_only, gboolean show_secrets, char *profile_flds = NULL, *active_flds = NULL; GPtrArray *invisibles, *sorted_cons; - nmc->should_wait = FALSE; - if (argc == 0) { char *fields_str; char *fields_all = NMC_FIELDS_CON_SHOW_ALL; @@ -2377,13 +2375,14 @@ do_connection_up (NmCli *nmc, int argc, char **argv) * and we can follow activation progress. */ nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, pwds, activate_connection_cb, &error)) { g_string_printf (nmc->return_text, _("Error: %s."), error ? error->message : _("unknown error")); nmc->return_value = error ? error->code : NMC_RESULT_ERROR_CON_ACTIVATION; g_clear_error (&error); + nmc->should_wait--; goto error; } @@ -2391,10 +2390,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv) if (nmc->print_output == NMC_PRINT_PRETTY) progress_id = g_timeout_add (120, progress_cb, _("preparing")); - g_free (line); - return nmc->return_value; error: - nmc->should_wait = FALSE; g_free (line); return nmc->return_value; } @@ -2549,7 +2545,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv) queue = g_slist_reverse (queue); if (nmc->timeout > 0) { - nmc->should_wait = TRUE; + nmc->should_wait++; info = g_slice_new0 (ConnectionCbInfo); info->nmc = nmc; @@ -6586,7 +6582,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv) goto error; } - nmc->should_wait = TRUE; + nmc->should_wait++; info = g_malloc0 (sizeof (AddConnectionInfo)); info->nmc = nmc; @@ -6610,7 +6606,6 @@ error: g_free (type_ask); g_free (ifname_ask); - nmc->should_wait = FALSE; return nmc->return_value; } @@ -8959,7 +8954,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t } nmc->nowait_flag = FALSE; - nmc->should_wait = TRUE; + nmc->should_wait++; nmc->print_output = NMC_PRINT_PRETTY; if (!nmc_activate_connection (nmc, NM_CONNECTION (rem_con), ifname, ap_nsp, ap_nsp, NULL, activate_connection_editor_cb, &tmp_err)) { @@ -9433,14 +9428,14 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) g_object_unref (connection); g_free (nmc_tab_completion.con_type); - nmc->should_wait = TRUE; + nmc->should_wait++; return nmc->return_value; error: g_assert (!connection); g_free (type_ask); - nmc->should_wait = FALSE; + nmc->should_wait++; return nmc->return_value; } @@ -9483,7 +9478,6 @@ do_connection_modify (NmCli *nmc, GError *error = NULL; nmc->return_value = NMC_RESULT_SUCCESS; - nmc->should_wait = FALSE; if (argc == 0) { g_string_printf (nmc->return_text, _("Error: No arguments provided.")); @@ -9538,7 +9532,7 @@ do_connection_modify (NmCli *nmc, update_connection (!temporary, rc, modify_connection_cb, nmc); - nmc->should_wait = TRUE; + nmc->should_wait++; finish: return nmc->return_value; } @@ -9785,7 +9779,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) info->timeout_id = g_timeout_add_seconds (nmc->timeout, connection_op_timeout_cb, info); nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; g_signal_connect (nmc->client, NM_CLIENT_CONNECTION_REMOVED, G_CALLBACK (connection_removed_cb), info); @@ -9813,7 +9807,6 @@ do_connection_reload (NmCli *nmc, int argc, char **argv) GError *error = NULL; nmc->return_value = NMC_RESULT_SUCCESS; - nmc->should_wait = FALSE; if (!nm_client_reload_connections (nmc->client, NULL, &error)) { g_string_printf (nmc->return_text, _("Error: failed to reload connections: %s."), @@ -9833,7 +9826,6 @@ do_connection_load (NmCli *nmc, int argc, char **argv) int i; nmc->return_value = NMC_RESULT_SUCCESS; - nmc->should_wait = FALSE; if (argc == 0) { g_string_printf (nmc->return_text, _("Error: No connection specified.")); @@ -10115,7 +10107,7 @@ do_connections (NmCli *nmc, int argc, char **argv) } else if (matches(*argv, "add") == 0) { nmc->return_value = do_connection_add (nmc, argc-1, argv+1); } else if (matches(*argv, "edit") == 0) { - nmc->should_wait = TRUE; + nmc->should_wait++; editor_thread_data.nmc = nmc; editor_thread_data.argc = argc - 1; editor_thread_data.argv = argv + 1; diff --git a/clients/cli/devices.c b/clients/cli/devices.c index e37d0f4b2b..b6e73e82ee 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -1622,7 +1622,7 @@ do_device_connect (NmCli *nmc, int argc, char **argv) * till connect_device_cb() is called, giving NM time to check our permissions. */ nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; /* Create secret agent */ nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect"); @@ -1840,7 +1840,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv) G_CALLBACK (device_removed_cb), info); nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; for (iter = queue; iter; iter = g_slist_next (iter)) { device = iter->data; @@ -1961,7 +1961,7 @@ do_device_delete (NmCli *nmc, int argc, char **argv) G_CALLBACK (device_removed_cb), info); nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; for (iter = queue; iter; iter = g_slist_next (iter)) { device = iter->data; @@ -2726,7 +2726,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv) * the user doesn't want to wait, in order to give NM time to check our * permissions. */ nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait = TRUE; + nmc->should_wait++; info = g_malloc0 (sizeof (AddAndActivateInfo)); info->nmc = nmc; @@ -3116,8 +3116,6 @@ do_device_wifi_rescan (NmCli *nmc, int argc, char **argv) const char *ssid; int i; - nmc->should_wait = TRUE; - ssids = g_ptr_array_new (); /* Get the parameters */ @@ -3185,7 +3183,7 @@ do_device_wifi_rescan (NmCli *nmc, int argc, char **argv) g_ptr_array_free (ssids, FALSE); return nmc->return_value; error: - nmc->should_wait = FALSE; + nmc->should_wait++; g_ptr_array_free (ssids, FALSE); return nmc->return_value; } diff --git a/clients/cli/general.c b/clients/cli/general.c index 9118fb33d1..abf71f67a1 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -619,7 +619,7 @@ do_general (NmCli *nmc, int argc, char **argv) if (next_arg (&argc, &argv) == 0) g_print ("Warning: ignoring extra garbage after '%s' hostname\n", hostname); - nmc->should_wait = TRUE; + nmc->should_wait++; nmc->get_client (nmc); /* create NMClient */ nm_client_save_hostname_async (nmc->client, hostname, NULL, save_hostname_cb, nmc); } diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index bd176c8fc8..9242dd4f41 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -532,7 +532,7 @@ nmc_init (NmCli *nmc) nmc->pwds_hash = NULL; nmc->pk_listener = NULL; - nmc->should_wait = FALSE; + nmc->should_wait = 0; nmc->nowait_flag = TRUE; nmc->print_output = NMC_PRINT_NORMAL; nmc->multiline_output = FALSE; diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 06662fefee..de44a08c19 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -144,7 +144,7 @@ typedef struct _NmCli { GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */ NMPolkitListener *pk_listener ; /* polkit agent listener */ - gboolean should_wait; /* Indication that nmcli should not end yet */ + int should_wait; /* Semaphore indicating whether nmcli should not end or not 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 */