From 3a698a2a1aad368d33b08d405fbc44d39f63982a Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Wed, 11 Sep 2013 16:10:14 +0200 Subject: [PATCH] udevtrigger: extend scan_subdir function Add more arguments to the function to make it usable recursively. Signed-off-by: Gabor Juhos --- udevtrigger.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/udevtrigger.c b/udevtrigger.c index 2f1af35..5a9acac 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -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); -- 2.25.1