From 2a4052bd8d227fa9ecd74ba2006eba45f4f08352 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 26 Apr 2020 14:09:59 +0200 Subject: [PATCH] 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 --- plugins/modprobe.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/modprobe.c b/plugins/modprobe.c index bcb4ed78..0cb0f311 100644 --- a/plugins/modprobe.c +++ b/plugins/modprobe.c @@ -142,11 +142,18 @@ static void coldplug(void *arg) struct module *m, *tmp; int rc = 0; + if (!fismnt("/sys")) { + print(1, "Cannot modprobe system, /sys is not mounted"); + return; + } + print_desc("Cold plugging system", NULL); - nftw("/sys/devices", scan_alias, 200, FTW_DEPTH); - TAILQ_FOREACH_SAFE(m, &modules, link, tmp) { - rc += modprobe(m->alias); - alias_remove(m); + rc = nftw("/sys/devices", scan_alias, 200, FTW_DEPTH | FTW_PHYS); + if (!rc) { + TAILQ_FOREACH_SAFE(m, &modules, link, tmp) { + rc += modprobe(m->alias); + alias_remove(m); + } } print_result(rc);