cli: improve/add NM running checks
Check whether NetworkManager is running and return new error NMC_RESULT_ERROR_NM_NOT_RUNNING when appropriate.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2011 Red Hat, Inc.
|
||||
* (C) Copyright 2010 - 2011 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
@@ -647,12 +647,6 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
|
||||
|
||||
nmc->should_wait = FALSE;
|
||||
|
||||
/* create NMClient */
|
||||
if (!nmc->get_client (nmc))
|
||||
return nmc->return_value;
|
||||
|
||||
active_cons = nm_client_get_active_connections (nmc->client);
|
||||
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
||||
fields_str = fields_common;
|
||||
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
||||
@@ -673,10 +667,25 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!nmc_is_nm_running (nmc, &error)) {
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: Can't find out if NetworkManager is running: %s."), error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_error_free (error);
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Print headers */
|
||||
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
|
||||
nmc->print_fields.header_name = _("Active connections");
|
||||
print_fields (nmc->print_fields, nmc->allowed_fields);
|
||||
|
||||
nmc->get_client (nmc);
|
||||
active_cons = nm_client_get_active_connections (nmc->client);
|
||||
if (active_cons && active_cons->len) {
|
||||
info = g_malloc0 (sizeof (StatusInfo));
|
||||
info->nmc = nmc;
|
||||
@@ -688,7 +697,6 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
|
||||
}
|
||||
|
||||
error:
|
||||
|
||||
return nmc->return_value;
|
||||
}
|
||||
|
||||
@@ -1555,9 +1563,20 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* create NMClient */
|
||||
if (!nmc->get_client (nmc))
|
||||
if (!nmc_is_nm_running (nmc, &error)) {
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: Can't find out if NetworkManager is running: %s."), error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_error_free (error);
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* create NMClient */
|
||||
nmc->get_client (nmc);
|
||||
|
||||
is_system = (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) ? TRUE : FALSE;
|
||||
con_path = nm_connection_get_path (connection);
|
||||
@@ -1574,6 +1593,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
||||
else
|
||||
g_string_printf (nmc->return_text, _("Error: No suitable device found."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
|
||||
g_clear_error (&error);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -1600,6 +1620,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
||||
{
|
||||
NMConnection *connection = NULL;
|
||||
NMActiveConnection *active = NULL;
|
||||
GError *error = NULL;
|
||||
const GPtrArray *active_cons;
|
||||
const char *con_path;
|
||||
const char *active_path;
|
||||
@@ -1645,9 +1666,20 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* create NMClient */
|
||||
if (!nmc->get_client (nmc))
|
||||
if (!nmc_is_nm_running (nmc, &error)) {
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: Can't find out if NetworkManager is running: %s."), error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_error_free (error);
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* create NMClient */
|
||||
nmc->get_client (nmc);
|
||||
|
||||
con_path = nm_connection_get_path (connection);
|
||||
con_scope = nm_connection_get_scope (connection);
|
||||
|
Reference in New Issue
Block a user