chiark / gitweb /
libudev: enumerate - ignore regular files while scanning
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 1 Oct 2008 11:57:39 +0000 (13:57 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 1 Oct 2008 11:57:39 +0000 (13:57 +0200)
udev/lib/libudev-enumerate.c
udev/lib/libudev-util.c
udev/lib/test-libudev.c

index 0377649..7d2d592 100644 (file)
@@ -200,7 +200,8 @@ static int match_attr(struct udev_enumerate *udev_enumerate, const char *syspath
        return 1;
 }
 
-static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir1, const char *subdir2)
+static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
+                                   const char *basedir, const char *subdir1, const char *subdir2)
 {
        struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
        char path[UTIL_PATH_SIZE];
@@ -231,11 +232,16 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, const
                util_strlcpy(syspath, path, sizeof(syspath));
                util_strlcat(syspath, "/", sizeof(syspath));
                util_strlcat(syspath, dent->d_name, sizeof(syspath));
+               if (lstat(syspath, &statbuf) != 0)
+                       continue;
+               if (S_ISREG(statbuf.st_mode))
+                       continue;
+               if (S_ISLNK(statbuf.st_mode))
+                       util_resolve_sys_link(udev, syspath, sizeof(syspath));
                util_strlcpy(filename, syspath, sizeof(filename));
                util_strlcat(filename, "/uevent", sizeof(filename));
                if (stat(filename, &statbuf) != 0)
                        continue;
-               util_resolve_sys_link(udev, syspath, sizeof(syspath));
                if (!match_attr(udev_enumerate, syspath))
                        continue;
                list_entry_add(udev, &udev_enumerate->devices_list, syspath, NULL, 1, 1);
@@ -262,7 +268,7 @@ static int match_subsystem(struct udev_enumerate *udev_enumerate, const char *su
        return 1;
 }
 
-static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *match)
+static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
 {
        struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
 
@@ -279,7 +285,7 @@ static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir,
        for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
                if (dent->d_name[0] == '.')
                        continue;
-               if (!match_subsystem(udev_enumerate, match != NULL ? match : dent->d_name))
+               if (!match_subsystem(udev_enumerate, subsystem != NULL ? subsystem : dent->d_name))
                        continue;
                scan_dir_and_add_devices(udev_enumerate, basedir, dent->d_name, subdir);
        }
@@ -400,7 +406,9 @@ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
                info(udev, "searching '%s/*' dir\n", subsysdir);
                scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
        }
-       info(udev, "searching '%s/*/drivers/*' dir\n", subsysdir);
-       scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");
+       if (match_subsystem(udev_enumerate, "drivers")) {
+               info(udev, "searching '%s/*/drivers/*' dir\n", subsysdir);
+               scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");
+       }
        return 0;
 }
index 0e5bc37..55bac9a 100644 (file)
@@ -64,17 +64,12 @@ ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver
 
 int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size)
 {
-       struct stat statbuf;
        char link_target[UTIL_PATH_SIZE];
 
        int len;
        int i;
        int back;
 
-       if (lstat(syspath, &statbuf) < 0)
-               return -1;
-       if (!S_ISLNK(statbuf.st_mode))
-               return -1;
        len = readlink(syspath, link_target, sizeof(link_target));
        if (len <= 0)
                return -1;
index 9c7acb0..7291e8c 100644 (file)
@@ -366,7 +366,7 @@ int main(int argc, char *argv[], char *envp[])
        test_enumerate_print_list(udev_enumerate);
        udev_enumerate_unref(udev_enumerate);
 
-       printf("enumerate '!block'\n");
+       printf("enumerate 'not block'\n");
        udev_enumerate = udev_enumerate_new(udev);
        if (udev_enumerate == NULL)
                return -1;