[gnome-bluetooth/wip/hadess/async-unregister] agent: Fix possible hang when switching Settings panels
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/async-unregister] agent: Fix possible hang when switching Settings panels
- Date: Fri, 19 Feb 2021 14:20:32 +0000 (UTC)
commit ac9be930e3809718a325d111b074dd140b2c9f2a
Author: Bastien Nocera <hadess hadess net>
Date: Fri Feb 19 15:12:46 2021 +0100
agent: Fix possible hang when switching Settings panels
There are usually 2 reasons why the agent might go away:
- we're switching panels in the Settings
- the Settings executable is exit()ing
In the former case, we can't actually do anything if unregistering the
agent fails, and we can already remove our object path without waiting
on anyone, so just print some debug if it fails.
In the latter case, we'll be gone from the bus before before the method
has time to answer.
This fixes possible hangs while unregistering the agent when switching
panels with some broken Bluetooth adapters and/or drivers.
Closes: #49
lib/bluetooth-agent.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
---
diff --git a/lib/bluetooth-agent.c b/lib/bluetooth-agent.c
index b005b9ba..d12aa96b 100644
--- a/lib/bluetooth-agent.c
+++ b/lib/bluetooth-agent.c
@@ -513,42 +513,29 @@ gboolean bluetooth_agent_register(BluetoothAgent *agent)
return TRUE;
}
-static gboolean
-error_matches_remote_error (GError *error,
- const char *remote_error)
+static void
+agent_unregister_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- g_autofree char *str = NULL;
- gboolean ret;
-
- if (error == NULL)
- return FALSE;
-
- str = g_dbus_error_get_remote_error (error);
- ret = (g_strcmp0 (str, remote_error) == 0);
+ g_autoptr(GError) error = NULL;
- return ret;
+ if (!agent_manager1_call_unregister_agent_finish (AGENT_MANAGER1 (object), res, &error))
+ g_debug ("Failed to unregister agent: %s", error->message);
+ else
+ g_debug ("Unregistered agent successfully");
}
gboolean bluetooth_agent_unregister(BluetoothAgent *agent)
{
- g_autoptr(GError) error = NULL;
-
g_return_val_if_fail (BLUETOOTH_IS_AGENT (agent), FALSE);
if (agent->agent_manager == NULL)
return FALSE;
- if (agent_manager1_call_unregister_agent_sync (agent->agent_manager,
- agent->path,
- NULL, &error) == FALSE) {
- /* Ignore errors if the adapter is gone */
- if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) == FALSE &&
- error_matches_remote_error (error, "org.bluez.Error.DoesNotExist") == FALSE) {
- g_printerr ("Agent unregistration failed: %s '%s'\n",
- error->message,
- g_quark_to_string (error->domain));
- }
- }
+ agent_manager1_call_unregister_agent (agent->agent_manager,
+ agent->path,
+ NULL, agent_unregister_cb, NULL);
g_clear_object (&agent->agent_manager);
g_clear_pointer (&agent->path, g_free);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]