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