From 294c62a589326c8dbf92ead2489f41209b4fffcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Sat, 5 May 2018 22:17:24 +0100 Subject: [PATCH] glib: ported to GTask API GLib version bumbed to 2.36 --- configure.ac | 2 +- src/polkit/polkitauthority.c | 271 ++++++++++-------- src/polkit/polkitpermission.c | 186 +++++------- src/polkit/polkitsystembusname.c | 51 ++-- src/polkit/polkitunixprocess.c | 19 +- src/polkit/polkitunixsession-systemd.c | 56 ++-- src/polkit/polkitunixsession.c | 46 ++- src/polkitagent/polkitagenttextlistener.c | 58 ++-- src/polkitbackend/polkitbackendauthority.c | 21 +- .../polkitbackendinteractiveauthority.c | 91 +++--- .../polkitbackendjsauthority.cpp | 48 ++-- 11 files changed, 393 insertions(+), 456 deletions(-) diff --git a/configure.ac b/configure.ac index 36df239..a813e6b 100644 --- a/configure.ac +++ b/configure.ac @@ -75,7 +75,7 @@ CC_CHECK_FLAGS_APPEND([WARN_CFLAGS], [CFLAGS], [\ ]) AC_SUBST(WARN_CFLAGS) -PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) +PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.36.0]) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c index 71d527c..791fdf4 100644 --- a/src/polkit/polkitauthority.c +++ b/src/polkit/polkitauthority.c @@ -425,27 +425,21 @@ authority_get_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); - GError *error; + GTask *task = G_TASK (user_data); + GError *error = NULL; - error = NULL; if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object), res, &error)) { g_assert (error != NULL); - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); + g_task_return_error (task, error); g_object_unref (source_object); } else - { - g_simple_async_result_set_op_res_gpointer (simple, - source_object, - g_object_unref); - } - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); + g_task_return_pointer (task, source_object, g_object_unref); + + g_object_unref (task); } /** @@ -469,25 +463,23 @@ polkit_authority_get_async (GCancellable *cancellable, gpointer user_data) { PolkitAuthority *authority; - GSimpleAsyncResult *simple; - GError *error; + GTask *task; + GError *error = NULL; g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - simple = g_simple_async_result_new (NULL, - callback, - user_data, - polkit_authority_get_async); + task = g_task_new (NULL, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_get_async); - error = NULL; authority = get_uninitialized_authority (cancellable, &error); if (authority == NULL) { g_assert (error != NULL); - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); + g_task_return_error (task, error); + g_object_unref (task); } else { @@ -495,7 +487,7 @@ polkit_authority_get_async (GCancellable *cancellable, G_PRIORITY_DEFAULT, cancellable, authority_get_async_cb, - simple); + task); } } @@ -513,24 +505,21 @@ PolkitAuthority * polkit_authority_get_finish (GAsyncResult *res, GError **error) { - GSimpleAsyncResult *simple; + GTask *task; GObject *object; - PolkitAuthority *ret; + PolkitAuthority *ret = NULL; - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); + g_return_val_if_fail (G_IS_TASK (res), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - simple = G_SIMPLE_ASYNC_RESULT (res); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_get_async); + task = G_TASK (res); - ret = NULL; + g_warn_if_fail (g_task_get_source_tag (task) == polkit_authority_get_async); - if (g_simple_async_result_propagate_error (simple, error)) + object = g_task_propagate_pointer (task, error); + if (object == NULL) goto out; - object = g_simple_async_result_get_op_res_gpointer (simple); - g_assert (object != NULL); ret = g_object_ref (POLKIT_AUTHORITY (object)); out: @@ -627,10 +616,9 @@ generic_async_cb (GObject *source_obj, GAsyncResult *res, gpointer user_data) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); - g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (res), g_object_unref); - g_simple_async_result_complete (simple); - g_object_unref (simple); + GTask *task = G_TASK (user_data); + g_task_return_pointer (task, g_object_ref (res), g_object_unref); + g_object_unref (task); } /* ---------------------------------------------------------------------------------------------------- */ @@ -656,8 +644,17 @@ polkit_authority_enumerate_actions (PolkitAuthority *authority, GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_enumerate_actions); + g_dbus_proxy_call (authority->proxy, "EnumerateActions", g_variant_new ("(s)", @@ -666,10 +663,7 @@ polkit_authority_enumerate_actions (PolkitAuthority *authority, -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_enumerate_actions)); + task); } /** @@ -698,13 +692,15 @@ polkit_authority_enumerate_actions_finish (PolkitAuthority *authority, GAsyncResult *_res; g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); + g_return_val_if_fail (G_IS_TASK (res), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); ret = NULL; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_enumerate_actions); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_enumerate_actions); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) @@ -766,7 +762,7 @@ polkit_authority_enumerate_actions_sync (PolkitAuthority *authority, typedef struct { PolkitAuthority *authority; - GSimpleAsyncResult *simple; + GTask *task; gchar *cancellation_id; } CheckAuthData; @@ -818,8 +814,7 @@ check_authorization_cb (GDBusProxy *proxy, (GAsyncReadyCallback) cancel_check_authorization_cb, NULL); } - g_simple_async_result_set_from_error (data->simple, error); - g_error_free (error); + g_task_return_error (data->task, error); } else { @@ -829,13 +824,11 @@ check_authorization_cb (GDBusProxy *proxy, result = polkit_authorization_result_new_for_gvariant (result_value); g_variant_unref (result_value); g_variant_unref (value); - g_simple_async_result_set_op_res_gpointer (data->simple, result, g_object_unref); + g_task_return_pointer (data->task, result, g_object_unref); } - g_simple_async_result_complete (data->simple); - g_object_unref (data->authority); - g_object_unref (data->simple); + g_object_unref (data->task); g_free (data->cancellation_id); g_free (data); } @@ -896,10 +889,11 @@ polkit_authority_check_authorization (PolkitAuthority *authority, data = g_new0 (CheckAuthData, 1); data->authority = g_object_ref (authority); - data->simple = g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_check_authorization); + data->task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (data->task, polkit_authority_check_authorization); G_LOCK (the_lock); if (cancellable != NULL) data->cancellation_id = g_strdup_printf ("cancellation-id-%d", authority->cancellation_id_counter++); @@ -936,21 +930,15 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority GAsyncResult *res, GError **error) { - PolkitAuthorizationResult *ret; + PolkitAuthorizationResult *ret = NULL; g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); + g_return_val_if_fail (G_IS_TASK (res), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - ret = NULL; - - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) - goto out; - - ret = g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); - - out: - return ret; + ret = g_task_propagate_pointer (G_TASK (res), error); + if (ret != NULL) + return g_object_ref (ret); } /** @@ -1049,12 +1037,20 @@ polkit_authority_register_authentication_agent (PolkitAuthority *authority, GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (POLKIT_IS_SUBJECT (subject)); g_return_if_fail (locale != NULL); g_return_if_fail (g_variant_is_object_path (object_path)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_register_authentication_agent); + g_dbus_proxy_call (authority->proxy, "RegisterAuthenticationAgent", g_variant_new ("(@(sa{sv})ss)", @@ -1065,10 +1061,7 @@ polkit_authority_register_authentication_agent (PolkitAuthority *authority, -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_register_authentication_agent)); + task); } /** @@ -1086,7 +1079,7 @@ polkit_authority_register_authentication_agent_finish (PolkitAuthority *authorit GAsyncResult *res, GError **error) { - gboolean ret; + gboolean ret = FALSE; GVariant *value; GAsyncResult *_res; @@ -1094,14 +1087,15 @@ polkit_authority_register_authentication_agent_finish (PolkitAuthority *authorit g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - ret = FALSE; - - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_register_authentication_agent); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_register_authentication_agent); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) goto out; + ret = TRUE; g_variant_unref (value); @@ -1196,6 +1190,7 @@ polkit_authority_register_authentication_agent_with_options (PolkitAuthority gpointer user_data) { GVariant *subject_value; + GTask *task; g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (POLKIT_IS_SUBJECT (subject)); @@ -1205,6 +1200,11 @@ polkit_authority_register_authentication_agent_with_options (PolkitAuthority subject_value = polkit_subject_to_gvariant (subject); g_variant_ref_sink (subject_value); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_register_authentication_agent_with_options); if (options != NULL) { g_dbus_proxy_call (authority->proxy, @@ -1218,10 +1218,7 @@ polkit_authority_register_authentication_agent_with_options (PolkitAuthority -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_register_authentication_agent_with_options)); + task); } else { @@ -1235,10 +1232,7 @@ polkit_authority_register_authentication_agent_with_options (PolkitAuthority -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_register_authentication_agent_with_options)); + task); } g_variant_unref (subject_value); } @@ -1263,13 +1257,15 @@ polkit_authority_register_authentication_agent_with_options_finish (PolkitAuthor GAsyncResult *_res; g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); + g_return_val_if_fail (G_IS_TASK (res), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); ret = FALSE; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_register_authentication_agent_with_options); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_register_authentication_agent_with_options); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) @@ -1361,11 +1357,18 @@ polkit_authority_unregister_authentication_agent (PolkitAuthority *authorit GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (POLKIT_IS_SUBJECT (subject)); g_return_if_fail (g_variant_is_object_path (object_path)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_unregister_authentication_agent); g_dbus_proxy_call (authority->proxy, "UnregisterAuthenticationAgent", g_variant_new ("(@(sa{sv})s)", @@ -1375,10 +1378,7 @@ polkit_authority_unregister_authentication_agent (PolkitAuthority *authorit -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_unregister_authentication_agent)); + task); } /** @@ -1401,17 +1401,20 @@ polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *author GAsyncResult *_res; g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); + g_return_val_if_fail (G_IS_TASK (res), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); ret = FALSE; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_unregister_authentication_agent); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_unregister_authentication_agent); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) goto out; + ret = TRUE; g_variant_unref (value); @@ -1492,6 +1495,7 @@ polkit_authority_authentication_agent_response (PolkitAuthority *authority, GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; /* Note that in reality, this API is only accessible to root, and * only called from the setuid helper `polkit-agent-helper-1`. * @@ -1506,6 +1510,12 @@ polkit_authority_authentication_agent_response (PolkitAuthority *authority, g_return_if_fail (POLKIT_IS_IDENTITY (identity)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_authentication_agent_response); + g_dbus_proxy_call (authority->proxy, "AuthenticationAgentResponse2", g_variant_new ("(us@(sa{sv}))", @@ -1516,10 +1526,7 @@ polkit_authority_authentication_agent_response (PolkitAuthority *authority, -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_authentication_agent_response)); + task); } /** @@ -1542,17 +1549,20 @@ polkit_authority_authentication_agent_response_finish (PolkitAuthority *authorit GAsyncResult *_res; g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); + g_return_val_if_fail (G_IS_TASK (res), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); ret = FALSE; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_authentication_agent_response); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_authentication_agent_response); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) goto out; + ret = TRUE; g_variant_unref (value); @@ -1630,10 +1640,18 @@ polkit_authority_enumerate_temporary_authorizations (PolkitAuthority *author GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (POLKIT_IS_SUBJECT (subject)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_enumerate_temporary_authorizations); + g_dbus_proxy_call (authority->proxy, "EnumerateTemporaryAuthorizations", g_variant_new ("(@(sa{sv}))", @@ -1642,10 +1660,7 @@ polkit_authority_enumerate_temporary_authorizations (PolkitAuthority *author -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_enumerate_temporary_authorizations)); + task); } /** @@ -1679,8 +1694,10 @@ polkit_authority_enumerate_temporary_authorizations_finish (PolkitAuthority *aut ret = NULL; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_enumerate_temporary_authorizations); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_enumerate_temporary_authorizations); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) @@ -1779,10 +1796,18 @@ polkit_authority_revoke_temporary_authorizations (PolkitAuthority *authority GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (POLKIT_IS_SUBJECT (subject)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_revoke_temporary_authorizations); + g_dbus_proxy_call (authority->proxy, "RevokeTemporaryAuthorizations", g_variant_new ("(@(sa{sv}))", @@ -1791,10 +1816,7 @@ polkit_authority_revoke_temporary_authorizations (PolkitAuthority *authority -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_revoke_temporary_authorizations)); + task); } /** @@ -1822,12 +1844,15 @@ polkit_authority_revoke_temporary_authorizations_finish (PolkitAuthority *author ret = FALSE; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_revoke_temporary_authorizations); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_revoke_temporary_authorizations); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) goto out; + ret = TRUE; g_variant_unref (value); @@ -1899,10 +1924,18 @@ polkit_authority_revoke_temporary_authorization_by_id (PolkitAuthority *auth GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; + g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); g_return_if_fail (id != NULL); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_authority_revoke_temporary_authorization_by_id); + g_dbus_proxy_call (authority->proxy, "RevokeTemporaryAuthorizationById", g_variant_new ("(s)", @@ -1911,10 +1944,7 @@ polkit_authority_revoke_temporary_authorization_by_id (PolkitAuthority *auth -1, cancellable, generic_async_cb, - g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_revoke_temporary_authorization_by_id)); + task); } /** @@ -1942,12 +1972,15 @@ polkit_authority_revoke_temporary_authorization_by_id_finish (PolkitAuthority *a ret = FALSE; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_revoke_temporary_authorization_by_id); - _res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); + g_warn_if_fail (g_task_get_source_tag (G_TASK (res)) == polkit_authority_revoke_temporary_authorization_by_id); + _res = G_ASYNC_RESULT (g_task_propagate_pointer (G_TASK (res), error)); + if (_res == NULL) + goto out; value = g_dbus_proxy_call_finish (authority->proxy, _res, error); if (value == NULL) goto out; + ret = TRUE; g_variant_unref (value); diff --git a/src/polkit/polkitpermission.c b/src/polkit/polkitpermission.c index f264094..a57b3c3 100644 --- a/src/polkit/polkitpermission.c +++ b/src/polkit/polkitpermission.c @@ -515,30 +515,18 @@ process_result (PolkitPermission *permission, /* ---------------------------------------------------------------------------------------------------- */ -typedef struct -{ - PolkitPermission *permission; - GSimpleAsyncResult *simple; -} AcquireData; - -static void -acquire_data_free (AcquireData *data) -{ - g_object_unref (data->simple); - g_free (data); -} - static void acquire_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - AcquireData *data = user_data; + GTask *task = G_TASK (user_data); + PolkitPermission *permission; PolkitAuthorizationResult *result; - GError *error; + GError *error = NULL; - error = NULL; - result = polkit_authority_check_authorization_finish (data->permission->authority, + permission = g_task_get_task_data (task); + result = polkit_authority_check_authorization_finish (permission->authority, res, &error); if (result != NULL) @@ -547,38 +535,40 @@ acquire_cb (GObject *source_object, * can_release are updated before returning to the user - see * also release_cb for where we do this as well */ - process_result (data->permission, result); + process_result (permission, result); if (!polkit_authorization_result_get_is_authorized (result)) { if (polkit_authorization_result_get_dismissed (result)) { - g_simple_async_result_set_error (data->simple, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - "User dismissed authentication dialog while trying to acquire permission for action-id %s", - data->permission->action_id); + g_task_return_new_error (task, + G_IO_ERROR, + G_IO_ERROR_CANCELLED, + "User dismissed authentication dialog while trying to acquire permission for action-id %s", + permission->action_id); + goto out; } else { - g_simple_async_result_set_error (data->simple, - POLKIT_ERROR, - POLKIT_ERROR_FAILED, - "Failed to acquire permission for action-id %s", - data->permission->action_id); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "Failed to acquire permission for action-id %s", + permission->action_id); + goto out; } } g_object_unref (result); } else { - g_simple_async_result_set_from_error (data->simple, error); - g_error_free (error); + g_task_return_error (task, error); + goto out; } - /* don't complete in idle since we're already completing in idle - * due to how PolkitAuthority works - */ - g_simple_async_result_complete (data->simple); - acquire_data_free (data); + + g_task_return_boolean (task, TRUE); + + out: + g_object_unref (task); } static void @@ -588,14 +578,11 @@ acquire_async (GPermission *gpermission, gpointer user_data) { PolkitPermission *permission = POLKIT_PERMISSION (gpermission); - AcquireData *data; - - data = g_new0 (AcquireData, 1); - data->permission = permission; - data->simple = g_simple_async_result_new (G_OBJECT (permission), - callback, - user_data, - acquire_async); + GTask *task = g_task_new (permission, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, acquire_async); polkit_authority_check_authorization (permission->authority, permission->subject, @@ -604,7 +591,7 @@ acquire_async (GPermission *gpermission, POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, cancellable, acquire_cb, - data); + task); } static gboolean @@ -612,15 +599,12 @@ acquire_finish (GPermission *gpermission, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + GTask *task; - simple = G_SIMPLE_ASYNC_RESULT (result); - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == acquire_async); + task = G_TASK (result); + g_warn_if_fail (g_task_get_source_tag (task) == acquire_async); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean (task, error); } static gboolean @@ -673,50 +657,40 @@ acquire (GPermission *gpermission, /* ---------------------------------------------------------------------------------------------------- */ -typedef struct -{ - PolkitPermission *permission; - GSimpleAsyncResult *simple; -} ReleaseData; - -static void -release_data_free (ReleaseData *data) -{ - g_object_unref (data->simple); - g_free (data); -} - static void release_check_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - ReleaseData *data = user_data; + GTask *task = user_data; + PolkitPermission *permission = g_task_get_source_object (task); PolkitAuthorizationResult *result; GError *error; error = NULL; - result = polkit_authority_check_authorization_finish (data->permission->authority, + result = polkit_authority_check_authorization_finish (permission->authority, res, &error); if (result == NULL) { g_prefix_error (&error, "Error checking authorization for action id %s after releasing the permission: ", - data->permission->action_id); - g_simple_async_result_set_from_error (data->simple, error); - g_error_free (error); + permission->action_id); + g_task_return_error (task, error); + goto out; } else { - process_result (data->permission, result); + process_result (permission, result); g_object_unref (result); } /* don't complete in idle since we're already completing in idle * due to how PolkitAuthority works */ - g_simple_async_result_complete (data->simple); - release_data_free (data); + g_task_return_boolean (task, TRUE); + + out: + g_object_unref (task); } static void @@ -724,25 +698,18 @@ release_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - ReleaseData *data = user_data; - GError *error; - gboolean ret; + GTask *task = user_data; + PolkitPermission *permission = g_task_get_source_object (task); + GError *error = NULL; + gboolean ret = FALSE; - ret = FALSE; - - error = NULL; - ret = polkit_authority_revoke_temporary_authorization_by_id_finish (data->permission->authority, + ret = polkit_authority_revoke_temporary_authorization_by_id_finish (permission->authority, res, &error); if (!ret) { - g_simple_async_result_set_from_error (data->simple, error); - g_error_free (error); - /* don't complete in idle since we're already completing in idle - * due to how PolkitAuthority works - */ - g_simple_async_result_complete (data->simple); - release_data_free (data); + g_task_return_error (task, error); + g_object_unref (task); } else { @@ -750,14 +717,14 @@ release_cb (GObject *source_object, * returning to the user - see also acquire_cb where we do this * as well */ - polkit_authority_check_authorization (data->permission->authority, - data->permission->subject, - data->permission->action_id, + polkit_authority_check_authorization (permission->authority, + permission->subject, + permission->action_id, NULL, /* PolkitDetails */ POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, NULL /* cancellable */, release_check_cb, - data); + task); } } @@ -767,25 +734,23 @@ release_async (GPermission *gpermission, GAsyncReadyCallback callback, gpointer user_data) { + GTask *task; PolkitPermission *permission = POLKIT_PERMISSION (gpermission); - ReleaseData *data; - data = g_new0 (ReleaseData, 1); - data->permission = permission; - data->simple = g_simple_async_result_new (G_OBJECT (permission), - callback, - user_data, - release_async); + task = g_task_new (permission, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, release_async); if (permission->tmp_authz_id == NULL) { - g_simple_async_result_set_error (data->simple, - POLKIT_ERROR, - POLKIT_ERROR_FAILED, - "Cannot release permission: no temporary authorization for action-id %s exist", - permission->action_id); - g_simple_async_result_complete_in_idle (data->simple); - release_data_free (data); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "Cannot release permission: no temporary authorization for action-id %s exist", + permission->action_id); + g_object_unref (task); goto out; } @@ -793,7 +758,7 @@ release_async (GPermission *gpermission, permission->tmp_authz_id, cancellable, release_cb, - data); + task); out: ; } @@ -803,15 +768,12 @@ release_finish (GPermission *gpermission, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - simple = G_SIMPLE_ASYNC_RESULT (result); - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == release_async); + GTask *task; - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; + task = G_TASK (result); + g_warn_if_fail (g_task_get_source_tag (task) == release_async); - return TRUE; + return g_task_propagate_boolean (task, error); } static gboolean diff --git a/src/polkit/polkitsystembusname.c b/src/polkit/polkitsystembusname.c index 8daa12c..aa92d63 100644 --- a/src/polkit/polkitsystembusname.c +++ b/src/polkit/polkitsystembusname.c @@ -271,19 +271,24 @@ polkit_system_bus_name_exists_sync (PolkitSubject *subject, } static void -exists_in_thread_func (GSimpleAsyncResult *res, - GObject *object, - GCancellable *cancellable) +exists_in_thread_func (GTask *task, + gpointer source_object, + gpointer task_data, + GCancellable *cancellable) { - GError *error; - error = NULL; - if (!polkit_system_bus_name_exists_sync (POLKIT_SUBJECT (object), + GError *error = NULL; + + g_assert (POLKIT_IS_SUBJECT (source_object)); + + if (!polkit_system_bus_name_exists_sync (POLKIT_SUBJECT (source_object), cancellable, &error)) { - g_simple_async_result_set_from_error (res, error); - g_error_free (error); + g_task_return_error (task, error); + return; } + + g_task_return_boolean (task, TRUE); } static void @@ -292,19 +297,14 @@ polkit_system_bus_name_exists (PolkitSubject *subject, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; + GTask *task; g_return_if_fail (POLKIT_IS_SYSTEM_BUS_NAME (subject)); - simple = g_simple_async_result_new (G_OBJECT (subject), - callback, - user_data, - polkit_system_bus_name_exists); - g_simple_async_result_run_in_thread (simple, - exists_in_thread_func, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref (simple); + task = g_task_new (subject, cancellable, callback, user_data); + g_task_set_source_tag (task, polkit_system_bus_name_exists); + g_task_run_in_thread (task, exists_in_thread_func); + g_object_unref (task); } static gboolean @@ -312,20 +312,11 @@ polkit_system_bus_name_exists_finish (PolkitSubject *subject, GAsyncResult *res, GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); - gboolean ret; - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_system_bus_name_exists); + GTask *task = G_TASK (res); - ret = FALSE; + g_warn_if_fail (g_task_get_source_tag (task) == polkit_system_bus_name_exists); - if (g_simple_async_result_propagate_error (simple, error)) - goto out; - - ret = g_simple_async_result_get_op_res_gboolean (simple); - - out: - return ret; + return g_task_propagate_boolean (task, error); } static void diff --git a/src/polkit/polkitunixprocess.c b/src/polkit/polkitunixprocess.c index d4ebf50..f292c9b 100644 --- a/src/polkit/polkitunixprocess.c +++ b/src/polkit/polkitunixprocess.c @@ -489,13 +489,14 @@ polkit_unix_process_exists (PolkitSubject *subject, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - simple = g_simple_async_result_new (G_OBJECT (subject), - callback, - user_data, - polkit_unix_process_exists); - g_simple_async_result_complete (simple); - g_object_unref (simple); + GTask *task; + task = g_task_new (subject, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_unix_process_exists); + g_task_return_boolean (task, TRUE); + g_object_unref (task); } static gboolean @@ -503,9 +504,9 @@ polkit_unix_process_exists_finish (PolkitSubject *subject, GAsyncResult *res, GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); + GTask *task = G_TASK (res); - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_process_exists); + g_warn_if_fail (g_task_get_source_tag (task) == polkit_unix_process_exists); return polkit_unix_process_exists_sync (subject, NULL, diff --git a/src/polkit/polkitunixsession-systemd.c b/src/polkit/polkitunixsession-systemd.c index c34f36a..0451757 100644 --- a/src/polkit/polkitunixsession-systemd.c +++ b/src/polkit/polkitunixsession-systemd.c @@ -375,19 +375,18 @@ polkit_unix_session_exists_sync (PolkitSubject *subject, } static void -exists_in_thread_func (GSimpleAsyncResult *res, - GObject *object, - GCancellable *cancellable) +exists_in_thread_func (GTask *task, + gpointer source_object, + gpointer task_data, + GCancellable *cancellable) { - GError *error; - error = NULL; - if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object), + GError *error = NULL; + if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (source_object), cancellable, &error)) - { - g_simple_async_result_set_from_error (res, error); - g_error_free (error); - } + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); } static void @@ -396,40 +395,29 @@ polkit_unix_session_exists (PolkitSubject *subject, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; + GTask *task; g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject)); - simple = g_simple_async_result_new (G_OBJECT (subject), - callback, - user_data, - polkit_unix_session_exists); - g_simple_async_result_run_in_thread (simple, - exists_in_thread_func, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref (simple); + task = g_task_new (subject, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_unix_session_exists); + g_task_run_in_thread (task, exists_in_thread_func); + g_object_unref (task); } static gboolean polkit_unix_session_exists_finish (PolkitSubject *subject, - GAsyncResult *res, - GError **error) + GAsyncResult *res, + GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); - gboolean ret; - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists); + GTask *task = G_TASK (res); - ret = FALSE; + g_warn_if_fail (g_task_get_source_tag (task) == polkit_unix_session_exists); - if (g_simple_async_result_propagate_error (simple, error)) - goto out; - - ret = g_simple_async_result_get_op_res_gboolean (simple); - - out: - return ret; + return g_task_propagate_boolean (task, error); } static void diff --git a/src/polkit/polkitunixsession.c b/src/polkit/polkitunixsession.c index 40817de..c6f85bc 100644 --- a/src/polkit/polkitunixsession.c +++ b/src/polkit/polkitunixsession.c @@ -396,18 +396,17 @@ polkit_unix_session_exists_sync (PolkitSubject *subject, } static void -exists_in_thread_func (GSimpleAsyncResult *res, - GObject *object, - GCancellable *cancellable) +exists_in_thread_func (GTask *task, + gpointer source_object, + gpointer task_data, + GCancellable *cancellable) { - GError *error; - error = NULL; + GError *error = NULL; if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object), cancellable, &error)) { - g_simple_async_result_set_from_error (res, error); - g_error_free (error); + g_task_return_error (task, error); } } @@ -417,19 +416,17 @@ polkit_unix_session_exists (PolkitSubject *subject, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; + GTask *task; g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject)); - simple = g_simple_async_result_new (G_OBJECT (subject), - callback, - user_data, - polkit_unix_session_exists); - g_simple_async_result_run_in_thread (simple, - exists_in_thread_func, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref (simple); + task = g_task_new (subject, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_unix_session_exists); + g_task_run_in_thread (simple, exists_in_thread_func); + g_object_unref (task); } static gboolean @@ -437,20 +434,11 @@ polkit_unix_session_exists_finish (PolkitSubject *subject, GAsyncResult *res, GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); - gboolean ret; - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists); - - ret = FALSE; + GTask *task = G_TASK (res); - if (g_simple_async_result_propagate_error (simple, error)) - goto out; - - ret = g_simple_async_result_get_op_res_gboolean (simple); + g_warn_if_fail (g_task_get_source_tag (task) == polkit_unix_session_exists); - out: - return ret; + return g_task_propagate_boolean (task, error); } static void diff --git a/src/polkitagent/polkitagenttextlistener.c b/src/polkitagent/polkitagenttextlistener.c index d864dfb..7678720 100644 --- a/src/polkitagent/polkitagenttextlistener.c +++ b/src/polkitagent/polkitagenttextlistener.c @@ -56,7 +56,7 @@ struct _PolkitAgentTextListener { PolkitAgentListener parent_instance; - GSimpleAsyncResult *simple; + GTask *task; PolkitAgentSession *active_session; gulong cancel_id; GCancellable *cancellable; @@ -212,14 +212,14 @@ on_completed (PolkitAgentSession *session, fprintf (listener->tty, "\x1B[0m"); fflush (listener->tty); - g_simple_async_result_complete_in_idle (listener->simple); + g_task_return_boolean (listener->task, gained_authorization); - g_object_unref (listener->simple); + g_object_unref (listener->task); g_object_unref (listener->active_session); g_cancellable_disconnect (listener->cancellable, listener->cancel_id); g_object_unref (listener->cancellable); - listener->simple = NULL; + listener->task = NULL; listener->active_session = NULL; listener->cancel_id = 0; } @@ -451,21 +451,21 @@ polkit_agent_text_listener_initiate_authentication (PolkitAgentListener *_liste gpointer user_data) { PolkitAgentTextListener *listener = POLKIT_AGENT_TEXT_LISTENER (_listener); - GSimpleAsyncResult *simple; + GTask *task; PolkitIdentity *identity; - simple = g_simple_async_result_new (G_OBJECT (listener), - callback, - user_data, - polkit_agent_text_listener_initiate_authentication); + task = g_task_new (listener, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_agent_text_listener_initiate_authentication); if (listener->active_session != NULL) { - g_simple_async_result_set_error (simple, - POLKIT_ERROR, - POLKIT_ERROR_FAILED, - "An authentication session is already underway."); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "An authentication session is already underway."); + g_object_unref (task); goto out; } @@ -490,12 +490,11 @@ polkit_agent_text_listener_initiate_authentication (PolkitAgentListener *_liste fprintf (listener->tty, "==== AUTHENTICATION CANCELED ====\n"); fprintf (listener->tty, "\x1B[0m"); fflush (listener->tty); - g_simple_async_result_set_error (simple, - POLKIT_ERROR, - POLKIT_ERROR_FAILED, - "Authentication was canceled."); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "Authentication was canceled."); + g_object_unref (task); goto out; } } @@ -528,7 +527,7 @@ polkit_agent_text_listener_initiate_authentication (PolkitAgentListener *_liste G_CALLBACK (on_show_error), listener); - listener->simple = simple; + listener->task = task; listener->cancellable = g_object_ref (cancellable); listener->cancel_id = g_cancellable_connect (cancellable, G_CALLBACK (on_cancelled), @@ -546,18 +545,11 @@ polkit_agent_text_listener_initiate_authentication_finish (PolkitAgentListener GAsyncResult *res, GError **error) { - gboolean ret; + GTask *task = (GTask *)res; - g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == + g_return_val_if_fail (G_IS_TASK (res), FALSE); + g_warn_if_fail (g_task_get_source_tag (task) == polkit_agent_text_listener_initiate_authentication); - ret = FALSE; - - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) - goto out; - - ret = TRUE; - - out: - return ret; + return g_task_propagate_boolean (task, error); } diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c index 0d1fac4..d668675 100644 --- a/src/polkitbackend/polkitbackendauthority.c +++ b/src/polkitbackend/polkitbackendauthority.c @@ -209,18 +209,19 @@ polkit_backend_authority_check_authorization (PolkitBackendAuthority *aut if (klass->check_authorization == NULL) { - GSimpleAsyncResult *simple; + GTask *task; g_warning ("check_authorization is not implemented (it is not optional)"); - simple = g_simple_async_result_new_error (G_OBJECT (authority), - callback, - user_data, - POLKIT_ERROR, - POLKIT_ERROR_NOT_SUPPORTED, - "Operation not supported (bug in backend)"); - g_simple_async_result_complete (simple); - g_object_unref (simple); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_NOT_SUPPORTED, + "Operation not supported (bug in backend)"); + g_object_unref (task); } else { @@ -250,7 +251,7 @@ polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *au if (klass->check_authorization_finish == NULL) { g_warning ("check_authorization_finish is not implemented (it is not optional)"); - g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); + g_task_propagate_boolean (G_TASK (res), error); return NULL; } else diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c index 1cd60d3..03528f9 100644 --- a/src/polkitbackend/polkitbackendinteractiveauthority.c +++ b/src/polkitbackend/polkitbackendinteractiveauthority.c @@ -626,7 +626,7 @@ check_authorization_challenge_cb (AuthenticationAgent *agent, PolkitIdentity *authenticated_identity, gpointer user_data) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); + GTask *task = G_TASK (user_data); PolkitBackendInteractiveAuthorityPrivate *priv; PolkitAuthorizationResult *result; gchar *scope_str; @@ -738,11 +738,8 @@ check_authorization_challenge_cb (AuthenticationAgent *agent, /* log_result (authority, action_id, subject, caller, result); */ - g_simple_async_result_set_op_res_gpointer (simple, - result, - g_object_unref); - g_simple_async_result_complete (simple); - g_object_unref (simple); + g_task_return_pointer (task, result, g_object_unref); + g_object_unref (task); g_free (subject_cmdline); g_free (authenticated_identity_str); @@ -756,22 +753,17 @@ polkit_backend_interactive_authority_check_authorization_finish (PolkitBackendAu GAsyncResult *res, GError **error) { - GSimpleAsyncResult *simple; - PolkitAuthorizationResult *result; - - simple = G_SIMPLE_ASYNC_RESULT (res); - - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_backend_interactive_authority_check_authorization); + GTask *task = (GTask *)res; + PolkitAuthorizationResult *result = NULL; - result = NULL; - - if (g_simple_async_result_propagate_error (simple, error)) - goto out; + g_return_val_if_fail (G_IS_TASK (task), NULL); + g_warn_if_fail (g_task_get_source_tag (task) == polkit_backend_interactive_authority_check_authorization); - result = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); + result = g_task_propagate_pointer (task, error); + if (result != NULL) + return g_object_ref (result); - out: - return result; + return NULL; } static gboolean @@ -852,7 +844,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority PolkitAuthorizationResult *result; PolkitImplicitAuthorization implicit_authorization; GError *error; - GSimpleAsyncResult *simple; + GTask *task; gboolean has_details; gchar **detail_keys; @@ -868,10 +860,11 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority user_of_subject_str = NULL; result = NULL; - simple = g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_backend_interactive_authority_check_authorization); + task = g_task_new (authority, + cancellable, + callback, + user_data); + g_task_set_source_tag (task, polkit_backend_interactive_authority_check_authorization); /* handle being called from ourselves */ if (caller == NULL) @@ -896,10 +889,8 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority &error); if (error != NULL) { - g_simple_async_result_set_from_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); + g_task_return_error (task, error); + g_object_unref (task); goto out; } @@ -911,10 +902,8 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority &error); if (error != NULL) { - g_simple_async_result_set_from_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); + g_task_return_error (task, error); + g_object_unref (task); goto out; } @@ -951,22 +940,21 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority { if (has_details) { - g_simple_async_result_set_error (simple, - POLKIT_ERROR, - POLKIT_ERROR_NOT_AUTHORIZED, - "Only trusted callers (e.g. uid 0 or an action owner) can use CheckAuthorization() and " - "pass details"); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_NOT_AUTHORIZED, + "Only trusted callers (e.g. uid 0 or an action owner) can use CheckAuthorization() and " + "pass details"); } else { - g_simple_async_result_set_error (simple, - POLKIT_ERROR, - POLKIT_ERROR_NOT_AUTHORIZED, - "Only trusted callers (e.g. uid 0 or an action owner) can use CheckAuthorization() for " - "subjects belonging to other identities"); + g_task_return_new_error (task, + POLKIT_ERROR, + POLKIT_ERROR_NOT_AUTHORIZED, + "Only trusted callers (e.g. uid 0 or an action owner) can use CheckAuthorization() for " + "subjects belonging to other identities"); } - g_simple_async_result_complete (simple); - g_object_unref (simple); + g_object_unref (task); goto out; } } @@ -983,10 +971,8 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority &error); if (error != NULL) { - g_simple_async_result_set_from_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); + g_task_return_error (task, error); + g_object_unref (task); goto out; } @@ -1014,7 +1000,7 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority implicit_authorization, cancellable, check_authorization_challenge_cb, - simple); + task); /* keep going */ goto out; @@ -1024,11 +1010,8 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority /* log_result (interactive_authority, action_id, subject, caller, result); */ /* Otherwise just return the result */ - g_simple_async_result_set_op_res_gpointer (simple, - g_object_ref (result), - g_object_unref); - g_simple_async_result_complete (simple); - g_object_unref (simple); + g_task_return_pointer (task, g_object_ref (result), g_object_unref); + g_object_unref (task); out: diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp index 517f3c6..29375ba 100644 --- a/src/polkitbackend/polkitbackendjsauthority.cpp +++ b/src/polkitbackend/polkitbackendjsauthority.cpp @@ -1526,7 +1526,7 @@ js_polkit_user_is_in_netgroup (JSContext *cx, typedef struct { - GSimpleAsyncResult *simple; /* borrowed reference */ + GTask *task; /* borrowed reference */ GMainContext *main_context; /* may be NULL */ GCancellable *cancellable; /* may be NULL */ @@ -1670,9 +1670,8 @@ utils_on_cancelled (GCancellable *cancellable, error = NULL; g_warn_if_fail (g_cancellable_set_error_if_cancelled (cancellable, &error)); - g_simple_async_result_take_error (data->simple, error); - g_simple_async_result_complete_in_idle (data->simple); - g_object_unref (data->simple); + g_task_return_error (data->task, error); + g_object_unref (data->task); } static gboolean @@ -1730,8 +1729,8 @@ utils_child_watch_cb (GPid pid, data->child_watch_source = NULL; /* we're done */ - g_simple_async_result_complete_in_idle (data->simple); - g_object_unref (data->simple); + g_task_return_boolean (data->task, TRUE); + g_object_unref (data->task); } static gboolean @@ -1745,8 +1744,8 @@ utils_timeout_cb (gpointer user_data) data->timeout_source = NULL; /* we're done */ - g_simple_async_result_complete_in_idle (data->simple); - g_object_unref (data->simple); + g_task_return_boolean (data->task, FALSE); + g_object_unref (data->task); return FALSE; /* remove source */ } @@ -1763,10 +1762,11 @@ utils_spawn (const gchar *const *argv, data = g_slice_new0 (UtilsSpawnData); data->timeout_seconds = timeout_seconds; - data->simple = g_simple_async_result_new (NULL, - callback, - user_data, - (gpointer*)utils_spawn); + data->task = g_task_new (NULL, + cancellable, + callback, + user_data); + g_task_set_source_tag (data->task, (gpointer*) utils_spawn); data->main_context = g_main_context_get_thread_default (); if (data->main_context != NULL) g_main_context_ref (data->main_context); @@ -1779,7 +1779,7 @@ utils_spawn (const gchar *const *argv, data->child_stderr_fd = -1; /* the life-cycle of UtilsSpawnData is tied to its GSimpleAsyncResult */ - g_simple_async_result_set_op_res_gpointer (data->simple, data, (GDestroyNotify) utils_spawn_data_free); + g_task_set_task_data (data->task, data, (GDestroyNotify) utils_spawn_data_free); error = NULL; if (data->cancellable != NULL) @@ -1788,9 +1788,8 @@ utils_spawn (const gchar *const *argv, error = NULL; if (g_cancellable_set_error_if_cancelled (data->cancellable, &error)) { - g_simple_async_result_take_error (data->simple, error); - g_simple_async_result_complete_in_idle (data->simple); - g_object_unref (data->simple); + g_task_return_error (data->task, error); + g_object_unref (data->task); goto out; } @@ -1814,9 +1813,8 @@ utils_spawn (const gchar *const *argv, &error)) { g_prefix_error (&error, "Error spawning: "); - g_simple_async_result_take_error (data->simple, error); - g_simple_async_result_complete_in_idle (data->simple); - g_object_unref (data->simple); + g_task_return_error (data->task, error); + g_object_unref (data->task); goto out; } @@ -1859,20 +1857,20 @@ utils_spawn_finish (GAsyncResult *res, gchar **out_standard_error, GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); + GTask *task = G_TASK (res); UtilsSpawnData *data; gboolean ret = FALSE; - g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); + g_return_val_if_fail (G_IS_TASK (res), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == utils_spawn); + g_warn_if_fail (g_task_get_source_tag (task) == utils_spawn); - if (g_simple_async_result_propagate_error (simple, error)) + data = (UtilsSpawnData*)g_task_get_task_data (task); + g_task_propagate_boolean (task, error); + if (error != NULL) goto out; - data = (UtilsSpawnData*)g_simple_async_result_get_op_res_gpointer (simple); - if (data->timed_out) { g_set_error (error, -- 2.17.0