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

Drew Moseley dmoseley at mvista.com
Mon Sep 22 11:29:13 PDT 2008


Hello,

There is a short window in the sysfs implementation where the directory
corresponding to a pnp device will exist but the ID file will not yet be
created.  This patch implements a retry that will catch this case.

Comments?

Drew


Signed-off-by: Drew Moseley <dmoseley at mvista.com>
*** hald/linux/device.c.orig	2008-09-19 14:34:09.000000000 -0700
--- hald/linux/device.c	2008-09-19 14:34:49.000000000 -0700
***************
*** 1925,1928 ****
--- 1925,1929 ----
  	HalDevice *d;
  	HalDevice *computer;
+ 	int num_tries;

  	d = hal_device_new ();
***************
*** 1936,1940 ****
--- 1937,1956 ----
  	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;


More information about the hal mailing list