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