]> err.no Git - systemd/commitdiff
[PATCH] another patch for path problem
authordsteklof@us.ibm.com <dsteklof@us.ibm.com>
Tue, 2 Dec 2003 08:48:01 +0000 (00:48 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:04 +0000 (21:13 -0700)
The quick patch I sent you yesterday fixes it in one location, but
there are other points in the library that calls sysfs_get_mnt_path. We
need to address all the areas in the library where paths are used. The
following patch is a band-aid until we can get a proper path management
in the library.

libsysfs/libsysfs.h
libsysfs/sysfs_bus.c
libsysfs/sysfs_class.c
libsysfs/sysfs_device.c
libsysfs/sysfs_driver.c
libsysfs/sysfs_utils.c

index f7e989e242ad4b53d4d5ac02c1b9af106e240fb9..6d8e58de21ec4235920d0d7f52b9a147e388aeae 100644 (file)
@@ -142,6 +142,7 @@ extern "C" {
 /*
  * Function Prototypes
  */
+extern int sysfs_trailing_slash(unsigned char *path);
 extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
 extern int sysfs_get_name_from_path(const unsigned char *path, 
                                        unsigned char *name, size_t len);
index 3111154cbc97839744e32e88a9847e15c3a1807b..639acef4eeddf6108c63199aa1eba11c2ce94ece 100644 (file)
@@ -112,7 +112,10 @@ static struct sysfs_directory *open_bus_dir(const unsigned char *name)
                return NULL;
        }
 
-       strcat(buspath, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(buspath) == 0)
+               strcat(buspath, "/");
+               
+       strcat(buspath, SYSFS_BUS_NAME);
        strcat(buspath, "/");
        strcat(buspath, name);
        busdir = sysfs_open_directory(buspath);
@@ -406,10 +409,13 @@ struct sysfs_device *sysfs_open_bus_device(unsigned char *busname,
                return NULL;
        }
 
-       strcat(path, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(path) == 0)
+               strcat(path, "/");
+       strcat(path, SYSFS_BUS_NAME);
        strcat(path, "/");
        strcat(path, busname);
-       strcat(path, SYSFS_DEVICES_DIR);
+       strcat(path, "/");
+       strcat(path, SYSFS_DEVICES_NAME);
        strcat(path, "/");
        strcat(path, dev_id);
 
@@ -442,15 +448,17 @@ int sysfs_find_driver_bus(const unsigned char *driver, unsigned char *busname,
        }
 
        memset(subsys, 0, SYSFS_PATH_MAX);
-       strcpy(subsys, SYSFS_BUS_DIR);
+       strcpy(subsys, SYSFS_BUS_NAME);
        buslist = sysfs_open_subsystem_list(subsys);
        if (buslist != NULL) {
                dlist_for_each_data(buslist, bus, char) {
                        memset(subsys, 0, SYSFS_PATH_MAX);
-                       strcpy(subsys, SYSFS_BUS_DIR);
+                       strcat(subsys, "/");
+                       strcpy(subsys, SYSFS_BUS_NAME);
                        strcat(subsys, "/");
                        strcat(subsys, bus);
-                       strcat(subsys, SYSFS_DRIVERS_DIR);
+                       strcat(subsys, "/");
+                       strcat(subsys, SYSFS_DRIVERS_NAME);
                        drivers = sysfs_open_subsystem_list(subsys);
                        if (drivers != NULL) {
                                dlist_for_each_data(drivers, curdrv, char) {
index a0273565d5610f80524a76736023eb5cb053b66b..54f22eee247abe76c16638ca418e7973349e7a1e 100644 (file)
@@ -116,14 +116,16 @@ static struct sysfs_directory *open_class_dir(const unsigned char *name)
                return NULL;
        }
 
+       if (sysfs_trailing_slash(classpath) == 0)
+               strcat(classpath, "/");
        /* 
         * We shall now treat "block" also as a class. Hence, check here
         * if "name" is "block" and proceed accordingly
         */
        if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
-               strcat(classpath, SYSFS_BLOCK_DIR);
+               strcat(classpath, SYSFS_BLOCK_NAME);
        } else {
-               strcat(classpath, SYSFS_CLASS_DIR);
+               strcat(classpath, SYSFS_CLASS_NAME);
                strcat(classpath, "/");
                strcat(classpath, name);
        }
@@ -365,10 +367,13 @@ static int get_classdev_path(const unsigned char *classname,
                 dprintf("Error getting sysfs mount path\n");
                 return -1;
        }
+       if (sysfs_trailing_slash(path) == 0)
+               strcat(path, "/");
+
        if (strcmp(classname, SYSFS_BLOCK_NAME) == 0) {
-               strcat(path, SYSFS_BLOCK_DIR);
+               strcat(path, SYSFS_BLOCK_NAME);
        } else {
-               strcat(path, SYSFS_CLASS_DIR);
+               strcat(path, SYSFS_CLASS_NAME);
                strcat(path, "/");
                strcat(path, classname);
        }
index fbd046f229a297fe5c58ba0d024f28518bba8623..323a43dac13ccfe93e93917ffd31318d85629854 100644 (file)
@@ -36,7 +36,9 @@ static int confirm_device_bus(struct sysfs_device *dev,
         if (sysfs_get_mnt_path(devpath, SYSFS_PATH_MAX) != 0)
                 return -1;
 
-        strcat(devpath, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(devpath) == 0)
+               strcat(devpath, "/");
+        strcat(devpath, SYSFS_BUS_NAME);
         strcat(devpath, "/");
         strcat(devpath, busname);
         strcat(devpath, SYSFS_DEVICES_DIR);
@@ -306,7 +308,10 @@ static struct sysfs_directory *open_root_device_dir(const unsigned char *name)
                return NULL;
        }
 
-       strcat(rootpath, SYSFS_DEVICES_DIR);
+       if (sysfs_trailing_slash(rootpath) == 0)
+               strcat(rootpath, "/");
+               
+       strcat(rootpath, SYSFS_DEVICES_NAME);
        strcat(rootpath, "/");
        strcat(rootpath, name);
        rdir = sysfs_open_directory(rootpath);
@@ -435,7 +440,9 @@ static int get_device_absolute_path(const unsigned char *device,
                dprintf ("Sysfs not supported on this system\n");
                return -1;
        }
-       strcat(bus_path, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(bus_path) == 0)
+               strcat(bus_path, "/");
+       strcat(bus_path, SYSFS_BUS_NAME);
        strcat(bus_path, "/");
        strcat(bus_path, bus);
        strcat(bus_path, SYSFS_DEVICES_DIR);
index 0011177e9959b6de8218e42070e9519045ba37f4..1877dbce0b1f40480ef4052a0dde578960d6dea0 100644 (file)
@@ -182,7 +182,9 @@ static int get_driver_path(const unsigned char *bus, const unsigned char *drv,
                dprintf("Error getting sysfs mount path\n");
                return -1;
        }
-       strcat(path, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(path) == 0)
+               strcat(path, "/");
+       strcat(path, SYSFS_BUS_NAME);
        strcat(path, "/");
        strcat(path, bus);
        strcat(path, SYSFS_DRIVERS_DIR);
index 4e96051c780452809f087efb52bf543f3855b021..627e618dceaf699dd811e091e09980126d4e711f 100644 (file)
@@ -76,6 +76,23 @@ static int sysfs_get_fs_mnt_path(const unsigned char *fs_type,
 #endif
 }
 
+/*
+ * sysfs_trailing_slash: checks if there's a trailing slash to path
+ * @path: path to check
+ * returns 1 if true and 0 if not
+ */
+int sysfs_trailing_slash(unsigned char *path)
+{
+       unsigned char *s = NULL;
+
+       if (path == NULL)
+               return 0;
+       s = &path[strlen(path)-1];
+       if (strncmp(s, "/", 1) == 0)
+               return 1;
+       return 0;
+}
+
 /*
  * sysfs_get_mnt_path: Gets the sysfs mount point.
  * @mnt_path: place to put "sysfs" mount point
@@ -226,6 +243,8 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
                return NULL;
        }
 
+       if (sysfs_trailing_slash(sysfs_path) == 0)
+               strcat(sysfs_path, "/");
        strcat(sysfs_path, name);
        dir = sysfs_open_directory(sysfs_path);
        if (dir == NULL) {
@@ -301,7 +320,9 @@ struct dlist *sysfs_open_bus_devices_list(unsigned char *name)
                return NULL;
        }
 
-       strcat(sysfs_path, SYSFS_BUS_DIR);
+       if (sysfs_trailing_slash(sysfs_path) == 0)
+               strcat(sysfs_path, "/");
+       strcat(sysfs_path, SYSFS_BUS_NAME);
        strcat(sysfs_path, "/");
        strcat(sysfs_path, name);
        strcat(sysfs_path, SYSFS_DEVICES_DIR);