plugins: modprobe: Never follow symlinks in /sys/devices

Unlike find(1), nftw(3) defaults to follow symlinks.  For some kernel
configurations this turned out to be detrimental and caused the plugin
to loop forever scanning modalias files.

Also, check if /sys is mounted before even calling nftw().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2020-04-26 14:55:38 +02:00
1 parent 3f5ff0d339
commit 2a4052bd8d
1 file changed
+11 -4
+11 -4
View File
@@ -142,11 +142,18 @@ static void coldplug(void *arg)
struct module *m, *tmp; struct module *m, *tmp;
int rc = 0; int rc = 0;
if (!fismnt("/sys")) {
print(1, "Cannot modprobe system, /sys is not mounted");
return;
}
print_desc("Cold plugging system", NULL); print_desc("Cold plugging system", NULL);
nftw("/sys/devices", scan_alias, 200, FTW_DEPTH); rc = nftw("/sys/devices", scan_alias, 200, FTW_DEPTH | FTW_PHYS);
TAILQ_FOREACH_SAFE(m, &modules, link, tmp) { if (!rc) {
rc += modprobe(m->alias); TAILQ_FOREACH_SAFE(m, &modules, link, tmp) {
alias_remove(m); rc += modprobe(m->alias);
alias_remove(m);
}
} }
print_result(rc); print_result(rc);