aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-03-11 11:26:44 +0200
committerTimo Teräs <timo.teras@iki.fi>2016-03-11 11:30:16 +0200
commit130ac62c49a796d558f9b3b6a343bdac870a9cdd (patch)
tree7973a846509c64b0f5ed13aa0729ae162cbece00
parentf7f60d610e921146415db59b501a78bde8f6bf1f (diff)
downloadmkinitfs-130ac62c49a796d558f9b3b6a343bdac870a9cdd.tar.bz2
mkinitfs-130ac62c49a796d558f9b3b6a343bdac870a9cdd.tar.xz
nlplug-findfs: limit recursion depth
Based on patch by donoban. Limit recursion depth for repository search to 2 levels (shell script had -maxdepth 3 for finding the file entry, so it's maximum of 2 levels of directories). For sysfs entries deeper search is allowed. ref #5192
-rw-r--r--nlplug-findfs.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/nlplug-findfs.c b/nlplug-findfs.c
index b2b5ac8..b93a5a9 100644
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -449,7 +449,7 @@ struct recurse_opts {
};
/* pathbuf needs hold PATH_MAX chars */
-static void recurse_dir(char *pathbuf, struct recurse_opts *opts)
+static void recurse_dir(char *pathbuf, struct recurse_opts *opts, int depth)
{
DIR *d = opendir(pathbuf);
struct dirent *entry;
@@ -492,9 +492,10 @@ static void recurse_dir(char *pathbuf, struct recurse_opts *opts)
goto next;
}
- if (is_dir)
- recurse_dir(pathbuf, opts);
- else
+ if (is_dir) {
+ if (depth > 0)
+ recurse_dir(pathbuf, opts, depth - 1);
+ } else
opts->callback(pathbuf, opts->userdata);
next:
pathbuf[pathlen] = '\0';
@@ -587,7 +588,7 @@ static int find_bootrepos(const char *devnode, const char *type,
return 0;
}
- recurse_dir(mountdir, &opts);
+ recurse_dir(mountdir, &opts, 2);
if (repos.count > 0)
rc |= FOUND_BOOTREPO;
@@ -804,9 +805,9 @@ static void *trigger_thread(void *data)
};
char path[PATH_MAX] = "/sys/bus";
- recurse_dir(path, &opts);
+ recurse_dir(path, &opts, 8);
strcpy(path, "/sys/devices");
- recurse_dir(path, &opts);
+ recurse_dir(path, &opts, 8);
write(fd, &ok, sizeof(ok));
return NULL;
}