- Check for modaliases below /sys (bnc #430179)
authorMichael Andres <ma@suse.de>
Wed, 12 Nov 2008 12:24:50 +0000 (12:24 +0000)
committerMichael Andres <ma@suse.de>
Wed, 12 Nov 2008 12:24:50 +0000 (12:24 +0000)
VERSION.cmake
package/libzypp.changes
zypp/target/modalias/Modalias.cc

index 8280486..1458209 100644 (file)
@@ -59,7 +59,7 @@
 #   changes file. See './mkChangelog -h' for help.
 #
 SET(LIBZYPP_MAJOR "5")
-SET(LIBZYPP_COMPATMINOR "21")
+SET(LIBZYPP_COMPATMINOR "23")
 SET(LIBZYPP_MINOR "23")
 SET(LIBZYPP_PATCH "0")
 #
index 41c8e10..a1bd38d 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Wed Nov 12 13:19:02 CET 2008 - ma@suse.de
+
+- Check for modaliases below /sys (bnc #430179)
+- revision 11653
+
+-------------------------------------------------------------------
 Tue Nov 11 18:36:33 CET 2008 - ma@suse.de
 
 - Avoid superfluous file copying and gpg invocation in keyring handling.
index 8172a5a..a1b1605 100644 (file)
@@ -30,6 +30,7 @@ extern "C"
 #include "zypp/base/Logger.h"
 
 #include "zypp/target/modalias/Modalias.h"
+#include "zypp/PathInfo.h"
 
 
 using std::endl;
@@ -59,23 +60,38 @@ struct modalias_list {
  * If FUNC returns a non-zero return value, stop reading the directory
  * and return that value. Returns -1 if an error occurs.
  */
+
 int
-foreach_file(const char *path, int (*func)(const char *, const char *, void *),
+foreach_file_recursive(const char *path_rec, int (*func)(const char *, const char *, void *),
             void *arg)
 {
        DIR *dir;
        struct dirent *dirent;
+       char path_tmp[PATH_MAX];
        int ret = 0;
 
-       if (!(dir = opendir(path)))
+       if (!(dir = opendir(path_rec)))
                return -1;
        while ((dirent = readdir(dir)) != NULL) {
 
                if (strcmp(dirent->d_name, ".") == 0 ||
                    strcmp(dirent->d_name, "..") == 0)
                        continue;
-               if ((ret = func(path, dirent->d_name, arg)) != 0)
-                       break;
+               snprintf(path_tmp, sizeof(path_tmp), "%s/%s", path_rec, dirent->d_name);
+
+               PathInfo path(path_tmp, PathInfo::LSTAT);
+
+               if (path.isLink ()) {
+                       continue;
+               }
+               if (path.isDir ()){
+                       (void) foreach_file_recursive(path_tmp, func, arg);
+               }else if (path.isFile ()){
+                       if ((ret = func(path_rec, dirent->d_name, arg)) != 0)
+                               break;
+               }else{
+                       continue;
+               }
        }
        if (closedir(dir) != 0)
                return -1;
@@ -95,7 +111,10 @@ read_modalias(const char *dir, const char *file, void *arg)
        char modalias[PATH_MAX];
        struct modalias_list **list = (struct modalias_list **)arg, *entry;
 
-       snprintf(path, sizeof(path), "%s/%s/modalias", dir, file);
+       if (strcmp(file, "modalias") != 0){
+               return 0;
+       }
+       snprintf(path, sizeof(path), "%s/%s", dir, file);
        if ((fd = open(path, O_RDONLY)) == -1)
                return 0;
        len = read(fd, modalias, sizeof(modalias) - 1);
@@ -120,38 +139,6 @@ out:
        return 0;
 }
 
-/*
- * Iterate over all devices on a bus (/sys/bus/BUS/devices/<*>)
- * and remembers all module aliases for those devices on
- * the linked modalias list passed in in ARG.
- */
-int
-iterate_bus(const char *dir, const char *file, void *arg)
-{
-       char path[PATH_MAX];
-
-       snprintf(path, sizeof(path), "%s/%s/devices", dir, file);
-       (void) foreach_file(path, read_modalias, arg);
-
-       return 0;
-}
-
-/*
- * Iterate over all devices in a class (/sys/class/CLASS/<*>)
- * and remembers all module aliases for those devices on
- * the linked modalias list passed in in ARG.
- */
-int
-iterate_class(const char *dir, const char *file, void *arg)
-{
-       char path[PATH_MAX];
-
-       snprintf(path, sizeof(path), "%s/%s", dir, file);
-       (void) foreach_file(path, read_modalias, arg);
-
-       return 0;
-}
-
       /////////////////////////////////////////////////////////////////
     } // namespace
     ///////////////////////////////////////////////////////////////////
@@ -177,11 +164,9 @@ struct Modalias::Impl
                dir = "/sys";
        DBG << "Using /sys directory : " << dir << endl;
 
-       snprintf(path, sizeof(path), "%s/bus", dir);
-       foreach_file( path, iterate_bus, &_modaliases );
+       snprintf(path, sizeof(path), "%s", dir);
+       foreach_file_recursive( path, read_modalias, &_modaliases );
 
-       snprintf(path, sizeof(path), "%s/class", dir);
-       foreach_file( path, iterate_class, &_modaliases );
     }
 
     /** Dtor. */