Re: [PATCH] libkmod: use realpath

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Forgot to mention. This commit can be modified freely to statisfy the maintainers :)

From: Wu Zhenyu <wuzhenyu@xxxxxxxx>
To: linux-modules@xxxxxxxxxxxxxxx
Subject: [PATCH] libkmod: use realpath
Date: Wed,  4 Oct 2023 21:04:08 +0800
Message-ID: <20231004130426.1673502-1-wuzhenyu@xxxxxxxx>
X-Mailer: git-send-email 2.42.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

$ modinfo ../Linux-Device-Driver/eg_07_ioctl/ioctl.ko | head -n1
filename:       /home/wzy/Desktop/kmod/../Linux-Device-Driver/eg_07_ioctl/ioctl.ko
$ tools/modinfo ../Linux-Device-Driver/eg_07_ioctl/ioctl.ko | head -n1
filename:       /home/wzy/Desktop/Linux-Device-Driver/eg_07_ioctl/ioctl.ko
---
 libkmod/libkmod-module.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 585da41..bdc1427 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -794,15 +794,17 @@ KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod)
  */
 KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod)
 {
-	char *line;
+	char *line, *path;
 
 	if (mod == NULL)
 		return NULL;
 
 	DBG(mod->ctx, "name='%s' path='%s'\n", mod->name, mod->path);
 
-	if (mod->path != NULL)
-		return mod->path;
+	if (mod->path != NULL) {
+		path = malloc(strlen(mod->path));
+		return realpath(mod->path, path);
+	}
 	if (mod->init.dep)
 		return NULL;
 
-- 
2.42.0






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux