hal/hald/linux block_class_device.c, 1.86.2.1, 1.86.2.2 bus_device.c, 1.19, 1.19.2.1 class_device.c, 1.29, 1.29.2.1 common.c, 1.15, 1.15.2.1 common.h, 1.10.2.1, 1.10.2.2 osspec.c, 1.52, 1.52.2.1

David Zeuthen david at freedesktop.org
Tue Nov 30 19:39:04 PST 2004


Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv9115/hald/linux

Modified Files:
      Tag: hal-0_4-stable-branch
	block_class_device.c bus_device.c class_device.c common.c 
	common.h osspec.c 
Log Message:
2004-11-30  David Zeuthen  <davidz at redhat.com>

	* hald/linux/osspec.c (compute_coldplug_visit_device): Descent down
	the to leafs of the /sys/devices tree but dont follow symlinks - done
	such that we can process sysfs trees with holes in them (cf. SCSI
	midlayer changes for kernel 2.6.10)

	* hald/linux/common.h: Remove prototypes for get_parent_sysfs_path()
	and add find_closest_ancestor(), find_computer()

	* hald/linux/common.c (find_closest_ancestor): New function - such
	that we can process sysfs trees with holes in them (cf. SCSI
	midlayer changes for kernel 2.6.10)
	(get_parent_sysfs_path): Make this static
	(find_computer): New function

	* hald/linux/class_device.c (class_device_visit): Use new function
	find_closest_ancestor() instead of get_parent_sysfs_path

	* hald/linux/bus_device.c (bus_device_visit): Use new function
	find_closest_ancestor() instead of get_parent_sysfs_path

	* hald/linux/block_class_device.c (block_class_visit): Use new
	function find_closest_ancestor() instead of get_parent_sysfs_path



Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.86.2.1
retrieving revision 1.86.2.2
diff -u -d -r1.86.2.1 -r1.86.2.2
--- block_class_device.c	22 Nov 2004 21:53:50 -0000	1.86.2.1
+++ block_class_device.c	1 Dec 2004 03:39:01 -0000	1.86.2.2
@@ -196,7 +196,6 @@
 {
 	HalDevice *d;
 	HalDevice *parent;
-	char *parent_sysfs_path;
 	ClassAsyncData *cad;
 	struct sysfs_device *sysdevice;
 
@@ -218,10 +217,12 @@
 	sysdevice = sysfs_get_classdev_device (class_device);
 
 	if (sysdevice == NULL) {
-		parent_sysfs_path = get_parent_sysfs_path (path);
+		parent = find_closest_ancestor (path);
 		hal_device_property_set_bool (d, "block.is_volume", TRUE);
 	} else {
-		parent_sysfs_path = sysdevice->path;
+		parent = hal_device_store_match_key_value_string (hald_get_gdl (), 
+								  "linux.sysfs_path_device", 
+								  sysdevice->path);
 		hal_device_property_set_bool (d, "block.is_volume", FALSE);
 	}
 
@@ -254,9 +255,6 @@
 	 * sure to be added before us (we probe devices in the right order
 	 * and we reorder hotplug events)
 	 */
-	parent = hal_device_store_match_key_value_string (hald_get_gdl (), 
-							  "linux.sysfs_path_device", 
-							  parent_sysfs_path);
 	if (parent == NULL) {
 		hal_device_store_remove (hald_get_tdl (), d);
 		d = NULL;

Index: bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/bus_device.c,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -u -d -r1.19 -r1.19.2.1
--- bus_device.c	28 Aug 2004 13:35:47 -0000	1.19
+++ bus_device.c	1 Dec 2004 03:39:01 -0000	1.19.2.1
@@ -87,7 +87,6 @@
 {
 	HalDevice *d;
 	HalDevice *parent;
-	char *parent_sysfs_path;
 	BusAsyncData *bad;
 	char buf[256];
 
@@ -107,8 +106,6 @@
 	snprintf (buf, sizeof(buf), "%s.linux.sysfs_path", self->hal_bus_name);
 	hal_device_property_set_string (d, buf, path);
 
-	parent_sysfs_path = get_parent_sysfs_path (path);
-
 	bad = g_new0 (BusAsyncData, 1);
 	bad->device = d;
 	bad->handler = self;
@@ -121,13 +118,13 @@
 		goto out;
 	} 
 
+
 	/* Find parent; this can happen synchronously as our parent is
 	 * sure to be added before us (we probe devices in the right order
 	 * and we reorder hotplug events)
 	 */
-	parent = hal_device_store_match_key_value_string (hald_get_gdl (), 
-							  "linux.sysfs_path_device", 
-							  parent_sysfs_path);
+	parent = find_closest_ancestor (path);
+
 	if (parent == NULL) {
 		hal_device_store_remove (hald_get_tdl (), d);
 		d = NULL;
@@ -137,7 +134,6 @@
 	bus_device_got_parent (hald_get_gdl(), parent, bad);
 
 out:
-	free (parent_sysfs_path);
 	return d;
 }
 

Index: class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/class_device.c,v
retrieving revision 1.29
retrieving revision 1.29.2.1
diff -u -d -r1.29 -r1.29.2.1
--- class_device.c	19 Oct 2004 22:58:03 -0000	1.29
+++ class_device.c	1 Dec 2004 03:39:01 -0000	1.29.2.1
@@ -202,15 +202,11 @@
 
 	} else {
 		if (sysdevice != NULL) {
-			what_to_find = get_parent_sysfs_path (sysdevice->path);
+			hal_target = find_closest_ancestor (sysdevice->path);
 		} else {
-			what_to_find = "(none)"; /* DZE: Yikes, hack to get added as a child to 'computer'? */
+			hal_target = find_computer ();
 		}
 
-		/* find the sysdevice we should be a child of */
-		hal_target = hal_device_store_match_key_value_string (hald_get_gdl (), 
-								      "linux.sysfs_path_device", 
-								      what_to_find);
 		if (hal_target == NULL)
 			goto error;
 

Index: common.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.c,v
retrieving revision 1.15
retrieving revision 1.15.2.1
diff -u -d -r1.15 -r1.15.2.1
--- common.c	2 Sep 2004 21:45:49 -0000	1.15
+++ common.c	1 Dec 2004 03:39:01 -0000	1.15.2.1
@@ -590,13 +590,57 @@
 	return computed_udi;
 }
 
+/** Find the closest ancestor by looking at sysfs paths
+ *
+ *  @param  sysfs_path           Path into sysfs, e.g. /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0
+ *  @return                      Parent Hal Device Object or #NULL if there is none
+ */
+HalDevice *
+find_closest_ancestor (const char *sysfs_path)
+{	
+	char buf[512];
+	HalDevice *parent;
+
+	parent = NULL;
+
+	strncpy (buf, sysfs_path, sizeof (buf));
+	do {
+		char *p;
+
+		p = strrchr (buf, '/');
+		if (p == NULL)
+			break;
+		*p = '\0';
+
+		parent = hal_device_store_match_key_value_string (hald_get_gdl (), 
+								  "linux.sysfs_path_device", 
+								  buf);
+		if (parent != NULL)
+			break;
+
+	} while (TRUE);
+
+	return parent;
+}
+
+HalDevice * find_computer ()
+{
+	HalDevice *d;
+	d = hal_device_store_match_key_value_string (hald_get_gdl (), 
+						     "linux.sysfs_path_device", 
+						     "(none)");
+	return d;
+}
+
+
 /** Given a sysfs-path for a device, this functions finds the sysfs
  *  path representing the parent of the given device by truncation.
  *
  *  @param  path                Sysfs-path of device to find parent for
- *  @return                     Path for parent; must be freed by caller
+ *  @return                     Path for parent or NULL if there is no parent; 
+ *                              must be freed by caller
  */
-char *
+static char *
 get_parent_sysfs_path (const char *path)
 {
 	int i;

Index: common.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.h,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -u -d -r1.10.2.1 -r1.10.2.2
--- common.h	22 Nov 2004 21:53:50 -0000	1.10.2.1
+++ common.h	1 Dec 2004 03:39:01 -0000	1.10.2.2
@@ -68,7 +68,9 @@
 
 char *rename_and_merge (HalDevice *d, ComputeFDI naming_func, const char *namespace);
 
-char *get_parent_sysfs_path (const char *path);
+HalDevice * find_closest_ancestor (const char *sysfs_path);
+
+HalDevice * find_computer ();
 
 dbus_bool_t class_device_get_major_minor (const char *sysfs_path, int *major, int *minor);
 

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.52
retrieving revision 1.52.2.1
diff -u -d -r1.52 -r1.52.2.1
--- osspec.c	26 Oct 2004 17:35:21 -0000	1.52
+++ osspec.c	1 Dec 2004 03:39:01 -0000	1.52.2.1
@@ -42,6 +42,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/utsname.h>
+#include <sys/stat.h>
 #include <time.h>
 
 #include <glib.h>
@@ -630,7 +631,7 @@
 	GError *err;
 	GDir *dir;
 	const gchar *f;
-		
+
 	bus = g_hash_table_lookup (sysfs_to_bus_map, path);
 	if (bus != NULL) {
 		for (i = 0; bus_device_handlers[i] != NULL; i++) {	
@@ -681,22 +682,29 @@
 						 h_string_pair_new (g_strdup (path), g_strdup (bus)));
 		goto found;
 	}
-	return;
 
 found:
 
 	/* visit children */
+	err = NULL;
 	if ((dir = g_dir_open (path, 0, &err)) == NULL) {
-		HAL_ERROR (("Unable to open %: %s", path, err->message));
+		HAL_ERROR (("Unable to open directory: %s", path, err->message));
 		g_error_free (err);
 		goto error;
 	}
 	while ((f = g_dir_read_name (dir)) != NULL) {
 		gchar path_child[SYSFS_PATH_MAX];
-		
+		struct stat statbuf;
+	
 		g_snprintf (path_child, SYSFS_PATH_MAX, "%s/%s", path, f);
-		
-		compute_coldplug_visit_device (path_child, coldplug_list);
+
+		if (lstat (path_child, &statbuf) == 0) {
+
+			if (!S_ISLNK (statbuf.st_mode)) {
+				/* recursion fun */
+				compute_coldplug_visit_device (path_child, coldplug_list);
+			}
+		}
 	}
 	g_dir_close (dir);
 




More information about the hal-commit mailing list