kmod_modprobe: Fix regression when inserting module
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 20 Dec 2011 15:11:33 +0000 (13:11 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 20 Dec 2011 15:11:33 +0000 (13:11 -0200)
Commit "e5e2a68 kmod_modprobe: properly handle install/remove commands"
introduced a regression that, while it worked for install/remove
commands, it ceased to work for normal module names. Move the check for
whether it's a install command or a module so both cases work.

tools/kmod-modprobe.c

index 7f069da..f78a7ac 100644 (file)
@@ -740,10 +740,7 @@ static int insmod_do(struct kmod_module *mod, const char *extra_opts)
        if (!ignore_loaded) {
                int state = kmod_module_get_initstate(mod);
 
-               if (state < 0) {
-                       LOG("Module %s not found.\n", modname);
-                       return -ENOENT;
-               } else if (state == KMOD_MODULE_BUILTIN) {
+               if (state == KMOD_MODULE_BUILTIN) {
                        if (first_time) {
                                LOG("Module %s already in kernel (builtin).\n",
                                    modname);
@@ -759,6 +756,16 @@ static int insmod_do(struct kmod_module *mod, const char *extra_opts)
                }
        }
 
+       /*
+        * At this point it's not possible to be a install/remove command
+        * anymore. So if we can't get module's path, it's because it was
+        * really intended to be a module and it doesn't exist
+        */
+       if (kmod_module_get_path(mod) == NULL) {
+               LOG("Module %s not found.\n", modname);
+               return -ENOENT;
+       }
+
        err = insmod_do_dependencies(mod);
        if (err < 0)
                return err;