]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Use errno instead of return value of init_module()
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 30 Dec 2011 16:13:33 +0000 (14:13 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 30 Dec 2011 16:13:33 +0000 (14:13 -0200)
Return -errno instead of the value returned by init_module(). We need to
differentiate between the several errors that might occur, e.g. "module
already loaded", access denied, etc.

libkmod/libkmod-module.c

index 64dda187c626557bdeeeb89de8e475d7b965d71a..0390250d0af50747ecbf861cf9bf0efdd9681145 100644 (file)
@@ -677,7 +677,8 @@ extern long init_module(const void *mem, unsigned long len, const char *args);
  * Insert a module in Linux kernel. It opens the file pointed by @mod,
  * mmap'ing it and passing to kernel.
  *
- * Returns: 0 on success or < 0 on failure.
+ * Returns: 0 on success or < 0 on failure. If module is already loaded it
+ * returns -EEXIST.
  */
 KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
                                                        unsigned int flags,
@@ -732,8 +733,10 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
        }
 
        err = init_module(mem, size, args);
-       if (err < 0)
-               ERR(mod->ctx, "Failed to insert module '%s'\n", path);
+       if (err < 0) {
+               err = -errno;
+               INFO(mod->ctx, "Failed to insert module '%s': %m\n", path);
+       }
 
        if (elf != NULL)
                kmod_elf_unref(elf);