From: Lucas De Marchi Date: Fri, 30 Dec 2011 16:13:33 +0000 (-0200) Subject: Use errno instead of return value of init_module() X-Git-Tag: v3~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbf59327e397f3a5dd810cb044e1823d3b17653e;p=thirdparty%2Fkmod.git 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 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);