summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-09-10 12:59:23 +0200
committerFelix Fietkau <nbd@openwrt.org>2013-09-10 13:25:35 +0200
commit92b3b9ae934a631d9f872c66e39fc2f82e05a642 (patch)
treeb370718c364002358c51eff76fb65ca524838100
parente6021a8a34e39328ffc867141da03c19da9b2aec (diff)
downloadunitd-92b3b9ae934a631d9f872c66e39fc2f82e05a642.tar
unitd-92b3b9ae934a631d9f872c66e39fc2f82e05a642.zip
udevtrigger: use a helper function for subdir scanning
The scan_{block,class,subsystem} functions are using identical code for scanning. Move that into a separate function to avoid code duplication. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
-rw-r--r--udevtrigger.c82
1 files changed, 25 insertions, 57 deletions
diff --git a/udevtrigger.c b/udevtrigger.c
index af620c2..fd293a4 100644
--- a/udevtrigger.c
+++ b/udevtrigger.c
@@ -179,6 +179,27 @@ static int device_list_insert(const char *path)
return 0;
}
+static void scan_subdir(const char *dirname)
+{
+ DIR *dir2;
+ struct dirent *dent2;
+
+ dir2 = opendir(dirname);
+ if (dir2 != NULL) {
+ for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+ char dirname2[PATH_SIZE];
+
+ if (dent2->d_name[0] == '.')
+ continue;
+
+ strlcpy(dirname2, dirname, sizeof(dirname2));
+ strlcat(dirname2, "/", sizeof(dirname2));
+ strlcat(dirname2, dent2->d_name, sizeof(dirname2));
+ device_list_insert(dirname2);
+ }
+ closedir(dir2);
+ }
+}
static void scan_subsystem(const char *subsys)
{
@@ -193,8 +214,6 @@ static void scan_subsystem(const char *subsys)
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char dirname[PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
@@ -205,21 +224,7 @@ static void scan_subsystem(const char *subsys)
strlcat(dirname, "/devices", sizeof(dirname));
/* look for devices */
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- strlcpy(dirname2, dirname, sizeof(dirname2));
- strlcat(dirname2, "/", sizeof(dirname2));
- strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- device_list_insert(dirname2);
- }
- closedir(dir2);
- }
+ scan_subdir(dirname);
}
closedir(dir);
}
@@ -237,8 +242,6 @@ static void scan_block(void)
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char dirname[PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
@@ -250,24 +253,7 @@ static void scan_block(void)
continue;
/* look for partitions */
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- if (!strcmp(dent2->d_name,"device"))
- continue;
-
- strlcpy(dirname2, dirname, sizeof(dirname2));
- strlcat(dirname2, "/", sizeof(dirname2));
- strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- device_list_insert(dirname2);
- }
- closedir(dir2);
- }
+ scan_subdir(dirname);
}
closedir(dir);
}
@@ -285,8 +271,6 @@ static void scan_class(void)
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char dirname[PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
if (dent->d_name[0] == '.')
continue;
@@ -294,24 +278,8 @@ static void scan_class(void)
strlcpy(dirname, base, sizeof(dirname));
strlcat(dirname, "/", sizeof(dirname));
strlcat(dirname, dent->d_name, sizeof(dirname));
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- if (!strcmp(dent2->d_name, "device"))
- continue;
-
- strlcpy(dirname2, dirname, sizeof(dirname2));
- strlcat(dirname2, "/", sizeof(dirname2));
- strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- device_list_insert(dirname2);
- }
- closedir(dir2);
- }
+
+ scan_subdir(dirname);
}
closedir(dir);
}