modprobe.c 18 KB

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