udevtrigger: extend scan_subdir function
authorGabor Juhos <juhosg@openwrt.org>
Wed, 11 Sep 2013 14:10:14 +0000 (16:10 +0200)
committerJohn Crispin <blogic@openwrt.org>
Fri, 13 Sep 2013 15:36:58 +0000 (17:36 +0200)
Add more arguments to the function to make it
usable recursively.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
udevtrigger.c

index 2f1af35488159d1ae10002a3907a9cdda5cc8556..5a9acacbcdf6acd633cf99591b19d73877409ba7 100644 (file)
@@ -179,7 +179,8 @@ static int device_list_insert(const char *path)
        return 0;
 }
 
-static void scan_subdir(const char *base)
+static void scan_subdir(const char *base, const char *subdir,
+                       bool insert, int depth)
 {
        DIR *dir;
        struct dirent *dent;
@@ -197,7 +198,20 @@ static void scan_subdir(const char *base)
                strlcpy(dirname, base, sizeof(dirname));
                strlcat(dirname, "/", sizeof(dirname));
                strlcat(dirname, dent->d_name, sizeof(dirname));
-               device_list_insert(dirname);
+
+               if (insert) {
+                       int err;
+
+                       err = device_list_insert(dirname);
+                       if (err)
+                               continue;
+               }
+
+               if (subdir)
+                       strlcat(dirname, subdir, sizeof(base));
+
+               if (depth)
+                       scan_subdir(dirname, NULL, true, depth - 1);
        }
 
        closedir(dir);
@@ -228,7 +242,7 @@ static void scan_subsystem(const char *subsys)
                strlcat(dirname, "/devices", sizeof(dirname));
 
                /* look for devices */
-               scan_subdir(dirname);
+               scan_subdir(dirname, NULL, true, 0);
        }
 
        closedir(dir);
@@ -259,7 +273,7 @@ static void scan_block(void)
                        continue;
 
                /* look for partitions */
-               scan_subdir(dirname);
+               scan_subdir(dirname, NULL, true, 0);
        }
 
        closedir(dir);
@@ -287,7 +301,7 @@ static void scan_class(void)
                strlcat(dirname, "/", sizeof(dirname));
                strlcat(dirname, dent->d_name, sizeof(dirname));
 
-               scan_subdir(dirname);
+               scan_subdir(dirname, NULL, true, 0);
        }
 
        closedir(dir);