libnm: make the the use of GInitable mandatory
Remove _nm_object_ensure_inited(), etc; objects that implement GInitable are now mandatory-to-init(). Remove constructor() implementations that sometimes return NULL; do all the relevant checking in init() instead. Make nm_client_new() and nm_remote_settings_new() take a GCancellable and a GError**.
This commit is contained in:
@@ -8645,6 +8645,7 @@ do_connections (NmCli *nmc, int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
gboolean real_cmd = FALSE;
|
||||
GError *error = NULL;
|
||||
|
||||
if (argc == 0)
|
||||
real_cmd = TRUE;
|
||||
@@ -8672,8 +8673,9 @@ do_connections (NmCli *nmc, int argc, char **argv)
|
||||
args_info.argv = argv;
|
||||
|
||||
/* get system settings */
|
||||
if (!(nmc->system_settings = nm_remote_settings_new (NULL))) {
|
||||
g_string_printf (nmc->return_text, _("Error: Could not get system settings."));
|
||||
if (!(nmc->system_settings = nm_remote_settings_new (NULL, &error))) {
|
||||
g_string_printf (nmc->return_text, _("Error: Could not get system settings: %s."), error->message);
|
||||
g_error_free (error);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
nmc->should_wait = FALSE;
|
||||
return nmc->return_value;
|
||||
|
@@ -611,8 +611,9 @@ do_general (NmCli *nmc, int argc, char **argv)
|
||||
}
|
||||
|
||||
/* get system settings */
|
||||
if (!(rem_settings = nm_remote_settings_new (NULL))) {
|
||||
g_string_printf (nmc->return_text, _("Error: Could not get system settings."));
|
||||
if (!(rem_settings = nm_remote_settings_new (NULL, &error))) {
|
||||
g_string_printf (nmc->return_text, _("Error: Could not get system settings: %s."), error->message);
|
||||
g_clear_error (&error);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
goto finish;
|
||||
}
|
||||
|
@@ -394,10 +394,13 @@ setup_signals (void)
|
||||
static NMClient *
|
||||
nmc_get_client (NmCli *nmc)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!nmc->client) {
|
||||
nmc->client = nm_client_new ();
|
||||
nmc->client = nm_client_new (NULL, &error);
|
||||
if (!nmc->client) {
|
||||
g_critical (_("Error: Could not create NMClient object."));
|
||||
g_critical (_("Error: Could not create NMClient object: %s."), error->message);
|
||||
g_clear_error (&error);
|
||||
exit (NMC_RESULT_ERROR_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
@@ -143,6 +143,7 @@ main (int argc, char *argv[])
|
||||
NMState state = NM_STATE_UNKNOWN;
|
||||
GMainLoop *loop;
|
||||
gint64 remaining_ms;
|
||||
GError *error = NULL;
|
||||
|
||||
GOptionEntry options[] = {
|
||||
{"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), "<timeout>"},
|
||||
@@ -191,9 +192,10 @@ main (int argc, char *argv[])
|
||||
g_type_init ();
|
||||
#endif
|
||||
|
||||
client = nm_client_new ();
|
||||
client = nm_client_new (NULL, &error);
|
||||
if (!client) {
|
||||
g_printerr (_("Error: Could not create NMClient object."));
|
||||
g_printerr (_("Error: Could not create NMClient object: %s."), error->message);
|
||||
g_error_free (error);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@@ -246,13 +246,23 @@ main (int argc, char **argv)
|
||||
|
||||
nm_editor_bindings_init ();
|
||||
|
||||
nm_client = nm_client_new ();
|
||||
nm_client = nm_client_new (NULL, &error);
|
||||
if (!nm_client) {
|
||||
g_printerr (_("Could not contact NetworkManager: %s.\n"), error->message);
|
||||
g_error_free (error);
|
||||
exit (1);
|
||||
}
|
||||
if (!nm_client_get_manager_running (nm_client)) {
|
||||
g_printerr ("%s\n", _("NetworkManager is not running."));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
nm_settings = nm_remote_settings_new (NULL);
|
||||
nm_settings = nm_remote_settings_new (NULL, &error);
|
||||
if (!nm_settings) {
|
||||
g_printerr (_("Could not contact NetworkManager: %s.\n"), error->message);
|
||||
g_error_free (error);
|
||||
exit (1);
|
||||
}
|
||||
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
|
||||
G_CALLBACK (connections_read), &got_connections);
|
||||
/* coverity[loop_condition] */
|
||||
|
Reference in New Issue
Block a user