]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modprobe: fix error path in removing modules
authorDave Reisner <dreisner@archlinux.org>
Thu, 15 Mar 2012 02:15:21 +0000 (22:15 -0400)
committerDave Reisner <dreisner@archlinux.org>
Thu, 15 Mar 2012 02:26:30 +0000 (22:26 -0400)
We really haven't paid this code much attention, and it's somewhat
evident in our divergence in behavior from module-init-tools. This patch
asserts the following behavior on exit:

* modprobe -r realmod_notloaded => exit zero
* modprobe -r --first-time realmod_notloaded => exit non-zero
* modprobe -r bogusmod => exit non-zero

tools/kmod-modprobe.c

index 55f379565e7058cd80c3304fff3673143503ab4c..996a91963e0ecfc1338ceda4879dad0a92395fb5 100644 (file)
@@ -412,22 +412,17 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies)
                int state = kmod_module_get_initstate(mod);
 
                if (state < 0) {
-                       LOG ("Module %s not found.\n", modname);
-                       err = -ENOENT;
-                       goto error;
-               } else if (state == KMOD_MODULE_BUILTIN) {
-                       LOG("Module %s is builtin.\n", modname);
-                       err = -ENOENT;
-                       goto error;
-               } else if (state != KMOD_MODULE_LIVE) {
                        if (first_time) {
                                LOG("Module %s is not in kernel.\n", modname);
                                err = -ENOENT;
-                               goto error;
                        } else {
                                err = 0;
-                               goto error;
                        }
+                       goto error;
+               } else if (state == KMOD_MODULE_BUILTIN) {
+                       LOG("Module %s is builtin.\n", modname);
+                       err = -ENOENT;
+                       goto error;
                }
        }
 
@@ -479,8 +474,10 @@ static int rmmod(struct kmod_ctx *ctx, const char *alias)
        if (err < 0)
                return err;
 
-       if (list == NULL)
+       if (list == NULL) {
                LOG("Module %s not found.\n", alias);
+               err = -ENOENT;
+       }
 
        kmod_list_foreach(l, list) {
                struct kmod_module *mod = kmod_module_get_module(l);