]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
kmod_modprobe: fix handling of remove commands
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 19 Dec 2011 04:18:14 +0000 (02:18 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 19 Dec 2011 11:35:43 +0000 (09:35 -0200)
The check for remove/install commands must be before the ignore_loaded
check because we will actually run something instead of
removing/inserting a module and the modname might not correspond to a
real module. Otherwise a fake module like "remove removeme echo 'bla'"
would not work.

This also keeps compatibility with modprobe.

tools/kmod-modprobe.c

index 2ea8d08317ac07bc53ef58194b5f9fbbc83528eb..c14baa5c9ece8f3f00bde0963e2d041c27dca70f 100644 (file)
@@ -417,27 +417,6 @@ static int rmmod_do(struct kmod_module *mod)
        struct kmod_list *pre = NULL, *post = NULL;
        int err;
 
-       if (!ignore_loaded) {
-               int state = kmod_module_get_initstate(mod);
-               if (state == KMOD_MODULE_BUILTIN) {
-                       LOG("Module %s is builtin.\n", modname);
-                       return -ENOENT;
-               } else if (state != KMOD_MODULE_LIVE) {
-                       if (first_time) {
-                               LOG("Module %s is not in kernel.\n", modname);
-                               return -ENOENT;
-                       } else
-                               return 0;
-               }
-       }
-
-       /* not in original modprobe -r, but helpful */
-       if (remove_dependencies) {
-               err = rmmod_do_dependencies(mod);
-               if (err < 0)
-                       return err;
-       }
-
        if (!ignore_commands) {
                const char *cmd;
 
@@ -462,6 +441,28 @@ static int rmmod_do(struct kmod_module *mod)
                }
        }
 
+       if (!ignore_loaded) {
+               int state = kmod_module_get_initstate(mod);
+
+               if (state == KMOD_MODULE_BUILTIN) {
+                       LOG("Module %s is builtin.\n", modname);
+                       return -ENOENT;
+               } else if (state != KMOD_MODULE_LIVE) {
+                       if (first_time) {
+                               LOG("Module %s is not in kernel.\n", modname);
+                               return -ENOENT;
+                       } else
+                               return 0;
+               }
+       }
+
+       /* not in original modprobe -r, but helpful */
+       if (remove_dependencies) {
+               err = rmmod_do_dependencies(mod);
+               if (err < 0)
+                       return err;
+       }
+
        if (!ignore_loaded) {
                int usage = kmod_module_get_refcnt(mod);
                if (usage > 0) {
@@ -698,29 +699,6 @@ static int insmod_do(struct kmod_module *mod, const char *extra_opts)
        char *opts = NULL;
        int err;
 
-       if (!ignore_loaded) {
-               int state = kmod_module_get_initstate(mod);
-
-               if (state == KMOD_MODULE_BUILTIN) {
-                       if (first_time) {
-                               LOG("Module %s already in kernel (builtin).\n",
-                                   modname);
-                               return -EEXIST;
-                       }
-                       return 0;
-               } else if (state == KMOD_MODULE_LIVE) {
-                       if (first_time) {
-                               LOG("Module %s already in kernel.\n", modname);
-                               return -EEXIST;
-                       }
-                       return 0;
-               }
-       }
-
-       err = insmod_do_dependencies(mod);
-       if (err < 0)
-               return err;
-
        if (!ignore_commands) {
                const char *cmd;
 
@@ -745,6 +723,29 @@ static int insmod_do(struct kmod_module *mod, const char *extra_opts)
                }
        }
 
+       if (!ignore_loaded) {
+               int state = kmod_module_get_initstate(mod);
+
+               if (state == KMOD_MODULE_BUILTIN) {
+                       if (first_time) {
+                               LOG("Module %s already in kernel (builtin).\n",
+                                   modname);
+                               return -EEXIST;
+                       }
+                       return 0;
+               } else if (state == KMOD_MODULE_LIVE) {
+                       if (first_time) {
+                               LOG("Module %s already in kernel.\n", modname);
+                               return -EEXIST;
+                       }
+                       return 0;
+               }
+       }
+
+       err = insmod_do_dependencies(mod);
+       if (err < 0)
+               return err;
+
        if (conf_opts || extra_opts) {
                if (conf_opts == NULL)
                        opts = strdup(extra_opts);