summaryrefslogtreecommitdiff
path: root/lib/bluetooth-agent.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2021-02-19 15:12:46 +0100
committerBastien Nocera <hadess@hadess.net>2021-02-19 15:20:20 +0100
commitac9be930e3809718a325d111b074dd140b2c9f2a (patch)
treee58ab118a563fe5b56caa4810676bbaa33a0aa3f /lib/bluetooth-agent.c
parentbf19319ce0927ec6c5c2c797b0e63cea7f152580 (diff)
downloadgnome-bluetooth-ac9be930e3809718a325d111b074dd140b2c9f2a.tar.gz
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
Diffstat (limited to 'lib/bluetooth-agent.c')
-rw-r--r--lib/bluetooth-agent.c37
1 files 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);