[PATCH] Fix dock station status detection

Holger Macht hmacht at suse.de
Thu Mar 13 11:05:47 PDT 2008


When the user triggers an undock operation, the kernel assumes that the
undock cannot fail (which is pretty true) and sends out the 'UNDOCK' udev
event before actually doing it. So when HAL comes down to
platform_refresh() and reads the 'docked' sysfs file, it still contains
'docked' (at odd times, it's a race).

As a solution, also read the 'flags' sysfs property to check if a undock
operation is currently in progress and update the 'info.docked' key
accordingly.

Signed-off-by: Holger Macht <hmacht at suse.de>
---

diff --git a/hald/linux/device.c b/hald/linux/device.c
index c41edf3..ebd8214 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -2019,7 +2019,7 @@ static gboolean
 platform_refresh (HalDevice *d)
 {
 	const gchar *id, *sysfs_path;
-	int docked;
+	gint docked, flags;
 
 	id = hal_device_property_get_string (d, "platform.id");
 	if (strncmp (id, "dock", 4) != 0)
@@ -2027,6 +2027,14 @@ platform_refresh (HalDevice *d)
 
 	sysfs_path = hal_device_property_get_string(d, "linux.sysfs_path");
 	hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0);
+
+	if (docked == 1) {
+		/* check if undock operation is currently in progress */
+		hal_util_get_int_from_file (sysfs_path, "flags", &flags, 0);
+		if (flags == 2)
+			docked = 0;
+	}
+
 	hal_device_property_set_bool (d, "info.docked", docked);
 
 	return TRUE;



More information about the hal mailing list