]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
kmod_module: get path on demand
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 5 Dec 2011 22:28:13 +0000 (20:28 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Dec 2011 04:48:04 +0000 (02:48 -0200)
libkmod/libkmod-module.c

index 74e8d22af0bb2db4a37d3f09ae76e4363629423f..152d8f64457aa96d4867cfefe0cff76925d860cc 100644 (file)
@@ -377,9 +377,26 @@ KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod)
        return mod->name;
 }
 
+/*
+ * Relative paths are relative to dirname. Absolute paths are only used when
+ * user created kmod_module by giving a path
+ */
 KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod)
 {
-       // FIXME calculate path if path == NULL
+       if (!mod->init.dep) {
+               /* lazy init */
+               char *line = kmod_search_moddep(mod->ctx, mod->name);
+
+               if (line == NULL)
+                       return NULL;
+
+               kmod_module_parse_depline((struct kmod_module *) mod, line);
+               free(line);
+
+               if (!mod->init.dep)
+                       return NULL;
+       }
+
        return mod->path;
 }