diff options
Diffstat (limited to 'clients/cloud-setup/main.c')
-rw-r--r-- | clients/cloud-setup/main.c | 75 |
1 files changed, 20 insertions, 55 deletions
diff --git a/clients/cloud-setup/main.c b/clients/cloud-setup/main.c index 8250945c47..2ba10285b6 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" @@ -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) { @@ -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,24 @@ 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, + 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, FALSE)) + _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) |