From: Karel Zak Date: Tue, 30 Jun 2026 15:17:31 +0000 (+0200) Subject: lib/procfs: use VFS dispatch for read and close X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e9acd2dbb4ac30f14ca7ec6a8b83aab622b4214;p=thirdparty%2Futil-linux.git lib/procfs: use VFS dispatch for read and close Pass VFS ops from path_cxt to read_procfs_file() and use ul_vfs_close() in procfs_process_get_data_for(). Addresses: https://github.com/util-linux/util-linux/issues/4308 Signed-off-by: Karel Zak --- diff --git a/lib/procfs.c b/lib/procfs.c index 1f760a144..c948e4bcf 100644 --- a/lib/procfs.c +++ b/lib/procfs.c @@ -17,6 +17,7 @@ #include "procfs.h" #include "fileutils.h" #include "all-io.h" +#include "vfs.h" #include "debug.h" #include "strutils.h" #include "statfs_magic.h" @@ -119,7 +120,8 @@ static void procfs_process_deinit_path(struct path_cxt *pc) ul_path_set_dialect(pc, NULL, NULL); } -static ssize_t read_procfs_file(int fd, char *buf, size_t bufsz) +static ssize_t read_procfs_file(const struct ul_vfs_ops *vfs, int fd, + char *buf, size_t bufsz) { ssize_t sz = 0; size_t i; @@ -127,7 +129,7 @@ static ssize_t read_procfs_file(int fd, char *buf, size_t bufsz) if (fd < 0) return -EINVAL; - sz = ul_read_all(fd, buf, bufsz); + sz = ul_vfs_read_all(vfs, fd, buf, bufsz); if (sz <= 0) return sz; @@ -145,8 +147,8 @@ static ssize_t procfs_process_get_data_for(struct path_cxt *pc, char *buf, size_ int fd = ul_path_open(pc, O_RDONLY|O_CLOEXEC, fname); if (fd >= 0) { - ssize_t sz = read_procfs_file(fd, buf, bufsz); - close(fd); + ssize_t sz = read_procfs_file(pc ? pc->vfs : NULL, fd, buf, bufsz); + ul_vfs_close(pc ? pc->vfs : NULL, fd); return sz; } return -errno; @@ -430,7 +432,7 @@ static char *strdup_procfs_file(pid_t pid, const char *name) if (fd < 0) return NULL; - if (read_procfs_file(fd, buf, sizeof(buf)) > 0) + if (read_procfs_file(NULL, fd, buf, sizeof(buf)) > 0) re = strdup(buf); close(fd); return re;