aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.de.marchi@gmail.com>2012-06-05 00:53:15 -0300
committerLucas De Marchi <lucas.de.marchi@gmail.com>2012-06-05 00:54:48 -0300
commita655370541b5ddd681e864ddf23b1e3e214830b7 (patch)
tree23ebe24f76bbf4bf4fe47f59264b6ffcffdfecff
parentddf1e7a61711580fee4d8d904a4a388aafecce27 (diff)
downloadkmod-a655370541b5ddd681e864ddf23b1e3e214830b7.tar.gz
testsuite: check if module is in kernel for return code
-rw-r--r--testsuite/init_module.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/testsuite/init_module.c b/testsuite/init_module.c
index 5983941..6db0d17 100644
--- a/testsuite/init_module.c
+++ b/testsuite/init_module.c
@@ -48,6 +48,7 @@ struct mod {
static struct mod *modules;
static bool need_init = true;
+static struct kmod_ctx *ctx;
static void parse_retcodes(struct mod *_modules, const char *s)
{
@@ -178,9 +179,33 @@ static void init_retcodes(void)
S_TC_INIT_MODULE_RETCODES);
}
+ ctx = kmod_new(NULL, NULL);
+
parse_retcodes(modules, s);
}
+static inline bool module_is_inkernel(const char *modname)
+{
+ struct kmod_module *mod;
+ int state;
+ bool ret;
+
+ if (kmod_module_new_from_name(ctx, modname, &mod) < 0)
+ return false;
+
+ state = kmod_module_get_initstate(mod);
+
+ if (state == KMOD_MODULE_LIVE ||
+ state == KMOD_MODULE_BUILTIN)
+ ret = true;
+ else
+ ret = false;
+
+ kmod_module_unref(mod);
+
+ return ret;
+}
+
TS_EXPORT long init_module(void *mem, unsigned long len, const char *args);
/*
@@ -223,10 +248,11 @@ long init_module(void *mem, unsigned long len, const char *args)
if (mod != NULL) {
errno = mod->errcode;
err = mod->ret;
- } else {
- /* mimic kernel behavior here */
+ } else if (module_is_inkernel(modname)) {
+ err = -1;
+ errno = EEXIST;
+ } else
err = 0;
- }
if (err == 0)
create_sysfs_files(modname);
@@ -243,4 +269,7 @@ void free_resources(void)
free(modules);
modules = mod;
}
+
+ if (ctx)
+ kmod_unref(ctx);
}