The most obvious problem was 'module not found' returning status 0 Add fixes for some existing cornercases modprobe -r an existing module or alias not loaded should return 0 modprobe alias already loaded should return 0
All that has been tested mainly with dummy.ko.gz module and rtnl-link-dummy alias Fix an old comment s/modprobe.dep/modules.dep/ modprobe actually does not support -k autoclean (should we really?) Could not modprobe -r (without parameter) specific code be removed? Actually, it just give modprobe:rmmod: Bad address (even with rmmod applet enabled) function old new delta modprobe_main 463 533 +70 do_modprobe 266 277 +11 add_probe 81 80 -1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 81/-1) Total: 80 bytes text data bss dec hex filename 221388 1585 8752 231725 3892d busybox_old 221468 1585 8752 231805 3897d busybox_unstripped Signed-off-by: Gilles Espinasse <[email protected]> --- modutils/modprobe.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-) diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 0339ebb..41b63da 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -52,8 +52,9 @@ struct globals { llist_t *probes; /* MEs of module(s) requested on cmdline */ char *cmdline_mopts; /* module options from cmdline */ int num_unresolved_deps; - /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */ - smallint need_symbols; + /* 1 "Did we have 'symbol:FOO' requested on cmdline?" + * 2 modprobe status */ + smallint modprobe_flags; }; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { } while (0) @@ -123,7 +124,7 @@ static void add_probe(const char *name) if (ENABLE_FEATURE_MODUTILS_SYMBOLS && strncmp(m->modname, "symbol:", 7) == 0 ) { - G.need_symbols = 1; + G.modprobe_flags |= 1; } } @@ -203,6 +204,7 @@ static int read_config(const char *path) config_file_action, NULL, NULL, 1); } +/* Return a value >=0 or -ENOENT if module not found in modules.dep */ static int do_modprobe(struct module_entry *m) { struct module_entry *m2; @@ -224,7 +226,9 @@ static int do_modprobe(struct module_entry *m) m2 = get_or_add_modentry(fn); if (option_mask32 & MODPROBE_OPT_REMOVE) { if (bb_delete_module(m->modname, O_EXCL) != 0) - rc = errno; + /* silence with module already unloaded */ + if (errno != ENOENT) + rc = errno; } else if (!(m2->flags & MODULE_FLAG_LOADED)) { options = m2->options; m2->options = NULL; @@ -242,7 +246,8 @@ static int do_modprobe(struct module_entry *m) free(fn); } -//FIXME: what if rc < 0? + /* On 2.6 kernel, rc is alway >=0 (0 or errno). + * On 2.4 kernel, that's EXIT_SUCCESS or EXIT_ERROR */ if (rc > 0 && !(option_mask32 & INSMOD_OPT_SILENT)) { bb_error_msg("failed to %sload module %s: %s", (option_mask32 & MODPROBE_OPT_REMOVE) ? "un" : "", @@ -260,7 +265,7 @@ static void load_modules_dep(void) char *colon, *tokens[2]; parser_t *p; - /* Modprobe does not work at all without modprobe.dep, + /* Modprobe does not work at all without modules.dep, * even if the full module name is given. Returning error here * was making us later confuse user with this message: * "module /full/path/to/existing/file/module.ko not found". @@ -358,7 +363,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) read_config("/etc/modprobe.conf"); read_config("/etc/modprobe.d"); - if (ENABLE_FEATURE_MODUTILS_SYMBOLS && G.need_symbols) + if (ENABLE_FEATURE_MODUTILS_SYMBOLS && G.modprobe_flags & 1) read_config("modules.symbols"); load_modules_dep(); if (ENABLE_FEATURE_MODUTILS_ALIAS && G.num_unresolved_deps) { @@ -375,10 +380,12 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) || !(me->flags & MODULE_FLAG_BLACKLISTED) ) { rc = do_modprobe(me); -//FIXME: what if rc > 0? + /* if rc > 0, do_modprobe already warn */ if (rc < 0 && !(opt & INSMOD_OPT_SILENT)) bb_error_msg("module %s not found", me->probed_name); + if (rc != 0) + G.modprobe_flags |= 2; } } else { /* Probe all realnames */ @@ -388,13 +395,17 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) DBG("probing %s by realname %s", me->modname, realname); m2 = get_or_add_modentry(realname); - if (!(m2->flags & MODULE_FLAG_BLACKLISTED)) - do_modprobe(m2); -//FIXME: error check? + if (!(m2->flags & MODULE_FLAG_BLACKLISTED) + && (!(m2->flags & MODULE_FLAG_LOADED) + || opt & MODPROBE_OPT_REMOVE ) + ) { + if (do_modprobe(m2)) + G.modprobe_flags |= 2; + } free(realname); } while (me->realnames != NULL); } } - return EXIT_SUCCESS; + return (G.modprobe_flags & 2) == 2; } -- 1.6.0.6 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
