mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
cloud-setup: reuse nmc_client_new_waitsync() to create NMClient instance
This commit is contained in:
parent
b6c83d18e4
commit
c5c7fffda8
|
@ -4707,6 +4707,7 @@ clients_cloud_setup_nm_cloud_setup_LDFLAGS = \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
clients_cloud_setup_nm_cloud_setup_LDADD = \
|
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-aux/libnm-libnm-core-aux.la \
|
||||||
shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \
|
shared/nm-libnm-core-intern/libnm-libnm-core-intern.la \
|
||||||
shared/nm-glib-aux/libnm-glib-aux.la \
|
shared/nm-glib-aux/libnm-glib-aux.la \
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
#include "nm-default.h"
|
#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 "nmcs-provider-ec2.h"
|
||||||
#include "nm-libnm-core-intern/nm-libnm-core-utils.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 **
|
static char **
|
||||||
_nmc_get_hwaddrs (NMClient *nmc)
|
_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 NMCSProvider *provider = NULL;
|
||||||
gs_unref_object NMClient *nmc = NULL;
|
gs_unref_object NMClient *nmc = NULL;
|
||||||
gs_unref_hashtable GHashTable *config_dict = 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")));
|
_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)
|
if (!provider)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
nmc = _nmc_create (sigterm_cancellable);
|
nmc_client_new_waitsync (sigterm_cancellable,
|
||||||
if (!nmc)
|
&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;
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nm_client_get_nm_running (nmc)) {
|
||||||
|
_LOGI ("NetworkManager is not running");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
config_dict = _get_config (sigterm_cancellable, provider, nmc);
|
config_dict = _get_config (sigterm_cancellable, provider, nmc);
|
||||||
if (!config_dict)
|
if (!config_dict)
|
||||||
|
|
|
@ -29,16 +29,15 @@ sources = files(
|
||||||
'nmcs-provider.c',
|
'nmcs-provider.c',
|
||||||
)
|
)
|
||||||
|
|
||||||
deps = [
|
|
||||||
libnmc_base_dep,
|
|
||||||
libnmc_dep,
|
|
||||||
libcurl_dep,
|
|
||||||
]
|
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
name,
|
name,
|
||||||
sources,
|
sources,
|
||||||
dependencies: deps,
|
dependencies: [
|
||||||
|
libnmc_base_dep,
|
||||||
|
libnmc_dep,
|
||||||
|
libcurl_dep,
|
||||||
|
libnm_libnm_aux_dep,
|
||||||
|
],
|
||||||
c_args: clients_c_flags +
|
c_args: clients_c_flags +
|
||||||
['-DG_LOG_DOMAIN="@0@"'.format(name)],
|
['-DG_LOG_DOMAIN="@0@"'.format(name)],
|
||||||
link_with: libnm_systemd_logging_stub,
|
link_with: libnm_systemd_logging_stub,
|
||||||
|
|
Loading…
Reference in a new issue