kmod_module: treat module creation by path with same names
If a module with the same name already exists, try to reference it if
paths are the same. Otherwise fail.
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 0aee3ee..3acd5b0 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -202,7 +202,17 @@
m = kmod_pool_get_module(ctx, name);
if (m != NULL) {
- free(abspath);
+ if (m->path == NULL)
+ m->path = abspath;
+ else if (streq(m->path, abspath))
+ free(abspath);
+ else {
+ ERR(ctx, "kmod_module '%s' already exists with different path\n",
+ name);
+ free(abspath);
+ return -EEXIST;
+ }
+
*mod = kmod_module_ref(m);
return 0;
}