From 361d5950b2c7884295122a782b668edf6bae429a Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Fri, 2 Dec 2022 17:20:32 +0000 Subject: [PATCH] modprobe: Make /proc/modules optional Currently, /proc/modules is a strong requirement for loading modules. This is problematic as procfs might not always be available. Checking /proc/modules only allows to flag if a module is already present to avoid loading it. It's something the kernel handles well already (finit_module returns EEXIST). So if this might be good to have, not being able to check the module presence shouldn't prevent modprobe from trying. --- toys/pending/modprobe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c index 1c4b7fe6..133d8785 100644 --- a/toys/pending/modprobe.c +++ b/toys/pending/modprobe.c @@ -489,15 +489,15 @@ void modprobe_main(void) } // Read /proc/modules to get loaded modules. - fs = xfopen("/proc/modules", "r"); - - while (read_line(fs, &procline) > 0) { + fs = fopen("/proc/modules", "r"); + + while (fs && read_line(fs, &procline) > 0) { *strchr(procline, ' ') = 0; get_mod(procline, 1)->flags = MOD_ALOADED; free(procline); procline = NULL; } - fclose(fs); + if (fs) fclose(fs); if (FLAG(a) || FLAG(r)) for (; *argv; argv++) add_mod(*argv); else { add_mod(*argv); -- 2.39.2