blob: 3474964f8f3e0c75f99f641be4d3e5d7db6abbcf [file] [log] [blame]
Eric Andersen0139ca92001-07-22 23:01:03 +00001/* vi: set sw=4 ts=4: */
2/*
Robert Grieblaead70b2002-07-26 15:54:20 +00003 * Modprobe written from scratch for BusyBox
Eric Andersen60e56f52002-04-26 06:04:01 +00004 *
Denis Vlasenkoba1315d2008-09-13 14:59:38 +00005 * Copyright (c) 2008 Timo Teras <timo.teras@iki.fi>
6 * Copyright (c) 2008 Vladimir Dronnikov
Robert Griebl6859d762002-08-05 02:57:12 +00007 *
Rob Landley79e1cab2005-11-15 00:08:29 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Denis Vlasenkoba1315d2008-09-13 14:59:38 +00009 */
Eric Andersen0139ca92001-07-22 23:01:03 +000010
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000012#include "modutils.h"
Robert Griebl52e8d062002-05-14 23:42:08 +000013#include <sys/utsname.h>
Bernhard Reutner-Fischer2c351a82006-06-03 19:08:49 +000014#include <fnmatch.h>
Eric Andersen0139ca92001-07-22 23:01:03 +000015
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +000016//#define DBG(...) bb_error_msg(__VA_ARGS__)
17#define DBG(...) ((void)0)
18
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000019#define MODULE_FLAG_LOADED 0x0001
20#define MODULE_FLAG_NEED_DEPS 0x0002
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +000021/* "was seen in modules.dep": */
22#define MODULE_FLAG_FOUND_IN_MODDEP 0x0004
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000023#define MODULE_FLAG_BLACKLISTED 0x0008
24
25struct module_entry { /* I'll call it ME. */
26 unsigned flags;
27 char *modname; /* stripped of /path/, .ext and s/-/_/g */
28 const char *probed_name; /* verbatim as seen on cmdline */
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +000029 char *options; /* options from config files */
30 llist_t *realnames; /* strings. if this module is an alias, */
31 /* real module name is one of these. */
32//Can there really be more than one? Example from real kernel?
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000033 llist_t *deps; /* strings. modules we depend on */
Eric Andersen60e56f52002-04-26 06:04:01 +000034};
35
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000036#define MODPROBE_OPTS "acdlnrt:VC:" IF_FEATURE_MODPROBE_BLACKLIST("b")
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000037enum {
38 MODPROBE_OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */
39 MODPROBE_OPT_DUMP_ONLY = (INSMOD_OPT_UNUSED << 1), /* c */
40 MODPROBE_OPT_D = (INSMOD_OPT_UNUSED << 2), /* d */
41 MODPROBE_OPT_LIST_ONLY = (INSMOD_OPT_UNUSED << 3), /* l */
42 MODPROBE_OPT_SHOW_ONLY = (INSMOD_OPT_UNUSED << 4), /* n */
43 MODPROBE_OPT_REMOVE = (INSMOD_OPT_UNUSED << 5), /* r */
44 MODPROBE_OPT_RESTRICT = (INSMOD_OPT_UNUSED << 6), /* t */
45 MODPROBE_OPT_VERONLY = (INSMOD_OPT_UNUSED << 7), /* V */
46 MODPROBE_OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << 8), /* C */
47 MODPROBE_OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 9) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
48};
49
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000050struct globals {
51 llist_t *db; /* MEs of all modules ever seen (caching for speed) */
52 llist_t *probes; /* MEs of module(s) requested on cmdline */
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +000053 char *cmdline_mopts; /* module options from cmdline */
54 int num_unresolved_deps;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000055 /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */
56 smallint need_symbols;
57};
58#define G (*(struct globals*)&bb_common_bufsiz1)
59#define INIT_G() do { } while (0)
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000060
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000061
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000062static int read_config(const char *path);
63
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +000064static char *gather_options_str(char *opts, const char *append)
65{
66 /* Speed-optimized. We call gather_options_str many times. */
67 if (opts == NULL) {
68 opts = xstrdup(append);
69 } else {
70 int optlen = strlen(opts);
71 opts = xrealloc(opts, optlen + strlen(append) + 2);
72 sprintf(opts + optlen, " %s", append);
73 }
74 return opts;
75}
76
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000077static struct module_entry *helper_get_module(const char *module, int create)
Denis Vlasenkof45c4f42008-06-16 04:09:25 +000078{
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000079 char modname[MODULE_NAME_LEN];
80 struct module_entry *e;
81 llist_t *l;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000082
Denis Vlasenko0e2f3622009-03-05 16:32:27 +000083 filename2modname(module, modname);
84 for (l = G.db; l != NULL; l = l->link) {
85 e = (struct module_entry *) l->data;
86 if (strcmp(e->modname, modname) == 0)
87 return e;
88 }
89 if (!create)
90 return NULL;
91
92 e = xzalloc(sizeof(*e));
93 e->modname = xstrdup(modname);
94 llist_add_to(&G.db, e);
95
96 return e;
97}
98static struct module_entry *get_or_add_modentry(const char *module)
99{
100 return helper_get_module(module, 1);
101}
102static struct module_entry *get_modentry(const char *module)
103{
104 return helper_get_module(module, 0);
105}
106
107static void add_probe(const char *name)
108{
109 struct module_entry *m;
110
111 m = get_or_add_modentry(name);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000112 if (m->flags & MODULE_FLAG_LOADED) {
113 DBG("skipping %s, it is already loaded", name);
114 return;
115 }
116
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000117 m->probed_name = name;
118 m->flags |= MODULE_FLAG_NEED_DEPS;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000119 llist_add_to_end(&G.probes, m);
120 G.num_unresolved_deps++;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000121 if (ENABLE_FEATURE_MODUTILS_SYMBOLS
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000122 && strncmp(m->modname, "symbol:", 7) == 0
123 ) {
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000124 G.need_symbols = 1;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000125 }
Denis Vlasenko9ddc8d52008-05-18 14:39:43 +0000126}
127
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000128static int FAST_FUNC config_file_action(const char *filename,
129 struct stat *statbuf UNUSED_PARAM,
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000130 void *userdata UNUSED_PARAM,
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000131 int depth UNUSED_PARAM)
Rob Landley72615752006-04-10 16:09:52 +0000132{
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000133 char *tokens[3];
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000134 parser_t *p;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000135 struct module_entry *m;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000136 int rc = TRUE;
Denis Vlasenkoe1ee48e2008-07-29 00:19:44 +0000137
138 if (bb_basename(filename)[0] == '.')
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000139 goto error;
Denis Vlasenkoe1ee48e2008-07-29 00:19:44 +0000140
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000141 p = config_open2(filename, fopen_for_read);
142 if (p == NULL) {
143 rc = FALSE;
144 goto error;
145 }
Rob Landley72615752006-04-10 16:09:52 +0000146
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000147 while (config_read(p, tokens, 3, 2, "# \t", PARSE_NORMAL)) {
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000148//Use index_in_strings?
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000149 if (strcmp(tokens[0], "alias") == 0) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000150 /* alias <wildcard> <modulename> */
151 llist_t *l;
152 char wildcard[MODULE_NAME_LEN];
153 char *rmod;
154
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000155 if (tokens[2] == NULL)
156 continue;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000157 filename2modname(tokens[1], wildcard);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000158
159 for (l = G.probes; l != NULL; l = l->link) {
160 m = (struct module_entry *) l->data;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000161 if (fnmatch(wildcard, m->modname, 0) != 0)
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000162 continue;
163 rmod = filename2modname(tokens[2], NULL);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000164 llist_add_to(&m->realnames, rmod);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000165
166 if (m->flags & MODULE_FLAG_NEED_DEPS) {
167 m->flags &= ~MODULE_FLAG_NEED_DEPS;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000168 G.num_unresolved_deps--;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000169 }
170
171 m = get_or_add_modentry(rmod);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000172 if (!(m->flags & MODULE_FLAG_NEED_DEPS)) {
173 m->flags |= MODULE_FLAG_NEED_DEPS;
174 G.num_unresolved_deps++;
175 }
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000176 }
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000177 } else if (strcmp(tokens[0], "options") == 0) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000178 /* options <modulename> <option...> */
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000179 if (tokens[2] == NULL)
180 continue;
181 m = get_or_add_modentry(tokens[1]);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000182 m->options = gather_options_str(m->options, tokens[2]);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000183 } else if (strcmp(tokens[0], "include") == 0) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000184 /* include <filename> */
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000185 read_config(tokens[1]);
186 } else if (ENABLE_FEATURE_MODPROBE_BLACKLIST
187 && strcmp(tokens[0], "blacklist") == 0
188 ) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000189 /* blacklist <modulename> */
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000190 get_or_add_modentry(tokens[1])->flags |= MODULE_FLAG_BLACKLISTED;
Rob Landley72615752006-04-10 16:09:52 +0000191 }
Rob Landleye9190962005-12-12 19:38:44 +0000192 }
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000193 config_close(p);
194error:
Robert Griebl52e8d062002-05-14 23:42:08 +0000195 return rc;
196}
197
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000198static int read_config(const char *path)
Robert Griebl52e8d062002-05-14 23:42:08 +0000199{
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000200 return recursive_action(path, ACTION_RECURSE | ACTION_QUIET,
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000201 config_file_action, NULL, NULL, 1);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000202}
Eric Andersen3b1a7442003-12-24 20:30:45 +0000203
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000204static int do_modprobe(struct module_entry *m)
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000205{
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000206 struct module_entry *m2;
207 char *fn, *options;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000208 int rc = -1;
209
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000210 if (!(m->flags & MODULE_FLAG_FOUND_IN_MODDEP)) {
211 DBG("skipping %s, not found in modules.dep", m->modname);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000212 return -ENOENT;
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000213 }
214 DBG("do_modprob'ing %s", m->modname);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000215
216 if (!(option_mask32 & MODPROBE_OPT_REMOVE))
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000217 m->deps = llist_rev(m->deps);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000218
219 rc = 0;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000220 while (m->deps && rc == 0) {
221 fn = llist_pop(&m->deps);
222 m2 = get_or_add_modentry(fn);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000223 if (option_mask32 & MODPROBE_OPT_REMOVE) {
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000224 if (bb_delete_module(m->modname, O_EXCL) != 0)
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000225 rc = errno;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000226 } else if (!(m2->flags & MODULE_FLAG_LOADED)) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000227 options = m2->options;
228 m2->options = NULL;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000229 if (m == m2)
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000230 options = gather_options_str(options, G.cmdline_mopts);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000231 rc = bb_init_module(fn, options);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000232 DBG("loaded %s '%s', rc:%d", fn, options, rc);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000233 if (rc == 0)
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000234 m2->flags |= MODULE_FLAG_LOADED;
Denis Vlasenko9604e1b2009-03-03 18:47:56 +0000235 free(options);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000236 } else {
237 DBG("%s is already loaded, skipping", fn);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000238 }
239
Denis Vlasenko9604e1b2009-03-03 18:47:56 +0000240 free(fn);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000241 }
242
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000243//FIXME: what if rc < 0?
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000244 if (rc > 0 && !(option_mask32 & INSMOD_OPT_SILENT)) {
Denis Vlasenko54d10052008-12-24 03:11:43 +0000245 bb_error_msg("failed to %sload module %s: %s",
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000246 (option_mask32 & MODPROBE_OPT_REMOVE) ? "un" : "",
247 m->probed_name ? m->probed_name : m->modname,
248 moderror(rc)
249 );
250 }
Denis Vlasenko9604e1b2009-03-03 18:47:56 +0000251
Eric Andersen908e3622003-06-20 09:56:37 +0000252 return rc;
Robert Griebl52e8d062002-05-14 23:42:08 +0000253}
254
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000255static void load_modules_dep(void)
256{
257 struct module_entry *m;
258 char *colon, *tokens[2];
259 parser_t *p;
260
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000261 /* Modprobe does not work at all without modprobe.dep,
262 * even if the full module name is given. Returning error here
263 * was making us later confuse user with this message:
264 * "module /full/path/to/existing/file/module.ko not found".
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000265 * It's better to die immediately, with good message.
266 * xfopen_for_read provides that. */
267 p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000268
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000269 while (G.num_unresolved_deps
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000270 && config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)
271 ) {
272 colon = last_char_is(tokens[0], ':');
273 if (colon == NULL)
274 continue;
275 *colon = 0;
276
277 m = get_modentry(tokens[0]);
278 if (m == NULL)
279 continue;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000280
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000281 /* Optimization... */
282 if ((m->flags & MODULE_FLAG_LOADED)
283 && !(option_mask32 & MODPROBE_OPT_REMOVE)
284 ) {
285 DBG("skip deps of %s, it's already loaded", tokens[0]);
286 continue;
287 }
288
289 m->flags |= MODULE_FLAG_FOUND_IN_MODDEP;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000290 if ((m->flags & MODULE_FLAG_NEED_DEPS) && (m->deps == NULL)) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000291 G.num_unresolved_deps--;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000292 llist_add_to(&m->deps, xstrdup(tokens[0]));
293 if (tokens[1])
294 string_to_llist(tokens[1], &m->deps, " ");
295 }
296 }
297 config_close(p);
298}
299
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000300int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenko9ddc0042008-08-06 00:51:43 +0000301int modprobe_main(int argc UNUSED_PARAM, char **argv)
Eric Andersen0139ca92001-07-22 23:01:03 +0000302{
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000303 struct utsname uts;
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000304 int rc;
305 unsigned opt;
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000306 struct module_entry *me;
Eric Andersen0139ca92001-07-22 23:01:03 +0000307
Denis Vlasenkoe7fca512007-11-10 01:32:18 +0000308 opt_complementary = "q-v:v-q";
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000309 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS, NULL, NULL);
Denis Vlasenko9ddc0042008-08-06 00:51:43 +0000310 argv += optind;
Denis Vlasenkob68979a2007-11-02 23:31:10 +0000311
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000312 if (opt & (MODPROBE_OPT_DUMP_ONLY | MODPROBE_OPT_LIST_ONLY |
313 MODPROBE_OPT_SHOW_ONLY))
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000314 bb_error_msg_and_die("not supported");
Robert Griebl236abbf2002-05-22 23:34:35 +0000315
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000316 if (!argv[0]) {
317 if (opt & MODPROBE_OPT_REMOVE) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000318 /* "modprobe -r" (w/o params).
319 * "If name is NULL, all unused modules marked
320 * autoclean will be removed".
321 */
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000322 if (bb_delete_module(NULL, O_NONBLOCK|O_EXCL) != 0)
323 bb_perror_msg_and_die("rmmod");
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000324 }
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000325 return EXIT_SUCCESS;
326 }
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000327
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000328 /* Goto modules location */
329 xchdir(CONFIG_DEFAULT_MODULES_DIR);
330 uname(&uts);
331 xchdir(uts.release);
Eric Andersen0139ca92001-07-22 23:01:03 +0000332
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000333 /* Retrieve module names of already loaded modules */
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000334 {
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000335 char *s;
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000336 parser_t *parser = config_open2("/proc/modules", fopen_for_read);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000337 while (config_read(parser, &s, 1, 1, "# \t", PARSE_NORMAL & ~PARSE_GREEDY))
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000338 get_or_add_modentry(s)->flags |= MODULE_FLAG_LOADED;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000339 config_close(parser);
340 }
Eric Andersen3b1a7442003-12-24 20:30:45 +0000341
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000342 if (opt & MODPROBE_OPT_INSERT_ALL) {
343 /* Each argument is a module name */
344 do {
345 add_probe(*argv++);
346 } while (*argv);
347 } else {
348 /* First argument is module name, rest are parameters */
349 add_probe(argv[0]);
350 G.cmdline_mopts = parse_cmdline_module_options(argv);
351 }
352
353 /* Happens if all requested modules are already loaded */
354 if (G.probes == NULL)
355 return EXIT_SUCCESS;
356
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000357 read_config("/etc/modprobe.conf");
358 read_config("/etc/modprobe.d");
359 if (ENABLE_FEATURE_MODUTILS_SYMBOLS && G.need_symbols)
360 read_config("modules.symbols");
361 load_modules_dep();
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000362 if (ENABLE_FEATURE_MODUTILS_ALIAS && G.num_unresolved_deps) {
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000363 read_config("modules.alias");
364 load_modules_dep();
365 }
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000366
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000367 while ((me = llist_pop(&G.probes)) != NULL) {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000368 if (me->realnames == NULL) {
369 /* This is not an alias. Literal names are blacklisted
370 * only if '-b' is given.
371 */
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000372 if (!(opt & MODPROBE_OPT_BLACKLIST)
373 || !(me->flags & MODULE_FLAG_BLACKLISTED)
374 ) {
375 rc = do_modprobe(me);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000376//FIXME: what if rc > 0?
Denis Vlasenkobb26db42008-10-31 02:04:28 +0000377 if (rc < 0 && !(opt & INSMOD_OPT_SILENT))
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000378 bb_error_msg("module %s not found",
379 me->probed_name);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000380 }
381 } else {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000382 /* Probe all realnames */
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000383 do {
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000384 char *realname = llist_pop(&me->realnames);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000385 struct module_entry *m2;
386
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000387 DBG("probing %s by realname %s", me->modname, realname);
Denis Vlasenko0e2f3622009-03-05 16:32:27 +0000388 m2 = get_or_add_modentry(realname);
389 if (!(m2->flags & MODULE_FLAG_BLACKLISTED))
390 do_modprobe(m2);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000391//FIXME: error check?
Denis Vlasenko9604e1b2009-03-03 18:47:56 +0000392 free(realname);
Denis Vlasenkoa6b6f052009-03-06 22:48:11 +0000393 } while (me->realnames != NULL);
Denis Vlasenkoba1315d2008-09-13 14:59:38 +0000394 }
395 }
396
397 return EXIT_SUCCESS;
Eric Andersen0139ca92001-07-22 23:01:03 +0000398}