Report modprobe status and not mostly report only EXITSUCCESS

v3
 Remove the global variable as any errror is reported from modprobe_maint
 Add a DBG message when probing module by file name
 Add an error message in case of alias error

This fix the following cases by reporting an error in status :
- when a module is not found
- unloading a module used by another module (like hid used by usbhid)
- when a module is not present in modules.dep (outdated .dep file)
- in case of alias error (try with echo "alias foo bar" >> 
modules.alias;modprobe foo

All that has been tested mainly with dummy.ko.gz module and rtnl-link-dummy 
alias
Not tested with blacklist.

Fix an old comment s/modprobe.dep/modules.dep/

Replace space with tab before 'struct module_entry *m;'

function                                             old     new   delta
modprobe_main                                        484     558     +74
.rodata                                            27199   27221     +22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 96/0)               Total: 96 bytes
   text    data     bss     dec     hex filename
 221622    1585    8752  231959   38a17 busybox_old
 221718    1585    8752  232055   38a77 busybox_unstripped

Signed-off-by: Gilles Espinasse <[email protected]>
---
 modutils/modprobe.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index d000c91..abd422f 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -140,7 +140,7 @@ static int FAST_FUNC config_file_action(const char 
*filename,
 {
        char *tokens[3];
        parser_t *p;
-        struct module_entry *m;
+       struct module_entry *m;
        int rc = TRUE;
 
        if (bb_basename(filename)[0] == '.')
@@ -209,6 +209,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 = m2; /* for compiler */
@@ -261,6 +262,8 @@ static int do_modprobe(struct module_entry *m)
                free(fn);
        }
 
+       /* On 2.6 kernel, rc is alway >=0 (0 or errno).
+        * On 2.4 kernel, that's EXIT_SUCCESS or EXIT_ERROR */
        if (rc && !(option_mask32 & INSMOD_OPT_SILENT)) {
                bb_error_msg("failed to %sload module %s: %s",
                        (option_mask32 & MODPROBE_OPT_REMOVE) ? "un" : "",
@@ -278,7 +281,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".
@@ -322,7 +325,7 @@ int modprobe_main(int argc, char **argv) 
MAIN_EXTERNALLY_VISIBLE;
 int modprobe_main(int argc UNUSED_PARAM, char **argv)
 {
        struct utsname uts;
-       int rc;
+       int rc = 0;
        unsigned opt;
        struct module_entry *me;
 
@@ -389,6 +392,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
 
        while ((me = llist_pop(&G.probes)) != NULL) {
                if (me->realnames == NULL) {
+                       DBG("probing by module name");
                        /* This is not an alias. Literal names are blacklisted
                         * only if '-b' is given.
                         */
@@ -396,7 +400,7 @@ 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);
@@ -409,13 +413,19 @@ 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 )
+                               ) {
+                                       rc=do_modprobe(m2);
+                                       if (rc < 0 && !(opt & 
INSMOD_OPT_SILENT))
+                                               bb_error_msg("module %s alias 
error",
+                                                            me->modname);
+                               }
                                free(realname);
                        } while (me->realnames != NULL);
                }
        }
 
-       return EXIT_SUCCESS;
+       return (rc != 0);
 }
-- 
1.6.0.6

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to