Do not report always EXITSUCCESS even with 'module not found'
Fix an old comment s/modprobe.dep/modules.dep

function                                             old     new   delta
modprobe_main                                        463     484     +21
count_error                                            -      12     +12
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 33/0)               Total: 33 bytes
   text    data     bss     dec     hex filename
 221162    1585    8752  231499   3884b busybox_old
 221195    1585    8752  231532   3886c busybox_unstripped

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

diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 0339ebb..12f1f99 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -54,6 +54,7 @@ struct globals {
        int num_unresolved_deps;
        /* bool. "Did we have 'symbol:FOO' requested on cmdline?" */
        smallint need_symbols;
+       smallint modprobe_status; /* to return the proper exit status */
 };
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define INIT_G() do { } while (0)
@@ -203,6 +204,14 @@ static int read_config(const char *path)
                                config_file_action, NULL, NULL, 1);
 }
 
+/* Hold modprobe status */
+static void count_error(int rc)
+{
+       if (rc != 0)
+               G.modprobe_status = 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;
@@ -242,7 +251,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 +270,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".
@@ -375,7 +385,8 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
                         || !(me->flags & MODULE_FLAG_BLACKLISTED)
                        ) {
                                rc = do_modprobe(me);
-//FIXME: what if rc > 0?
+                               count_error(rc);
+                               /* if rc > 0, do_modprobe already warn */
                                if (rc < 0 && !(opt & INSMOD_OPT_SILENT))
                                        bb_error_msg("module %s not found",
                                                     me->probed_name);
@@ -389,12 +400,12 @@ 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?
+                                       count_error(do_modprobe(m2));
+
                                free(realname);
                        } while (me->realnames != NULL);
                }
        }
 
-       return EXIT_SUCCESS;
+       return G.modprobe_status;
 }
-- 
1.6.0.6

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

Reply via email to