diff options
author | Thomas Haller <thaller@redhat.com> | 2021-03-29 09:06:50 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-03-29 18:33:31 +0200 |
commit | 89a6671e5fff8d245f5a9d5ad98fb4e7bea880c4 (patch) | |
tree | 2a63d1fe6dafba8b8a5b3e49d3a73a2d2e2bd40a | |
parent | 1f890f5831099bb04a50f9f09622c966884e7070 (diff) | |
download | NetworkManager-89a6671e5fff8d245f5a9d5ad98fb4e7bea880c4.tar.gz |
libnm: cleanup handling of cancellation for initializing NMClient
-rw-r--r-- | src/libnm-client-impl/nm-client.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/libnm-client-impl/nm-client.c b/src/libnm-client-impl/nm-client.c index 211bc21a84..19847cc353 100644 --- a/src/libnm-client-impl/nm-client.c +++ b/src/libnm-client-impl/nm-client.c @@ -7263,12 +7263,20 @@ _init_start_check_complete(NMClient *self) static void _init_start_cancelled_cb(GCancellable *cancellable, gpointer user_data) { - NMClient *self = user_data; - GError * error; + NMClient * self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); + GError * error; nm_assert(NM_IS_CLIENT(self)); - nm_assert(NM_CLIENT_GET_PRIVATE(self)->init_data); - nm_assert(NM_CLIENT_GET_PRIVATE(self)->init_data->cancellable == cancellable); + nm_assert(priv->init_data); + nm_assert(priv->init_data->cancellable == cancellable); + + if (priv->init_data->cancelled_id == 0) { + /* this only can happen if the cancellable was already cancelled initially. + * In this case we are called synchronously. Do nothing, and let the caller + * handle it. */ + return; + } nm_utils_error_set_cancelled(&error, FALSE, NULL); _init_start_complete(self, error); @@ -7291,19 +7299,20 @@ _init_start_with_bus(NMClient *self) NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); if (priv->init_data->cancellable) { - priv->init_data->cancelled_id = g_signal_connect(priv->init_data->cancellable, - "cancelled", - G_CALLBACK(_init_start_cancelled_cb), - self); - if (g_cancellable_is_cancelled(priv->init_data->cancellable)) { - priv->init_data->cancel_on_idle_source = g_idle_source_new(); - g_source_set_callback(priv->init_data->cancel_on_idle_source, - _init_start_cancel_on_idle_cb, - self, - NULL); + gulong id; + + id = g_cancellable_connect(priv->init_data->cancellable, + G_CALLBACK(_init_start_cancelled_cb), + self, + NULL); + if (id == 0) { + priv->init_data->cancel_on_idle_source = + nm_g_idle_source_new(G_PRIORITY_DEFAULT, _init_start_cancel_on_idle_cb, self, NULL); g_source_attach(priv->init_data->cancel_on_idle_source, priv->main_context); return; } + + priv->init_data->cancelled_id = id; } _assert_main_context_is_current_thread_default(self, dbus_context); |