ref: 130ac62c49a796d558f9b3b6a343bdac870a9cdd
parent: f7f60d610e921146415db59b501a78bde8f6bf1f
author: Timo Teräs <timo.teras@iki.fi>
date: Fri Mar 11 05:26:44 CST 2016
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
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -449,7 +449,7 @@
};
/* 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 @@
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 @@
return 0;
}
- recurse_dir(mountdir, &opts);
+ recurse_dir(mountdir, &opts, 2);
if (repos.count > 0)
rc |= FOUND_BOOTREPO;
@@ -804,9 +805,9 @@
};
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;
}