Blame SOURCES/0002-lib-Fix-cancellation-handling.patch

04bdd5
From 84ec5f5a11908e636ff3b992aecfc5c8f8faddb5 Mon Sep 17 00:00:00 2001
04bdd5
From: Bastien Nocera <hadess@hadess.net>
04bdd5
Date: Wed, 20 Nov 2013 17:10:46 +0100
04bdd5
Subject: [PATCH 2/3] lib: Fix cancellation handling
04bdd5
04bdd5
We weren't checking for cancellation properly, not passing
04bdd5
cancellables to sub-routines, and not reporting cancelled calls
04bdd5
correctly.
04bdd5
---
04bdd5
 lib/bluetooth-client.c | 30 ++++++++++++++++++------------
04bdd5
 1 file changed, 18 insertions(+), 12 deletions(-)
04bdd5
04bdd5
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
04bdd5
index 1fe7e6d..e224033 100644
04bdd5
--- a/lib/bluetooth-client.c
04bdd5
+++ b/lib/bluetooth-client.c
04bdd5
@@ -1661,23 +1661,20 @@ connect_callback (GDBusProxy   *proxy,
04bdd5
 		  ConnectData  *conndata)
04bdd5
 {
04bdd5
 	GVariant *variant;
04bdd5
-	gboolean retval;
04bdd5
 	GError *error = NULL;
04bdd5
 
04bdd5
 	variant = g_dbus_proxy_call_finish (proxy, res, &error);
04bdd5
 	if (variant == NULL) {
04bdd5
-		retval = FALSE;
04bdd5
 		g_debug ("Connect failed for %s: %s",
04bdd5
 			 g_dbus_proxy_get_object_path (proxy), error->message);
04bdd5
-		g_error_free (error);
04bdd5
+		g_simple_async_result_take_error (conndata->simple, error);
04bdd5
 	} else {
04bdd5
 		g_debug ("Connect succeeded for %s",
04bdd5
 			 g_dbus_proxy_get_object_path (proxy));
04bdd5
 		g_variant_unref (variant);
04bdd5
-		retval = TRUE;
04bdd5
+		g_simple_async_result_set_op_res_gboolean (conndata->simple, TRUE);
04bdd5
 	}
04bdd5
 
04bdd5
-	g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
04bdd5
 	g_simple_async_result_complete_in_idle (conndata->simple);
04bdd5
 
04bdd5
 	g_object_unref (conndata->simple);
04bdd5
@@ -1699,10 +1696,11 @@ disconnect_callback (GDBusProxy   *proxy,
04bdd5
 			g_debug ("Disconnect failed for %s: %s",
04bdd5
 				 g_dbus_proxy_get_object_path (G_DBUS_PROXY (conndata->device)),
04bdd5
 				 error->message);
04bdd5
-			g_error_free (error);
04bdd5
+			g_simple_async_result_take_error (conndata->simple, error);
04bdd5
 		} else {
04bdd5
 			g_debug ("Disconnect succeeded for %s",
04bdd5
 				 g_dbus_proxy_get_object_path (G_DBUS_PROXY (conndata->device)));
04bdd5
+			g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
04bdd5
 		}
04bdd5
 	} else {
04bdd5
 		GDBusProxy *service;
04bdd5
@@ -1716,6 +1714,10 @@ disconnect_callback (GDBusProxy   *proxy,
04bdd5
 				 g_dbus_proxy_get_object_path (proxy),
04bdd5
 				 g_dbus_proxy_get_interface_name (proxy),
04bdd5
 				 error->message);
04bdd5
+			if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
04bdd5
+				g_simple_async_result_take_error (conndata->simple, error);
04bdd5
+				goto bail;
04bdd5
+			}
04bdd5
 			g_error_free (error);
04bdd5
 		} else {
04bdd5
 			g_debug ("Disconnect succeeded for %s on %s",
04bdd5
@@ -1737,14 +1739,14 @@ disconnect_callback (GDBusProxy   *proxy,
04bdd5
 				   g_variant_new ("()"),
04bdd5
 				   G_DBUS_CALL_FLAGS_NONE,
04bdd5
 				   -1,
04bdd5
-				   NULL,
04bdd5
+				   g_object_get_data (G_OBJECT (conndata->simple), "cancellable"),
04bdd5
 				   (GAsyncReadyCallback) disconnect_callback,
04bdd5
 				   conndata);
04bdd5
 
04bdd5
 		return;
04bdd5
 	}
04bdd5
 
04bdd5
-	g_simple_async_result_set_op_res_gboolean (conndata->simple, retval);
04bdd5
+bail:
04bdd5
 	g_simple_async_result_complete_in_idle (conndata->simple);
04bdd5
 
04bdd5
 	g_object_unref (proxy);
04bdd5
@@ -1836,6 +1838,7 @@ bluetooth_client_connect_service (BluetoothClient     *client,
04bdd5
 		g_object_set_data_full (G_OBJECT (simple), "device",
04bdd5
 					g_strdup (device), g_free);
04bdd5
 	}
04bdd5
+	g_simple_async_result_set_check_cancellable (simple, cancellable);
04bdd5
 
04bdd5
 	gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
04bdd5
 			    BLUETOOTH_COLUMN_PROXY, &proxy,
04bdd5
@@ -1891,7 +1894,7 @@ bluetooth_client_connect_service (BluetoothClient     *client,
04bdd5
 				   NULL,
04bdd5
 				   G_DBUS_CALL_FLAGS_NONE,
04bdd5
 				   -1,
04bdd5
-				   NULL,
04bdd5
+				   cancellable,
04bdd5
 				   (GAsyncReadyCallback) connect_callback,
04bdd5
 				   conndata);
04bdd5
 	} else if (table != NULL) {
04bdd5
@@ -1914,14 +1917,14 @@ bluetooth_client_connect_service (BluetoothClient     *client,
04bdd5
 				   NULL,
04bdd5
 				   G_DBUS_CALL_FLAGS_NONE,
04bdd5
 				   -1,
04bdd5
-				   NULL,
04bdd5
+				   cancellable,
04bdd5
 				   (GAsyncReadyCallback) disconnect_callback,
04bdd5
 				   conndata);
04bdd5
 	} else if (table == NULL) {
04bdd5
 		g_debug ("Calling device_call_disconnect() for %s",
04bdd5
 			 g_dbus_proxy_get_object_path (proxy));
04bdd5
 		device_call_disconnect (DEVICE (proxy),
04bdd5
-					NULL,
04bdd5
+					cancellable,
04bdd5
 					(GAsyncReadyCallback) disconnect_callback,
04bdd5
 					conndata);
04bdd5
 		g_object_unref (proxy);
04bdd5
@@ -1956,7 +1959,10 @@ bluetooth_client_connect_service_finish (BluetoothClient *client,
04bdd5
 
04bdd5
 	g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == bluetooth_client_connect_service);
04bdd5
 
04bdd5
-	return g_simple_async_result_get_op_res_gboolean (simple);
04bdd5
+	if (g_simple_async_result_get_op_res_gboolean (simple))
04bdd5
+		return TRUE;
04bdd5
+	g_simple_async_result_propagate_error (simple, error);
04bdd5
+	return FALSE;
04bdd5
 }
04bdd5
 
04bdd5
 #define BOOL_STR(x) (x ? "True" : "False")
04bdd5
-- 
04bdd5
1.8.4.2
04bdd5