From 71e975cd4d73fcebb3772ac18a8a231830bd9b43 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 7 Dec 2011 13:53:53 -0200 Subject: [PATCH] kmod_module: store absolute path when creating module from path --- libkmod/libkmod-module.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index e7a7150..0aee3ee 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -182,19 +182,27 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, int err; struct stat st; char name[NAME_MAX]; + char *abspath; size_t namelen; if (ctx == NULL || path == NULL) return -ENOENT; - err = stat(path, &st); - if (err < 0) + abspath = path_make_absolute_cwd(path); + if (abspath == NULL) + return -ENOMEM; + + err = stat(abspath, &st); + if (err < 0) { + free(abspath); return -errno; + } path_to_modname(path, name, &namelen); m = kmod_pool_get_module(ctx, name); if (m != NULL) { + free(abspath); *mod = kmod_module_ref(m); return 0; } @@ -203,15 +211,9 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, if (m == NULL) return -errno; - m->path = strdup(path); - if (m->path == NULL) { - err = -errno; - free(m); - return err; - } - m->ctx = kmod_ref(ctx); memcpy(m->name, name, namelen); + m->path = abspath; m->refcount = 1; kmod_pool_add_module(ctx, m); -- 2.7.4