diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-09-19 11:31:19 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2014-09-19 11:37:32 +0200 |
commit | 3ae90a1660ddb6a7ec98e073df2643b052f24562 (patch) | |
tree | aa7c63ba8a03678cab5921cf4f47406cb5262f4e | |
parent | 6ff4491eda0c164e4c2766ba5897d2168f22b374 (diff) | |
download | NetworkManager-jk/nmcli-NM-running-fixes.tar.gz |
cli: get NMClient early and remove duplicated codejk/nmcli-NM-running-fixes
-rw-r--r-- | clients/cli/connections.c | 46 | ||||
-rw-r--r-- | clients/cli/devices.c | 99 |
2 files changed, 13 insertions, 132 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 1396b2356c..28fa8f778a 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1284,13 +1284,6 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv) char *profile_flds = NULL, *active_flds = NULL; nmc->should_wait = FALSE; - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto finish; - } if (argc == 0) { char *fields_str; @@ -1997,15 +1990,6 @@ do_connection_up (NmCli *nmc, int argc, char **argv) argv++; } - /* create NMClient */ - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - /* Use nowait_flag instead of should_wait because exiting has to be postponed till * active_connection_state_cb() is called. That gives NM time to check our permissions * and we can follow activation progress. @@ -2057,15 +2041,6 @@ do_connection_down (NmCli *nmc, int argc, char **argv) } } - /* create NMClient */ - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - /* Get active connections */ active_cons = nm_client_get_active_connections (nmc->client); while (arg_num > 0) { @@ -7459,7 +7434,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t g_clear_error (&tmp_err); break; } - nmc->get_client (nmc); nmc->nowait_flag = FALSE; nmc->should_wait = TRUE; @@ -7601,7 +7575,6 @@ get_ethernet_device_name (NmCli *nmc) const GPtrArray *devices; int i; - nmc->get_client (nmc); devices = nm_client_get_devices (nmc->client); for (i = 0; i < devices->len; i++) { NMDevice *dev = g_ptr_array_index (devices, i); @@ -7966,15 +7939,6 @@ do_connection_modify (NmCli *nmc, nmc->should_wait = FALSE; - /* create NMClient */ - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto finish; - } - if (argc == 0) { g_string_printf (nmc->return_text, _("Error: No arguments provided.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -8174,15 +8138,6 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) nmc->return_value = NMC_RESULT_SUCCESS; nmc->should_wait = FALSE; - /* create NMClient */ - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto finish; - } - if (argc == 0) { if (nmc->ask) { line = nmc_readline (PROMPT_CONNECTION); @@ -8438,7 +8393,6 @@ do_connections (NmCli *nmc, int argc, char **argv) nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; return nmc->return_value; } - /* Compare NM and nmcli versions */ if (!nmc_versions_match (nmc)) return nmc->return_value; diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 705838de4d..8bd2c84445 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -1180,17 +1180,6 @@ do_devices_status (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - /* Add headers */ nmc->print_fields.header_name = _("Status of devices"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); @@ -1228,17 +1217,6 @@ do_devices_show (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = get_devices_sorted (nmc->client); if (ifname) { @@ -1392,16 +1370,6 @@ do_device_connect (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) { NMDevice *candidate = devices[i]; @@ -1526,16 +1494,6 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) { NMDevice *candidate = devices[i]; @@ -1620,16 +1578,6 @@ do_device_delete (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) { NMDevice *candidate = devices[i]; @@ -1761,17 +1709,6 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = get_devices_sorted (nmc->client); if (ifname) { /* Device specified - list only APs of this interface */ @@ -2219,17 +2156,6 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = nm_client_get_devices (nmc->client); /* Find a device to activate the connection on */ @@ -2393,7 +2319,6 @@ do_device_wifi_rescan (NmCli *nmc, int argc, char **argv) } /* Find Wi-Fi device to scan on. When no ifname is provided, the first Wi-Fi is used. */ - nmc->get_client (nmc); devices = nm_client_get_devices (nmc->client); devices_idx = 0; device = find_wifi_device_by_iface (devices, ifname, &devices_idx); @@ -2518,17 +2443,6 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv) goto error; } - nmc->get_client (nmc); - - if (!nm_client_get_nm_running (nmc->client)) { - g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); - nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; - goto error; - } - - if (!nmc_versions_match (nmc)) - goto error; - devices = nm_client_get_devices (nmc->client); if (ifname) { /* Device specified - list only NSPs of this interface */ @@ -2745,6 +2659,19 @@ do_devices (NmCli *nmc, int argc, char **argv) rl_attempted_completion_function = (rl_completion_func_t *) nmcli_device_tab_completion; + /* Get NMClient object early */ + nmc->get_client (nmc); + + /* Check whether NetworkManager is runnung */ + if (!nm_client_get_nm_running (nmc->client)) { + g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); + nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; + return nmc->return_value; + } + /* Compare NM and nmcli versions */ + if (!nmc_versions_match (nmc)) + return nmc->return_value; + if (argc == 0) { if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) goto opt_error; |