]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/procfs: use VFS dispatch for read and close
authorKarel Zak <kzak@redhat.com>
Tue, 30 Jun 2026 15:17:31 +0000 (17:17 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Jul 2026 10:18:04 +0000 (12:18 +0200)
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 <kzak@redhat.com>
lib/procfs.c

index 1f760a14426d07e9a8995ac234dacb27a656a0f2..c948e4bcf7117441576dc6047c951e6f8b425b9c 100644 (file)
@@ -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;