Use errno instead of return value of init_module()
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.
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 64dda18..0390250 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -677,7 +677,8 @@
* 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 @@
}
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);