aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/modprobe.c
diff options
context:
space:
mode:
authorSteve Muckle <smuckle@google.com>2017-01-09 11:54:20 -0800
committerRob Landley <rob@landley.net>2017-01-28 16:50:01 -0600
commit066f230dd89952671a5faae172e6c73a9af08512 (patch)
tree0e6293f2817e6533603c4a65638ed362cb8e5b8d /toys/pending/modprobe.c
parent8b2646e1c048163e01a8dd7349f1e23d21ad76b0 (diff)
downloadtoybox-066f230dd89952671a5faae172e6c73a9af08512.tar.gz
modprobe: add -d option to specify module directory path(s)
While most systems have their kernel modules, modules.dep etc located at /lib/modules/`uname -r` this is not always the case. The -d option may be used to specify a nonstandard path for these files. It may be used more than once to specify multiple directories where these files may be found.
Diffstat (limited to 'toys/pending/modprobe.c')
-rw-r--r--toys/pending/modprobe.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c
index 7c93a5cd..50ec60f5 100644
--- a/toys/pending/modprobe.c
+++ b/toys/pending/modprobe.c
@@ -5,17 +5,18 @@
*
* No Standard.
-USE_MODPROBE(NEWTOY(modprobe, "alrqvsDb", TOYFLAG_SBIN))
+USE_MODPROBE(NEWTOY(modprobe, "alrqvsDbd*", TOYFLAG_SBIN))
config MODPROBE
bool "modprobe"
default n
help
- usage: modprobe [-alrqvsDb] MODULE [symbol=value][...]
+ usage: modprobe [-alrqvsDb] [-d DIR] MODULE [symbol=value][...]
modprobe utility - inserts modules and dependencies.
-a Load multiple MODULEs
+ -d Load modules from DIR, option may be used multiple times
-l List (MODULE is a pattern)
-r Remove MODULE (stacks) or do autoclean
-q Quiet
@@ -29,6 +30,7 @@ config MODPROBE
#include <sys/syscall.h>
GLOBALS(
+ struct arg_list *dirs;
struct arg_list *probes;
struct arg_list *dbase[256];
char *cmdopts;
@@ -42,6 +44,7 @@ GLOBALS(
*/
#define DBASE_SIZE 256
#define MODNAME_LEN 256
+#define MODULE_BASE_DIR "/lib/modules/"
// Modules flag definations
#define MOD_ALOADED 0x0001
@@ -492,6 +495,7 @@ void modprobe_main(void)
FILE *fs;
struct module_s *module;
unsigned flags = toys.optflags;
+ struct arg_list *dirs;
TT.dbg = (flags & FLAG_v) ? xprintf : dummy;
@@ -506,16 +510,24 @@ void modprobe_main(void)
return;
}
- // change directory to /lib/modules/<release>/
- xchdir("/lib/modules");
- uname(&uts);
- xchdir(uts.release);
+ if (!TT.dirs) {
+ uname(&uts);
+ TT.dirs = xzalloc(sizeof(struct arg_list));
+ TT.dirs->arg = xmalloc(strlen(MODULE_BASE_DIR) + strlen(uts.release) + 1);
+ strcpy(TT.dirs->arg, MODULE_BASE_DIR);
+ strcat(TT.dirs->arg, uts.release);
+ }
// modules.dep processing for dependency check.
if (flags & FLAG_l) {
- if (depmode_read_entry(toys.optargs[0])) error_exit("no module found.");
- return;
+ for (dirs = TT.dirs; dirs; dirs = dirs->next) {
+ xchdir(dirs->arg);
+ if (!depmode_read_entry(toys.optargs[0]))
+ return;
+ }
+ error_exit("no module found.");
}
+
// Read /proc/modules to get loaded modules.
fs = xfopen("/proc/modules", "r");
@@ -540,9 +552,18 @@ void modprobe_main(void)
}
dirtree_read("/etc/modprobe.conf", config_action);
dirtree_read("/etc/modprobe.d", config_action);
- if (TT.symreq) dirtree_read("modules.symbols", config_action);
- if (TT.nudeps) dirtree_read("modules.alias", config_action);
- find_dep();
+
+ for (dirs = TT.dirs; dirs; dirs = dirs->next) {
+ xchdir(dirs->arg);
+ if (TT.symreq) dirtree_read("modules.symbols", config_action);
+ if (TT.nudeps) dirtree_read("modules.alias", config_action);
+ }
+
+ for (dirs = TT.dirs; dirs; dirs = dirs->next) {
+ xchdir(dirs->arg);
+ find_dep();
+ }
+
while ((module = llist_popme(&TT.probes))) {
if (!module->rnames) {
TT.dbg("probing by module name\n");