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) { if (info->callback) {
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
if (is_disposing) { nm_utils_error_set_cancelled (&error, is_disposing, "NMActRequest");
/* 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");
}
info->callback (self, info, NULL, error, info->callback_data); 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); value = _nm_dbus_proxy_call_finish (proxy, res, G_VARIANT_TYPE ("((bba{ss}))"), &error);
if (value == NULL) { if (value == NULL) {
if (data->cancellation_id != NULL && if (data->cancellation_id != NULL &&
(!g_dbus_error_is_remote_error (error) && ( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)
error->domain == G_IO_ERROR && && !g_dbus_error_is_remote_error (error))) {
error->code == G_IO_ERROR_CANCELLED)) {
_LOGD ("call[%u]: CheckAuthorization cancelled", data->call_id); _LOGD ("call[%u]: CheckAuthorization cancelled", data->call_id);
g_dbus_proxy_call (priv->proxy, g_dbus_proxy_call (priv->proxy,
"CancelCheckAuthorization", "CancelCheckAuthorization",

View file

@ -576,19 +576,15 @@ req_complete_release (Request *req,
} }
static void static void
req_complete_cancel (Request *req, req_complete_cancel (Request *req, gboolean is_disposing)
GQuark domain,
guint code,
const char *message)
{ {
GError *error = NULL; gs_free_error GError *error = NULL;
nm_assert (req && req->self); nm_assert (req && req->self);
nm_assert (!g_hash_table_contains (NM_AGENT_MANAGER_GET_PRIVATE (req->self)->requests, req)); 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); req_complete_release (req, NULL, NULL, NULL, error);
g_error_free (error);
} }
static void static void
@ -1242,7 +1238,7 @@ nm_agent_manager_cancel_secrets (NMAgentManager *self,
request_id)) request_id))
g_return_if_reached (); 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; GHashTableIter iter;
Request *req; Request *req;
cancel_more:
g_hash_table_iter_init (&iter, priv->requests); 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); 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; priv->requests = NULL;
} }

View file

@ -29,6 +29,7 @@
#include "nm-bus-manager.h" #include "nm-bus-manager.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "NetworkManagerUtils.h"
#include "nmdbus-secret-agent.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. */ * Only clear r->cancellable to indicate that the request was cancelled. */
if (callback) { if (callback) {
GError *error = NULL; gs_free_error GError *error = NULL;
if (disposing) { nm_utils_error_set_cancelled (&error, disposing, "NMSecretAgent");
/* 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");
}
/* @r might be a dangling pointer at this point. However, that is no problem /* @r might be a dangling pointer at this point. However, that is no problem
* to pass it as (opaque) call_id. */ * to pass it as (opaque) call_id. */
callback (self, r, NULL, error, callback_data); callback (self, r, NULL, error, callback_data);
g_error_free (error);
} }
} }

View file

@ -1270,10 +1270,9 @@ schedule_dummy:
static void static void
_get_secrets_cancel (NMSettingsConnection *self, _get_secrets_cancel (NMSettingsConnection *self,
GetSecretsInfo *info, GetSecretsInfo *info,
gboolean shutdown) gboolean is_disposing)
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
if (!g_slist_find (priv->get_secret_requests, info)) if (!g_slist_find (priv->get_secret_requests, info))
@ -1286,17 +1285,7 @@ _get_secrets_cancel (NMSettingsConnection *self,
else else
g_source_remove (info->t.idle.id); g_source_remove (info->t.idle.id);
if (shutdown) { nm_utils_error_set_cancelled (&error, is_disposing, "NMSettingsConnection");
/* 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");
}
_get_secrets_info_callback (info, NULL, NULL, error); _get_secrets_info_callback (info, NULL, NULL, error);