From bbf59327e397f3a5dd810cb044e1823d3b17653e Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 30 Dec 2011 14:13:33 -0200 Subject: [PATCH] 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. --- libkmod/libkmod-module.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 64dda187..0390250d 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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); -- 2.47.3