rmmod: fix bad error message
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 24 Oct 2015 02:17:04 +0000 (04:17 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 24 Oct 2015 02:17:04 +0000 (04:17 +0200)
    Before:

    ># busybox_old rmmod gtrhfhdfghdf
    rmmod: can't unload 'gtrhfhdfghdf': unknown symbol in module, or unknown parameter

    After:

    ># busybox rmmod gtrhfhdfghdf
    rmmod: can't unload module 'gtrhfhdfghdf': No such file or directory

function                                             old     new   delta
modprobe_main                                        726     721      -5
do_modprobe                                          599     590      -9
rmmod_main                                           187     169     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-32)             Total: -32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
modutils/modprobe.c
modutils/modutils.c
modutils/rmmod.c

index 314a7a1cbea8acf2978fef0c5b59929682bbbfb3..952ba03772959f36dc8d21863064800bcf4a88bb 100644 (file)
@@ -461,9 +461,8 @@ static int do_modprobe(struct module_entry *m)
                                rc = bb_delete_module(m2->modname, O_EXCL);
                                if (rc) {
                                        if (first) {
-                                               bb_error_msg("can't unload module %s: %s",
-                                                       humanly_readable_name(m2),
-                                                       moderror(rc));
+                                               bb_perror_msg("can't unload module %s",
+                                                       humanly_readable_name(m2));
                                                break;
                                        }
                                } else {
@@ -622,7 +621,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
                         * autoclean will be removed".
                         */
                        if (bb_delete_module(NULL, O_NONBLOCK | O_EXCL) != 0)
-                               bb_perror_msg_and_die("rmmod");
+                               bb_perror_nomsg_and_die();
                }
                return EXIT_SUCCESS;
        }
index 84300d93158aae58b4ed24903e323d223b687629..ef4134af5e129abf0e55cee0ee2f6cef875c6476 100644 (file)
@@ -190,6 +190,11 @@ int FAST_FUNC bb_delete_module(const char *module, unsigned int flags)
        return errno;
 }
 
+/* Note: not suitable for delete_module() errnos.
+ * For them, probably only EWOULDBLOCK needs explaining:
+ * "Other modules depend on us". So far we don't do such
+ * translation and don't use moderror() for removal errors.
+ */
 const char* FAST_FUNC moderror(int err)
 {
        switch (err) {
index f13ff9eb6552c776ff4071f71d584a5750dd58c6..5c353ef95f00df3ae7ea4c25f28b12eef6d48acf 100644 (file)
@@ -28,7 +28,7 @@
 int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int rmmod_main(int argc UNUSED_PARAM, char **argv)
 {
-       int n;
+       int n, err;
        unsigned flags = O_NONBLOCK | O_EXCL;
 
        /* Parse command line. */
@@ -40,7 +40,8 @@ int rmmod_main(int argc UNUSED_PARAM, char **argv)
                flags |= O_TRUNC;
        if (n & 4) {
                /* Unload _all_ unused modules via NULL delete_module() call */
-               if (bb_delete_module(NULL, flags) != 0 && errno != EFAULT)
+               err = bb_delete_module(NULL, flags);
+               if (err && err != EFAULT)
                        bb_perror_msg_and_die("rmmod");
                return EXIT_SUCCESS;
        }
@@ -58,9 +59,10 @@ int rmmod_main(int argc UNUSED_PARAM, char **argv)
                        safe_strncpy(modname, bname, MODULE_NAME_LEN);
                else
                        filename2modname(bname, modname);
-               if (bb_delete_module(modname, flags))
-                       bb_error_msg_and_die("can't unload '%s': %s",
-                                       modname, moderror(errno));
+               err = bb_delete_module(modname, flags);
+               if (err)
+                       bb_perror_msg_and_die("can't unload module '%s'",
+                                       modname);
        }
 
        return EXIT_SUCCESS;