summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-09-24 13:14:14 +0200
committerThomas Haller <thaller@redhat.com>2015-09-25 10:34:02 +0200
commit320f454e9f06db6859134daf4e9e567e9b03c8eb (patch)
tree064f47994587ab6f4a1bade0914db16388831959
parent44f3f18797cf3b0e0d45791939b2f9f023d51230 (diff)
downloadNetworkManager-320f454e9f06db6859134daf4e9e567e9b03c8eb.tar.gz
core: use NM_UTILS_ERROR_CANCELLED_DISPOSING error reason
-rw-r--r--src/nm-activation-request.c13
-rw-r--r--src/nm-auth-manager.c5
-rw-r--r--src/settings/nm-agent-manager.c20
-rw-r--r--src/settings/nm-secret-agent.c18
-rw-r--r--src/settings/nm-settings-connection.c15
5 files changed, 18 insertions, 53 deletions
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c
index 173dc19fd7..e6645bdbc4 100644
--- a/src/nm-activation-request.c
+++ b/src/nm-activation-request.c
@@ -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);
}
diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c
index 46a011205e..bc519eb199 100644
--- a/src/nm-auth-manager.c
+++ b/src/nm-auth-manager.c
@@ -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",
diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c
index c3abaac25c..0c36d286f2 100644
--- a/src/settings/nm-agent-manager.c
+++ b/src/settings/nm-agent-manager.c
@@ -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;
}
diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c
index 1032027c39..29c0f55b4d 100644
--- a/src/settings/nm-secret-agent.c
+++ b/src/settings/nm-secret-agent.c
@@ -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;
-
- 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");
- }
+ gs_free_error GError *error = NULL;
+
+ 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);
}
}
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index 9ab0bc6b30..29162c7984 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -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);