summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg KH <greg@press.(none)>2005-05-18 23:32:28 -0700
committerGreg KH <gregkh@suse.de>2005-05-18 23:32:28 -0700
commitb479b4887f5a0eb69b801645ab1b14636c4b06a2 (patch)
tree3c12df92b63aafb6ad6d6b760628783c1b898b8e
parent60f44733522cca3a619db598e4c83b8e8d0750b6 (diff)
Fix libsysfs issue with relying on the detach_state file to be
present in order to traverse the tree properly. Based on a patch from Daniel Stekloff <dsteklof@us.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--libsysfs/sysfs_device.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/libsysfs/sysfs_device.c b/libsysfs/sysfs_device.c
index d1c5b321f0..1c59403edd 100644
--- a/libsysfs/sysfs_device.c
+++ b/libsysfs/sysfs_device.c
@@ -383,7 +383,7 @@ struct sysfs_device *sysfs_open_device(const char *bus, const char *bus_id)
*/
struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev)
{
- char ppath[SYSFS_PATH_MAX], *tmp;
+ char ppath[SYSFS_PATH_MAX], dpath[SYSFS_PATH_MAX], *tmp;
if (!dev) {
errno = EINVAL;
@@ -394,6 +394,7 @@ struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev)
return (dev->parent);
memset(ppath, 0, SYSFS_PATH_MAX);
+ memset(dpath, 0, SYSFS_PATH_MAX);
safestrcpy(ppath, dev->path);
tmp = strrchr(ppath, '/');
if (!tmp) {
@@ -410,16 +411,14 @@ struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev)
}
*tmp = '\0';
- /*
- * All "devices" have the "detach_state" attribute - validate here
- */
- safestrcat(ppath, "/detach_state");
- if (sysfs_path_is_file(ppath)) {
+ /* Make sure we're not at the top of the device tree */
+ sysfs_get_mnt_path(dpath, SYSFS_PATH_MAX);
+ safestrcat(dpath, "/" SYSFS_DEVICES_NAME);
+ if (strcmp(dpath, ppath) == 0) {
dprintf("Device at %s does not have a parent\n", dev->path);
return NULL;
}
- tmp = strrchr(ppath, '/');
- *tmp = '\0';
+
dev->parent = sysfs_open_device_path(ppath);
if (!dev->parent) {
dprintf("Error opening device %s's parent at %s\n",