core: use NM_UTILS_ERROR_CANCELLED_DISPOSING error reason

This commit is contained in:
Thomas Haller 2015-09-24 13:14:14 +02:00
parent 44f3f18797
commit 320f454e9f
5 changed files with 17 additions and 52 deletions

View file

@ -216,18 +216,7 @@ _do_cancel_secrets (NMActRequest *self, GetSecretsInfo *info, gboolean is_dispos
if (info->callback) {
gs_free_error GError *error = NULL;
if (is_disposing) {
/* Use a different error code. G_IO_ERROR_CANCELLED is only used synchronously
* when the user calls nm_act_request_cancel_secrets(). Disposing the instance
* with pending requests also cancels the requests, but with a different error
* code. */
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Disposing NMActRequest instance");
} else {
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
"Request cancelled");
}
nm_utils_error_set_cancelled (&error, is_disposing, "NMActRequest");
info->callback (self, info, NULL, error, info->callback_data);
}

View file

@ -175,9 +175,8 @@ check_authorization_cb (GDBusProxy *proxy,
value = _nm_dbus_proxy_call_finish (proxy, res, G_VARIANT_TYPE ("((bba{ss}))"), &error);
if (value == NULL) {
if (data->cancellation_id != NULL &&
(!g_dbus_error_is_remote_error (error) &&
error->domain == G_IO_ERROR &&
error->code == G_IO_ERROR_CANCELLED)) {
( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)
&& !g_dbus_error_is_remote_error (error))) {
_LOGD ("call[%u]: CheckAuthorization cancelled", data->call_id);
g_dbus_proxy_call (priv->proxy,
"CancelCheckAuthorization",

View file

@ -576,19 +576,15 @@ req_complete_release (Request *req,
}
static void
req_complete_cancel (Request *req,
GQuark domain,
guint code,
const char *message)
req_complete_cancel (Request *req, gboolean is_disposing)
{
GError *error = NULL;
gs_free_error GError *error = NULL;
nm_assert (req && req->self);
nm_assert (!g_hash_table_contains (NM_AGENT_MANAGER_GET_PRIVATE (req->self)->requests, req));
g_set_error_literal (&error, domain, code, message);
nm_utils_error_set_cancelled (&error, is_disposing, "NMAgentManager");
req_complete_release (req, NULL, NULL, NULL, error);
g_error_free (error);
}
static void
@ -1242,7 +1238,7 @@ nm_agent_manager_cancel_secrets (NMAgentManager *self,
request_id))
g_return_if_reached ();
req_complete_cancel (request_id, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Request cancelled");
req_complete_cancel (request_id, FALSE);
}
/*************************************************************/
@ -1571,12 +1567,14 @@ dispose (GObject *object)
GHashTableIter iter;
Request *req;
cancel_more:
g_hash_table_iter_init (&iter, priv->requests);
while (g_hash_table_iter_next (&iter, (gpointer *) &req, NULL)) {
if (g_hash_table_iter_next (&iter, (gpointer *) &req, NULL)) {
g_hash_table_iter_remove (&iter);
req_complete_cancel (req, G_IO_ERROR, G_IO_ERROR_FAILED, "Disposing NMAgentManagerClass instance");
req_complete_cancel (req, TRUE);
goto cancel_more;
}
g_hash_table_destroy (priv->requests);
g_hash_table_unref (priv->requests);
priv->requests = NULL;
}

View file

@ -29,6 +29,7 @@
#include "nm-bus-manager.h"
#include "nm-auth-subject.h"
#include "nm-simple-connection.h"
#include "NetworkManagerUtils.h"
#include "nmdbus-secret-agent.h"
@ -428,23 +429,12 @@ do_cancel_secrets (NMSecretAgent *self, Request *r, gboolean disposing)
* Only clear r->cancellable to indicate that the request was cancelled. */
if (callback) {
GError *error = NULL;
gs_free_error GError *error = NULL;
if (disposing) {
/* hijack an error code. G_IO_ERROR_CANCELLED is only used synchronously
* when the user calls nm_act_request_cancel_secrets().
* When the user disposes the instance, we also invoke the callback synchronously,
* but with a different error-reason. */
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Disposing NMSecretAgent instance");
} else {
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
"Request cancelled");
}
nm_utils_error_set_cancelled (&error, disposing, "NMSecretAgent");
/* @r might be a dangling pointer at this point. However, that is no problem
* to pass it as (opaque) call_id. */
callback (self, r, NULL, error, callback_data);
g_error_free (error);
}
}

View file

@ -1270,10 +1270,9 @@ schedule_dummy:
static void
_get_secrets_cancel (NMSettingsConnection *self,
GetSecretsInfo *info,
gboolean shutdown)
gboolean is_disposing)
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
gs_free_error GError *error = NULL;
if (!g_slist_find (priv->get_secret_requests, info))
@ -1286,17 +1285,7 @@ _get_secrets_cancel (NMSettingsConnection *self,
else
g_source_remove (info->t.idle.id);
if (shutdown) {
/* Use a different error code. G_IO_ERROR_CANCELLED is only used synchronously
* when the user calls nm_act_request_cancel_secrets(). Disposing the instance
* with pending requests also cancels the requests, but with a different error
* code. */
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Disposing NMActRequest instance");
} else {
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
"Request cancelled");
}
nm_utils_error_set_cancelled (&error, is_disposing, "NMSettingsConnection");
_get_secrets_info_callback (info, NULL, NULL, error);