Blame SOURCES/0001-common-fix-udev-based-device-removal.patch

9b746a
From 6b34f996699a80c249d2cccfe369b3b61e70d4ce Mon Sep 17 00:00:00 2001
9b746a
From: Peter Hutterer <peter.hutterer@who-t.net>
9b746a
Date: Mon, 10 Dec 2018 14:43:30 +1000
9b746a
Subject: [PATCH] common: fix udev-based device removal
9b746a
9b746a
libgudev allocs a new GUdevDevice object for each event, so the pointer value
9b746a
for the 'add' udev event differs from the one for the 'remove' event. If we
9b746a
use the pointer value as hash table key, we'll never remove the device.
9b746a
Switch to use the syspath of the device instead, that one is unique per
9b746a
device.
9b746a
9b746a
Fixes #309
9b746a
---
9b746a
 panels/common/gsd-device-manager-udev.c | 16 ++++++++++------
9b746a
 1 file changed, 10 insertions(+), 6 deletions(-)
9b746a
9b746a
diff --git a/panels/common/gsd-device-manager-udev.c b/panels/common/gsd-device-manager-udev.c
9b746a
index aa9304232..105c8e987 100644
9b746a
--- a/panels/common/gsd-device-manager-udev.c
9b746a
+++ b/panels/common/gsd-device-manager-udev.c
9b746a
@@ -122,6 +122,7 @@ add_device (GsdUdevDeviceManager *manager,
9b746a
 {
9b746a
 	GUdevDevice *parent;
9b746a
 	GsdDevice *device;
9b746a
+	gchar *syspath;
9b746a
 
9b746a
 	parent = g_udev_device_get_parent (udev_device);
9b746a
 
9b746a
@@ -129,7 +130,8 @@ add_device (GsdUdevDeviceManager *manager,
9b746a
 		return;
9b746a
 
9b746a
 	device = create_device (udev_device);
9b746a
-	g_hash_table_insert (manager->devices, g_object_ref (udev_device), device);
9b746a
+	syspath = g_strdup (g_udev_device_get_sysfs_path (udev_device));
9b746a
+	g_hash_table_insert (manager->devices, syspath, device);
9b746a
 	g_signal_emit_by_name (manager, "device-added", device);
9b746a
 }
9b746a
 
9b746a
@@ -138,17 +140,19 @@ remove_device (GsdUdevDeviceManager *manager,
9b746a
 	       GUdevDevice	    *udev_device)
9b746a
 {
9b746a
 	GsdDevice *device;
9b746a
+	gchar *syspath;
9b746a
 
9b746a
-	device = g_hash_table_lookup (manager->devices, udev_device);
9b746a
+	syspath = g_strdup (g_udev_device_get_sysfs_path (udev_device));
9b746a
+	device = g_hash_table_lookup (manager->devices, syspath);
9b746a
 
9b746a
 	if (!device)
9b746a
 		return;
9b746a
 
9b746a
-	g_hash_table_steal (manager->devices, udev_device);
9b746a
+	g_hash_table_steal (manager->devices, syspath);
9b746a
 	g_signal_emit_by_name (manager, "device-removed", device);
9b746a
 
9b746a
 	g_object_unref (device);
9b746a
-	g_object_unref (udev_device);
9b746a
+	g_free (syspath);
9b746a
 }
9b746a
 
9b746a
 static void
9b746a
@@ -173,8 +177,8 @@ gsd_udev_device_manager_init (GsdUdevDeviceManager *manager)
9b746a
 	const gchar *subsystems[] = { "input", NULL };
9b746a
 	GList *devices, *l;
9b746a
 
9b746a
-	manager->devices = g_hash_table_new_full (NULL, NULL,
9b746a
-						  (GDestroyNotify) g_object_unref,
9b746a
+	manager->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
9b746a
+						  (GDestroyNotify) g_free,
9b746a
 						  (GDestroyNotify) g_object_unref);
9b746a
 
9b746a
 	manager->udev_client = g_udev_client_new (subsystems);
9b746a
-- 
9b746a
2.24.0
9b746a