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