]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
replace opathdir with opendir_flags
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2022 11:55:20 +0000 (13:55 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2022 11:58:41 +0000 (13:58 +0200)
`opathdir` was used to replace `opendir` in order to ensure
`O_NOFOLLOW` and `O_CLOEXEC` were set, however it also added
`O_PATH` which prevents `readdir`/`getdents` to be used on
it, causing the `/sys/devices/system/cpu/<subdir>`
directories to be empty.

Instead, let's have an `opendir_flags` utility which simply
passed additional flags to the `open(..., O_DIRECTORY)` call
preceding `fdopendir()`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/sysfs_fuse.c
src/utils.c
src/utils.h

index 892be8939ed1b6e9a00a0d753425266131dd44a1..5e3b631379af0c0c85ca9090c8e0b4f48fc44c5a 100644 (file)
@@ -596,7 +596,7 @@ __lxcfs_fuse_ops int sys_readdir(const char *path, void *buf,
 
                return filler_sys_devices_system_cpu(path, buf, filler);
        case LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_SUBDIR:
-               dirp = opathdir(path);
+               dirp = opendir_flags(path, O_CLOEXEC | O_NOFOLLOW);
                if (!dirp)
                        return -errno;
 
index 8771be2f1d494aaae588755bb277671bdb2cf484..926760df5a3bf9e10e291a4010d0fddba9cac816 100644 (file)
@@ -627,12 +627,12 @@ char *read_file_at(int dfd, const char *fnam, unsigned int o_flags)
        return move_ptr(buf);
 }
 
-DIR *opathdir(const char *path)
+DIR *opendir_flags(const char *path, int flags)
 {
        __do_close int dfd = -EBADF;
        DIR *dirp;
 
-       dfd = open(path, O_DIRECTORY | O_PATH | O_CLOEXEC | O_NOFOLLOW);
+       dfd = open(path, O_DIRECTORY | flags);
        if (dfd < 0)
                return NULL;
 
index 0e8d3c86c106fa08ea6325811b0ff085c12fd8f1..eb01aca2f780db335634958a3e97e13c6478d9e5 100644 (file)
@@ -59,7 +59,7 @@ static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
 extern FILE *fopen_cached(const char *path, const char *mode,
                          void **caller_freed_buffer);
 extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer);
-extern DIR *opathdir(const char *path);
+extern DIR *opendir_flags(const char *path, int oflags);
 extern ssize_t write_nointr(int fd, const void *buf, size_t count);
 extern int safe_uint64(const char *numstr, uint64_t *converted, int base);
 extern char *trim_whitespace_in_place(char *buffer);