[gnome-bluetooth] lib: Ignore "org.bluez.Error.DoesNotExist" error when unregistering



commit 2c6d78c75b4d0bcd3e330136b5c7f7a7624280b1
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Nov 24 17:51:19 2017 +0100

    lib: Ignore "org.bluez.Error.DoesNotExist" error when unregistering
    
    That means that the agent was never registered. You could achieve this
    by:
    - bluetoothd is running, launch an agent
    - kill and restart bluetoothd
    - kill the agent
    - unregister() fails with:
    Agent unregistration failed: GDBus.Error:org.bluez.Error.DoesNotExist: Does Not Exist 'g-io-error-quark'
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790797

 lib/bluetooth-agent.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/lib/bluetooth-agent.c b/lib/bluetooth-agent.c
index 1ce37e8..ded68db 100644
--- a/lib/bluetooth-agent.c
+++ b/lib/bluetooth-agent.c
@@ -539,6 +539,23 @@ gboolean bluetooth_agent_register(BluetoothAgent *agent)
        return TRUE;
 }
 
+static gboolean
+error_matches_remote_error (GError     *error,
+                           const char *remote_error)
+{
+       char *str;
+       gboolean ret;
+
+       if (error == NULL)
+               return FALSE;
+
+       str = g_dbus_error_get_remote_error (error);
+       ret = (g_strcmp0 (str, remote_error) == 0);
+       g_free (str);
+
+       return ret;
+}
+
 gboolean bluetooth_agent_unregister(BluetoothAgent *agent)
 {
        BluetoothAgentPrivate *priv;
@@ -555,7 +572,8 @@ gboolean bluetooth_agent_unregister(BluetoothAgent *agent)
                                                       priv->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) {
+               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));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]