kmod_module: treat module creation by path with same names
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 7 Dec 2011 16:08:01 +0000 (14:08 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 7 Dec 2011 16:15:49 +0000 (14:15 -0200)
If a module with the same name already exists, try to reference it if
paths are the same. Otherwise fail.

libkmod/libkmod-module.c

index 0aee3ee..3acd5b0 100644 (file)
@@ -202,7 +202,17 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
 
        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;
        }