diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-06 13:52:29 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-12-10 09:17:17 +0100 |
commit | c5c7fffda839a9aa0a013a482d55d2386814b120 (patch) | |
tree | 854a179b5f8edf007b09bb0ca25daca237a35631 | |
parent | b6c83d18e439d5221e75d99f1b6f3b77d00d2ff1 (diff) | |
download | NetworkManager-c5c7fffda839a9aa0a013a482d55d2386814b120.tar.gz |
cloud-setup: reuse nmc_client_new_waitsync() to create NMClient instance
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | clients/cloud-setup/main.c | 75 | ||||
-rw-r--r-- | clients/cloud-setup/meson.build | 13 |
3 files changed, 27 insertions, 62 deletions
diff --git a/Makefile.am b/Makefile.am index 6c29e44ff2..4f690a5c0e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4707,6 +4707,7 @@ clients_cloud_setup_nm_cloud_setup_LDFLAGS = \ $(NULL) clients_cloud_setup_nm_cloud_setup_LDADD = \ + shared/nm-libnm-aux/libnm-libnm-aux.la \ shared/nm-libnm-core-aux/libnm-libnm-core-aux.la \ shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \ shared/nm-glib-aux/libnm-glib-aux.la \ 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) diff --git a/clients/cloud-setup/meson.build b/clients/cloud-setup/meson.build index e9cd970a36..b0a6191c46 100644 --- a/clients/cloud-setup/meson.build +++ b/clients/cloud-setup/meson.build @@ -29,16 +29,15 @@ sources = files( 'nmcs-provider.c', ) -deps = [ - libnmc_base_dep, - libnmc_dep, - libcurl_dep, -] - executable( name, sources, - dependencies: deps, + dependencies: [ + libnmc_base_dep, + libnmc_dep, + libcurl_dep, + libnm_libnm_aux_dep, + ], c_args: clients_c_flags + ['-DG_LOG_DOMAIN="@0@"'.format(name)], link_with: libnm_systemd_logging_stub, |