[PATCH] Implement retry on linux sysfs pnp id file.

Drew Moseley dmoseley at mvista.com
Mon Sep 22 15:11:28 PDT 2008


> Can you send the patch with diff -Nur or plain git diff?

Updated patch below.

> I'm currently not sure if we should do this. IMO the kernel should get fixed 
> instead to provide the sysfs file only if the content/information is really 
> available. Did you report the problem to the kernel guys?

I've spoken w/ some kernel guys locally and they are of the opinion that
with sysfs, unfortunately, that's the way it has to be.  There is
precedence for this kind of sleep already in hald/linux/blockdev.c which
is what I modelled this patch after.

Drew




Signed-off-by: Drew Moseley <dmoseley at mvista.com>
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 036e6a8..e89406f 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1925,6 +1925,7 @@ pnp_add (const gchar *sysfs_path, const gchar
*device_file, HalDevice *parent_de
 {
 	HalDevice *d;
 	HalDevice *computer;
+	int num_tries;

 	d = hal_device_new ();
 	hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
@@ -1936,7 +1937,22 @@ pnp_add (const gchar *sysfs_path, const gchar
*device_file, HalDevice *parent_de

 	hal_util_set_driver (d, "info.linux.driver", sysfs_path);

+	num_tries = 0;
+retry_pnpid:
 	hal_util_set_string_from_file (d, "pnp.id", sysfs_path, "id");
+
+	if (!hal_device_has_property (d, "pnp.id")) {
+		if (num_tries <= 5) {
+			int num_ms;
+			num_ms = 10 * (1<<num_tries);
+			HAL_INFO (("spinning %d ms waiting for pnp.id file for sysfs path %s",
+					   num_ms, sysfs_path));
+			usleep (1000 * num_ms);
+			num_tries++;
+			goto retry_pnpid;
+		}
+	}
+
 	if (hal_device_has_property (d, "pnp.id")) {
 		gchar *pnp_description;
 		const char *pnp_id;



More information about the hal mailing list