summary refs log tree commit diff
path: root/clients/cloud-setup/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'clients/cloud-setup/main.c')
-rw-r--r--clients/cloud-setup/main.c86
1 files changed, 26 insertions, 60 deletions
diff --git a/clients/cloud-setup/main.c b/clients/cloud-setup/main.c
index 8250945c..4e1a9a4e 100644
--- a/clients/cloud-setup/main.c
+++ b/clients/cloud-setup/main.c
@@ -2,8 +2,9 @@
 
 #include "nm-default.h"
 
-#include "nm-cloud-setup-utils.h"
+#include "nm-libnm-aux/nm-libnm-aux.h"
 
+#include "nm-cloud-setup-utils.h"
 #include "nmcs-provider-ec2.h"
 #include "nm-libnm-core-intern/nm-libnm-core-utils.h"
 
@@ -30,7 +31,7 @@ _provider_detect_cb (GObject *source,
 
 	nm_assert (success != (!!error));
 
-	if (nm_utils_error_is_cancelled (error, FALSE))
+	if (nm_utils_error_is_cancelled (error))
 		return;
 
 	dd = user_data;
@@ -122,58 +123,6 @@ out:
 
 /*****************************************************************************/
 
-typedef struct {
-	GMainLoop *main_loop;
-	NMClient *nmc;
-} ClientCreateData;
-
-static void
-_nmc_create_cb (GObject *source_object,
-                GAsyncResult *result,
-                gpointer user_data)
-{
-	gs_unref_object NMClient *nmc = NULL;
-	ClientCreateData *data = user_data;
-	gs_free_error GError *error = NULL;
-
-	nmc = nm_client_new_finish (result, &error);
-	if (!nmc) {
-		if (!nm_utils_error_is_cancelled (error, FALSE))
-			_LOGI ("failure to talk to NetworkManager: %s", error->message);
-		goto out;
-	}
-
-	if (!nm_client_get_nm_running (nmc)) {
-		_LOGI ("NetworkManager is not running");
-		goto out;
-	}
-
-	_LOGD ("NetworkManager is running");
-	nmcs_wait_for_objects_register (nmc);
-	nmcs_wait_for_objects_register (nm_client_get_context_busy_watcher (nmc));
-
-	data->nmc = g_steal_pointer (&nmc);
-out:
-	g_main_loop_quit (data->main_loop);
-}
-
-static NMClient *
-_nmc_create (GCancellable *sigterm_cancellable)
-{
-	nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new (NULL, FALSE);
-	ClientCreateData data = {
-		.main_loop = main_loop,
-	};
-
-	nm_client_new_async (sigterm_cancellable, _nmc_create_cb, &data);
-
-	g_main_loop_run (main_loop);
-
-	return data.nmc;
-}
-
-/*****************************************************************************/
-
 static char **
 _nmc_get_hwaddrs (NMClient *nmc)
 {
@@ -270,7 +219,7 @@ _get_config_cb (GObject *source,
 	config_dict = nmcs_provider_get_config_finish (NMCS_PROVIDER (source), result, &error);
 
 	if (!config_dict) {
-		if (!nm_utils_error_is_cancelled (error, FALSE))
+		if (!nm_utils_error_is_cancelled (error))
 			_LOGI ("failure to get meta data: %s", error->message);
 	} else
 		_LOGD ("meta data received");
@@ -386,7 +335,7 @@ _nmc_mangle_connection (NMDevice *device,
 		entry = nm_ip_routing_rule_new (AF_INET);
 		nm_ip_routing_rule_set_priority (entry, rt_table);
 		nm_ip_routing_rule_set_from (entry,
-		                             nm_utils_inet4_ntop (config_data->ipv4s_arr[i], sbuf),
+		                             _nm_utils_inet4_ntop (config_data->ipv4s_arr[i], sbuf),
 		                             32);
 		nm_ip_routing_rule_set_table (entry, rt_table);
 
@@ -477,7 +426,7 @@ try_again:
 	                                                         &applied_version_id,
 	                                                         &error);
 	if (!applied_connection) {
-		if (!nm_utils_error_is_cancelled (error, FALSE))
+		if (!nm_utils_error_is_cancelled (error))
 			_LOGD ("config device %s: device has no applied connection (%s). Skip", hwaddr, error->message);
 		return any_changes;
 	}
@@ -528,7 +477,7 @@ try_again:
 			goto try_again;
 		}
 
-		if (!nm_utils_error_is_cancelled (error, FALSE)) {
+		if (!nm_utils_error_is_cancelled (error)) {
 			_LOGD ("config device %s: failure to reapply connection \"%s\" (%s): %s",
 			       hwaddr,
 			       nm_connection_get_id (applied_connection),
@@ -593,6 +542,7 @@ main (int argc, const char *const*argv)
 	gs_unref_object NMCSProvider *provider = NULL;
 	gs_unref_object NMClient *nmc = NULL;
 	gs_unref_hashtable GHashTable *config_dict = NULL;
+	gs_free_error GError *error = NULL;
 
 	_nm_logging_enabled_init (g_getenv (NMCS_ENV_VARIABLE ("NM_CLOUD_SETUP_LOG")));
 
@@ -616,9 +566,25 @@ main (int argc, const char *const*argv)
 	if (!provider)
 		goto done;
 
-	nmc = _nmc_create (sigterm_cancellable);
-	if (!nmc)
+	nmc_client_new_waitsync (sigterm_cancellable,
+	                         &nmc,
+	                         &error,
+	                         NM_CLIENT_INSTANCE_FLAGS, (guint) NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS,
+	                         NULL);
+
+	nmcs_wait_for_objects_register (nmc);
+	nmcs_wait_for_objects_register (nm_client_get_context_busy_watcher (nmc));
+
+	if (error) {
+		if (!nm_utils_error_is_cancelled (error))
+			_LOGI ("failure to talk to NetworkManager: %s", error->message);
 		goto done;
+	}
+
+	if (!nm_client_get_nm_running (nmc)) {
+		_LOGI ("NetworkManager is not running");
+		goto done;
+	}
 
 	config_dict = _get_config (sigterm_cancellable, provider, nmc);
 	if (!config_dict)