whitespace fixes
[platform/upstream/busybox.git] / modutils / modprobe.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Modprobe written from scratch for BusyBox
4  *
5  * Copyright (c) 2008 Timo Teras <timo.teras@iki.fi>
6  * Copyright (c) 2008 Vladimir Dronnikov
7  *
8  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9  */
10
11 //applet:IF_MODPROBE(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))
12
13 #include "libbb.h"
14 #include "modutils.h"
15 #include <sys/utsname.h>
16 #include <fnmatch.h>
17
18 //#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
19 #define DBG(...) ((void)0)
20
21 /* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t),
22  * we expect the full dependency list to be specified in modules.dep.
23  * Older versions would only export the direct dependency list.
24  */
25
26
27 //usage:#if !ENABLE_MODPROBE_SMALL
28 //usage:#define modprobe_notes_usage
29 //usage:        "modprobe can (un)load a stack of modules, passing each module options (when\n"
30 //usage:        "loading). modprobe uses a configuration file to determine what option(s) to\n"
31 //usage:        "pass each module it loads.\n"
32 //usage:        "\n"
33 //usage:        "The configuration file is searched (in this order):\n"
34 //usage:        "\n"
35 //usage:        "    /etc/modprobe.conf (2.6 only)\n"
36 //usage:        "    /etc/modules.conf\n"
37 //usage:        "    /etc/conf.modules (deprecated)\n"
38 //usage:        "\n"
39 //usage:        "They all have the same syntax (see below). If none is present, it is\n"
40 //usage:        "_not_ an error; each loaded module is then expected to load without\n"
41 //usage:        "options. Once a file is found, the others are tested for.\n"
42 //usage:        "\n"
43 //usage:        "/etc/modules.conf entry format:\n"
44 //usage:        "\n"
45 //usage:        "  alias <alias_name> <mod_name>\n"
46 //usage:        "    Makes it possible to modprobe alias_name, when there is no such module.\n"
47 //usage:        "    It makes sense if your mod_name is long, or you want a more representative\n"
48 //usage:        "    name for that module (eg. 'scsi' in place of 'aha7xxx').\n"
49 //usage:        "    This makes it also possible to use a different set of options (below) for\n"
50 //usage:        "    the module and the alias.\n"
51 //usage:        "    A module can be aliased more than once.\n"
52 //usage:        "\n"
53 //usage:        "  options <mod_name|alias_name> <symbol=value...>\n"
54 //usage:        "    When loading module mod_name (or the module aliased by alias_name), pass\n"
55 //usage:        "    the \"symbol=value\" pairs as option to that module.\n"
56 //usage:        "\n"
57 //usage:        "Sample /etc/modules.conf file:\n"
58 //usage:        "\n"
59 //usage:        "  options tulip irq=3\n"
60 //usage:        "  alias tulip tulip2\n"
61 //usage:        "  options tulip2 irq=4 io=0x308\n"
62 //usage:        "\n"
63 //usage:        "Other functionality offered by 'classic' modprobe is not available in\n"
64 //usage:        "this implementation.\n"
65 //usage:        "\n"
66 //usage:        "If module options are present both in the config file, and on the command line,\n"
67 //usage:        "then the options from the command line will be passed to the module _after_\n"
68 //usage:        "the options from the config file. That way, you can have defaults in the config\n"
69 //usage:        "file, and override them for a specific usage from the command line.\n"
70 //usage:#define modprobe_example_usage
71 //usage:       "(with the above /etc/modules.conf):\n\n"
72 //usage:       "$ modprobe tulip\n"
73 //usage:       "   will load the module 'tulip' with default option 'irq=3'\n\n"
74 //usage:       "$ modprobe tulip irq=5\n"
75 //usage:       "   will load the module 'tulip' with option 'irq=5', thus overriding the default\n\n"
76 //usage:       "$ modprobe tulip2\n"
77 //usage:       "   will load the module 'tulip' with default options 'irq=4 io=0x308',\n"
78 //usage:       "   which are the default for alias 'tulip2'\n\n"
79 //usage:       "$ modprobe tulip2 irq=8\n"
80 //usage:       "   will load the module 'tulip' with default options 'irq=4 io=0x308 irq=8',\n"
81 //usage:       "   which are the default for alias 'tulip2' overridden by the option 'irq=8'\n\n"
82 //usage:       "   from the command line\n\n"
83 //usage:       "$ modprobe tulip2 irq=2 io=0x210\n"
84 //usage:       "   will load the module 'tulip' with default options 'irq=4 io=0x308 irq=4 io=0x210',\n"
85 //usage:       "   which are the default for alias 'tulip2' overridden by the options 'irq=2 io=0x210'\n\n"
86 //usage:       "   from the command line\n"
87 //usage:
88 //usage:#define modprobe_trivial_usage
89 //usage:        "[-alrqvsD" IF_FEATURE_MODPROBE_BLACKLIST("b") "]"
90 //usage:        " MODULE [symbol=value]..."
91 //usage:#define modprobe_full_usage "\n\n"
92 //usage:       "Options:"
93 //usage:     "\n        -a      Load multiple MODULEs"
94 //usage:     "\n        -l      List (MODULE is a pattern)"
95 //usage:     "\n        -r      Remove MODULE (stacks) or do autoclean"
96 //usage:     "\n        -q      Quiet"
97 //usage:     "\n        -v      Verbose"
98 //usage:     "\n        -s      Log to syslog"
99 //usage:     "\n        -D      Show dependencies"
100 //usage:        IF_FEATURE_MODPROBE_BLACKLIST(
101 //usage:     "\n        -b      Apply blacklist to module names too"
102 //usage:        )
103 //usage:#endif /* !ENABLE_MODPROBE_SMALL */
104
105 /* Note that usage text doesn't document various 2.4 options
106  * we pull in through INSMOD_OPTS define */
107 #define MODPROBE_OPTS  "alrD" IF_FEATURE_MODPROBE_BLACKLIST("b")
108 /* -a and -D _are_ in fact compatible */
109 #define MODPROBE_COMPLEMENTARY ("q-v:v-q:l--arD:r--alD:a--lr:D--rl")
110 //#define MODPROBE_OPTS  "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b")
111 //#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al"
112 enum {
113         OPT_INSERT_ALL   = (INSMOD_OPT_UNUSED << 0), /* a */
114         //OPT_DUMP_ONLY  = (INSMOD_OPT_UNUSED << x), /* c */
115         //OPT_DIRNAME    = (INSMOD_OPT_UNUSED << x), /* d */
116         OPT_LIST_ONLY    = (INSMOD_OPT_UNUSED << 1), /* l */
117         //OPT_SHOW_ONLY  = (INSMOD_OPT_UNUSED << x), /* n */
118         OPT_REMOVE       = (INSMOD_OPT_UNUSED << 2), /* r */
119         //OPT_RESTRICT   = (INSMOD_OPT_UNUSED << x), /* t */
120         //OPT_VERONLY    = (INSMOD_OPT_UNUSED << x), /* V */
121         //OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << x), /* C */
122         OPT_SHOW_DEPS    = (INSMOD_OPT_UNUSED << 3), /* D */
123         OPT_BLACKLIST    = (INSMOD_OPT_UNUSED << 4) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
124 };
125 #if ENABLE_LONG_OPTS
126 static const char modprobe_longopts[] ALIGN1 =
127         /* nobody asked for long opts (yet) */
128         // "all\0"          No_argument "a"
129         // "list\0"         No_argument "l"
130         // "remove\0"       No_argument "r"
131         // "quiet\0"        No_argument "q"
132         // "verbose\0"      No_argument "v"
133         // "syslog\0"       No_argument "s"
134         /* module-init-tools 3.11.1 has only long opt --show-depends
135          * but no short -D, we provide long opt for scripts which
136          * were written for 3.11.1: */
137         "show-depends\0" No_argument "D"
138         // IF_FEATURE_MODPROBE_BLACKLIST(
139         // "use-blacklist\0" No_argument "b"
140         // )
141         ;
142 #endif
143
144 #define MODULE_FLAG_LOADED              0x0001
145 #define MODULE_FLAG_NEED_DEPS           0x0002
146 /* "was seen in modules.dep": */
147 #define MODULE_FLAG_FOUND_IN_MODDEP     0x0004
148 #define MODULE_FLAG_BLACKLISTED         0x0008
149
150 struct module_entry { /* I'll call it ME. */
151         unsigned flags;
152         char *modname; /* stripped of /path/, .ext and s/-/_/g */
153         const char *probed_name; /* verbatim as seen on cmdline */
154         char *options; /* options from config files */
155         llist_t *realnames; /* strings. if this module is an alias, */
156         /* real module name is one of these. */
157 //Can there really be more than one? Example from real kernel?
158         llist_t *deps; /* strings. modules we depend on */
159 };
160
161 struct globals {
162         llist_t *db; /* MEs of all modules ever seen (caching for speed) */
163         llist_t *probes; /* MEs of module(s) requested on cmdline */
164         char *cmdline_mopts; /* module options from cmdline */
165         int num_unresolved_deps;
166         /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */
167         smallint need_symbols;
168         struct utsname uts;
169 } FIX_ALIASING;
170 #define G (*(struct globals*)&bb_common_bufsiz1)
171 #define INIT_G() do { } while (0)
172 struct BUG_G_too_big {
173         char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
174 };
175
176
177 static int read_config(const char *path);
178
179 static char *gather_options_str(char *opts, const char *append)
180 {
181         /* Speed-optimized. We call gather_options_str many times. */
182         if (append) {
183                 if (opts == NULL) {
184                         opts = xstrdup(append);
185                 } else {
186                         int optlen = strlen(opts);
187                         opts = xrealloc(opts, optlen + strlen(append) + 2);
188                         sprintf(opts + optlen, " %s", append);
189                 }
190         }
191         return opts;
192 }
193
194 static struct module_entry *helper_get_module(const char *module, int create)
195 {
196         char modname[MODULE_NAME_LEN];
197         struct module_entry *e;
198         llist_t *l;
199
200         filename2modname(module, modname);
201         for (l = G.db; l != NULL; l = l->link) {
202                 e = (struct module_entry *) l->data;
203                 if (strcmp(e->modname, modname) == 0)
204                         return e;
205         }
206         if (!create)
207                 return NULL;
208
209         e = xzalloc(sizeof(*e));
210         e->modname = xstrdup(modname);
211         llist_add_to(&G.db, e);
212
213         return e;
214 }
215 static struct module_entry *get_or_add_modentry(const char *module)
216 {
217         return helper_get_module(module, 1);
218 }
219 static struct module_entry *get_modentry(const char *module)
220 {
221         return helper_get_module(module, 0);
222 }
223
224 static void add_probe(const char *name)
225 {
226         struct module_entry *m;
227
228         m = get_or_add_modentry(name);
229         if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
230          && (m->flags & MODULE_FLAG_LOADED)
231         ) {
232                 DBG("skipping %s, it is already loaded", name);
233                 return;
234         }
235
236         DBG("queuing %s", name);
237         m->probed_name = name;
238         m->flags |= MODULE_FLAG_NEED_DEPS;
239         llist_add_to_end(&G.probes, m);
240         G.num_unresolved_deps++;
241         if (ENABLE_FEATURE_MODUTILS_SYMBOLS
242          && strncmp(m->modname, "symbol:", 7) == 0
243         ) {
244                 G.need_symbols = 1;
245         }
246 }
247
248 static int FAST_FUNC config_file_action(const char *filename,
249                                         struct stat *statbuf UNUSED_PARAM,
250                                         void *userdata UNUSED_PARAM,
251                                         int depth UNUSED_PARAM)
252 {
253         char *tokens[3];
254         parser_t *p;
255         struct module_entry *m;
256         int rc = TRUE;
257
258         if (bb_basename(filename)[0] == '.')
259                 goto error;
260
261         p = config_open2(filename, fopen_for_read);
262         if (p == NULL) {
263                 rc = FALSE;
264                 goto error;
265         }
266
267         while (config_read(p, tokens, 3, 2, "# \t", PARSE_NORMAL)) {
268 //Use index_in_strings?
269                 if (strcmp(tokens[0], "alias") == 0) {
270                         /* alias <wildcard> <modulename> */
271                         llist_t *l;
272                         char wildcard[MODULE_NAME_LEN];
273                         char *rmod;
274
275                         if (tokens[2] == NULL)
276                                 continue;
277                         filename2modname(tokens[1], wildcard);
278
279                         for (l = G.probes; l != NULL; l = l->link) {
280                                 m = (struct module_entry *) l->data;
281                                 if (fnmatch(wildcard, m->modname, 0) != 0)
282                                         continue;
283                                 rmod = filename2modname(tokens[2], NULL);
284                                 llist_add_to(&m->realnames, rmod);
285
286                                 if (m->flags & MODULE_FLAG_NEED_DEPS) {
287                                         m->flags &= ~MODULE_FLAG_NEED_DEPS;
288                                         G.num_unresolved_deps--;
289                                 }
290
291                                 m = get_or_add_modentry(rmod);
292                                 if (!(m->flags & MODULE_FLAG_NEED_DEPS)) {
293                                         m->flags |= MODULE_FLAG_NEED_DEPS;
294                                         G.num_unresolved_deps++;
295                                 }
296                         }
297                 } else if (strcmp(tokens[0], "options") == 0) {
298                         /* options <modulename> <option...> */
299                         if (tokens[2] == NULL)
300                                 continue;
301                         m = get_or_add_modentry(tokens[1]);
302                         m->options = gather_options_str(m->options, tokens[2]);
303                 } else if (strcmp(tokens[0], "include") == 0) {
304                         /* include <filename> */
305                         read_config(tokens[1]);
306                 } else if (ENABLE_FEATURE_MODPROBE_BLACKLIST
307                  && strcmp(tokens[0], "blacklist") == 0
308                 ) {
309                         /* blacklist <modulename> */
310                         get_or_add_modentry(tokens[1])->flags |= MODULE_FLAG_BLACKLISTED;
311                 }
312         }
313         config_close(p);
314  error:
315         return rc;
316 }
317
318 static int read_config(const char *path)
319 {
320         return recursive_action(path, ACTION_RECURSE | ACTION_QUIET,
321                                 config_file_action, NULL, NULL, 1);
322 }
323
324 static const char *humanly_readable_name(struct module_entry *m)
325 {
326         /* probed_name may be NULL. modname always exists. */
327         return m->probed_name ? m->probed_name : m->modname;
328 }
329
330 static char *parse_and_add_kcmdline_module_options(char *options, const char *modulename)
331 {
332         char *kcmdline_buf;
333         char *kcmdline;
334         char *kptr;
335         int len;
336
337         kcmdline_buf = xmalloc_open_read_close("/proc/cmdline", NULL);
338         if (!kcmdline_buf)
339                 return options;
340
341         kcmdline = kcmdline_buf;
342         len = strlen(modulename);
343         while ((kptr = strsep(&kcmdline, "\n\t ")) != NULL) {
344                 if (strncmp(modulename, kptr, len) != 0)
345                         continue;
346                 kptr += len;
347                 if (*kptr != '.')
348                         continue;
349                 /* It is "modulename.xxxx" */
350                 kptr++;
351                 if (strchr(kptr, '=') != NULL) {
352                         /* It is "modulename.opt=[val]" */
353                         options = gather_options_str(options, kptr);
354                 }
355         }
356         free(kcmdline_buf);
357
358         return options;
359 }
360
361 /* Return: similar to bb_init_module:
362  * 0 on success,
363  * -errno on open/read error,
364  * errno on init_module() error
365  */
366 /* NB: INSMOD_OPT_SILENT bit suppresses ONLY non-existent modules,
367  * not deleted ones (those are still listed in modules.dep).
368  * module-init-tools version 3.4:
369  * # modprobe bogus
370  * FATAL: Module bogus not found. [exitcode 1]
371  * # modprobe -q bogus            [silent, exitcode still 1]
372  * but:
373  * # rm kernel/drivers/net/dummy.ko
374  * # modprobe -q dummy
375  * FATAL: Could not open '/lib/modules/xxx/kernel/drivers/net/dummy.ko': No such file or directory
376  * [exitcode 1]
377  */
378 static int do_modprobe(struct module_entry *m)
379 {
380         int rc, first;
381         llist_t *l;
382
383         if (!(m->flags & MODULE_FLAG_FOUND_IN_MODDEP)) {
384                 if (!(option_mask32 & INSMOD_OPT_SILENT))
385                         bb_error_msg("module %s not found in modules.dep",
386                                 humanly_readable_name(m));
387                 return -ENOENT;
388         }
389         DBG("do_modprob'ing %s", m->modname);
390
391         if (!(option_mask32 & OPT_REMOVE))
392                 m->deps = llist_rev(m->deps);
393
394         for (l = m->deps; l != NULL; l = l->link)
395                 DBG("dep: %s", l->data);
396
397         first = 1;
398         rc = 0;
399         while (m->deps) {
400                 struct module_entry *m2;
401                 char *fn, *options;
402
403                 rc = 0;
404                 fn = llist_pop(&m->deps); /* we leak it */
405                 m2 = get_or_add_modentry(fn);
406
407                 if (option_mask32 & OPT_REMOVE) {
408                         /* modprobe -r */
409                         if (m2->flags & MODULE_FLAG_LOADED) {
410                                 rc = bb_delete_module(m2->modname, O_EXCL);
411                                 if (rc) {
412                                         if (first) {
413                                                 bb_error_msg("can't unload module %s: %s",
414                                                         humanly_readable_name(m2),
415                                                         moderror(rc));
416                                                 break;
417                                         }
418                                 } else {
419                                         m2->flags &= ~MODULE_FLAG_LOADED;
420                                 }
421                         }
422                         /* do not error out if *deps* fail to unload */
423                         first = 0;
424                         continue;
425                 }
426
427                 options = m2->options;
428                 m2->options = NULL;
429                 options = parse_and_add_kcmdline_module_options(options, m2->modname);
430                 if (m == m2)
431                         options = gather_options_str(options, G.cmdline_mopts);
432
433                 if (option_mask32 & OPT_SHOW_DEPS) {
434                         printf(options ? "insmod %s/%s/%s %s\n"
435                                         : "insmod %s/%s/%s\n",
436                                 CONFIG_DEFAULT_MODULES_DIR, G.uts.release, fn,
437                                 options);
438                         free(options);
439                         continue;
440                 }
441
442                 if (m2->flags & MODULE_FLAG_LOADED) {
443                         DBG("%s is already loaded, skipping", fn);
444                         free(options);
445                         continue;
446                 }
447
448                 rc = bb_init_module(fn, options);
449                 DBG("loaded %s '%s', rc:%d", fn, options, rc);
450                 if (rc == EEXIST)
451                         rc = 0;
452                 free(options);
453                 if (rc) {
454                         bb_error_msg("can't load module %s (%s): %s",
455                                 humanly_readable_name(m2),
456                                 fn,
457                                 moderror(rc)
458                         );
459                         break;
460                 }
461                 m2->flags |= MODULE_FLAG_LOADED;
462         }
463
464         return rc;
465 }
466
467 static void load_modules_dep(void)
468 {
469         struct module_entry *m;
470         char *colon, *tokens[2];
471         parser_t *p;
472
473         /* Modprobe does not work at all without modules.dep,
474          * even if the full module name is given. Returning error here
475          * was making us later confuse user with this message:
476          * "module /full/path/to/existing/file/module.ko not found".
477          * It's better to die immediately, with good message.
478          * xfopen_for_read provides that. */
479         p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
480
481         while (G.num_unresolved_deps
482          && config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)
483         ) {
484                 colon = last_char_is(tokens[0], ':');
485                 if (colon == NULL)
486                         continue;
487                 *colon = 0;
488
489                 m = get_modentry(tokens[0]);
490                 if (m == NULL)
491                         continue;
492
493                 /* Optimization... */
494                 if ((m->flags & MODULE_FLAG_LOADED)
495                  && !(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
496                 ) {
497                         DBG("skip deps of %s, it's already loaded", tokens[0]);
498                         continue;
499                 }
500
501                 m->flags |= MODULE_FLAG_FOUND_IN_MODDEP;
502                 if ((m->flags & MODULE_FLAG_NEED_DEPS) && (m->deps == NULL)) {
503                         G.num_unresolved_deps--;
504                         llist_add_to(&m->deps, xstrdup(tokens[0]));
505                         if (tokens[1])
506                                 string_to_llist(tokens[1], &m->deps, " \t");
507                 } else
508                         DBG("skipping dep line");
509         }
510         config_close(p);
511 }
512
513 int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
514 int modprobe_main(int argc UNUSED_PARAM, char **argv)
515 {
516         int rc;
517         unsigned opt;
518         struct module_entry *me;
519
520         INIT_G();
521
522         IF_LONG_OPTS(applet_long_options = modprobe_longopts;)
523         opt_complementary = MODPROBE_COMPLEMENTARY;
524         opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS);
525         argv += optind;
526
527         /* Goto modules location */
528         xchdir(CONFIG_DEFAULT_MODULES_DIR);
529         uname(&G.uts);
530         xchdir(G.uts.release);
531
532         if (opt & OPT_LIST_ONLY) {
533                 char name[MODULE_NAME_LEN];
534                 char *colon, *tokens[2];
535                 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
536
537                 while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
538                         colon = last_char_is(tokens[0], ':');
539                         if (!colon)
540                                 continue;
541                         *colon = '\0';
542                         filename2modname(tokens[0], name);
543                         if (!argv[0])
544                                 puts(tokens[0]);
545                         else {
546                                 int i;
547                                 for (i = 0; argv[i]; i++) {
548                                         if (fnmatch(argv[i], name, 0) == 0) {
549                                                 puts(tokens[0]);
550                                         }
551                                 }
552                         }
553                 }
554                 return EXIT_SUCCESS;
555         }
556
557         /* Yes, for some reason -l ignores -s... */
558         if (opt & INSMOD_OPT_SYSLOG)
559                 logmode = LOGMODE_SYSLOG;
560
561         if (!argv[0]) {
562                 if (opt & OPT_REMOVE) {
563                         /* "modprobe -r" (w/o params).
564                          * "If name is NULL, all unused modules marked
565                          * autoclean will be removed".
566                          */
567                         if (bb_delete_module(NULL, O_NONBLOCK | O_EXCL) != 0)
568                                 bb_perror_msg_and_die("rmmod");
569                 }
570                 return EXIT_SUCCESS;
571         }
572
573         /* Retrieve module names of already loaded modules */
574         {
575                 char *s;
576                 parser_t *parser = config_open2("/proc/modules", fopen_for_read);
577                 while (config_read(parser, &s, 1, 1, "# \t", PARSE_NORMAL & ~PARSE_GREEDY))
578                         get_or_add_modentry(s)->flags |= MODULE_FLAG_LOADED;
579                 config_close(parser);
580         }
581
582         if (opt & (OPT_INSERT_ALL | OPT_REMOVE)) {
583                 /* Each argument is a module name */
584                 do {
585                         DBG("adding module %s", *argv);
586                         add_probe(*argv++);
587                 } while (*argv);
588         } else {
589                 /* First argument is module name, rest are parameters */
590                 DBG("probing just module %s", *argv);
591                 add_probe(argv[0]);
592                 G.cmdline_mopts = parse_cmdline_module_options(argv, /*quote_spaces:*/ 1);
593         }
594
595         /* Happens if all requested modules are already loaded */
596         if (G.probes == NULL)
597                 return EXIT_SUCCESS;
598
599         read_config("/etc/modprobe.conf");
600         read_config("/etc/modprobe.d");
601         if (ENABLE_FEATURE_MODUTILS_SYMBOLS && G.need_symbols)
602                 read_config("modules.symbols");
603         load_modules_dep();
604         if (ENABLE_FEATURE_MODUTILS_ALIAS && G.num_unresolved_deps) {
605                 read_config("modules.alias");
606                 load_modules_dep();
607         }
608
609         rc = 0;
610         while ((me = llist_pop(&G.probes)) != NULL) {
611                 if (me->realnames == NULL) {
612                         DBG("probing by module name");
613                         /* This is not an alias. Literal names are blacklisted
614                          * only if '-b' is given.
615                          */
616                         if (!(opt & OPT_BLACKLIST)
617                          || !(me->flags & MODULE_FLAG_BLACKLISTED)
618                         ) {
619                                 rc |= do_modprobe(me);
620                         }
621                         continue;
622                 }
623
624                 /* Probe all real names for the alias */
625                 do {
626                         char *realname = llist_pop(&me->realnames);
627                         struct module_entry *m2;
628
629                         DBG("probing alias %s by realname %s", me->modname, realname);
630                         m2 = get_or_add_modentry(realname);
631                         if (!(m2->flags & MODULE_FLAG_BLACKLISTED)
632                          && (!(m2->flags & MODULE_FLAG_LOADED)
633                             || (opt & (OPT_REMOVE | OPT_SHOW_DEPS)))
634                         ) {
635 //TODO: we can pass "me" as 2nd param to do_modprobe,
636 //and make do_modprobe emit more meaningful error messages
637 //with alias name included, not just module name alias resolves to.
638                                 rc |= do_modprobe(m2);
639                         }
640                         free(realname);
641                 } while (me->realnames != NULL);
642         }
643
644         return (rc != 0);
645 }