]> git.proxmox.com Git - mirror_lxcfs.git/blobdiff - src/proc_fuse.c
tree-wide: set _GNU_SOURCE in meson.build
[mirror_lxcfs.git] / src / proc_fuse.c
index 3a36dcac4f40b254a0097372cd6941b7c4c5b1df..4ac5d44b0a10c32033044f89627e3b303a8d51b4 100644 (file)
@@ -1,28 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
 #include "config.h"
 
-#ifdef HAVE_FUSE3
-#ifndef FUSE_USE_VERSION
-#define FUSE_USE_VERSION 30
-#endif
-#else
-#ifndef FUSE_USE_VERSION
-#define FUSE_USE_VERSION 26
-#endif
-#endif
-
-#define _FILE_OFFSET_BITS 64
-
-#define __STDC_FORMAT_MACROS
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <fuse.h>
 #include <inttypes.h>
 #include <libgen.h>
 #include <pthread.h>
@@ -47,6 +29,8 @@
 #include <sys/sysinfo.h>
 #include <sys/vfs.h>
 
+#include "proc_fuse.h"
+
 #include "bindings.h"
 #include "cgroup_fuse.h"
 #include "cgroups/cgroup.h"
@@ -325,8 +309,7 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
        __do_free char *cgroup = NULL, *memusage_str = NULL,
                 *memswusage_str = NULL, *memswpriority_str = NULL;
        struct fuse_context *fc = fuse_get_context();
-       struct lxcfs_opts *opts = (struct lxcfs_opts *)fuse_get_context()->private_data;
-       bool wants_swap = opts && !opts->swap_off && liblxcfs_can_use_swap();
+       bool wants_swap = lxcfs_has_opt(fuse_get_context()->private_data, LXCFS_SWAP_ON);
        struct file_info *d = INTTYPE_TO_PTR(fi->fh);
        uint64_t memswlimit = 0, memlimit = 0, memusage = 0, memswusage = 0,
                 swtotal = 0, swusage = 0, memswpriority = 1,
@@ -341,7 +324,7 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
        size_t linelen = 0;
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -438,7 +421,7 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
        d->cached = 1;
        d->size = (int)total_len;
 
-       if (total_len > size)
+       if ((size_t)total_len > size)
                total_len = size;
        memcpy(buf, d->buf, total_len);
 
@@ -512,7 +495,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
        int ret;
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -643,7 +626,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
                l = snprintf(cache, cache_size, "%s", lbuf);
                if (l < 0)
                        return log_error(0, "Failed to write cache");
-               if (l >= cache_size)
+               if ((size_t)l >= cache_size)
                        return log_error(0, "Write to cache was truncated");
 
                cache += l;
@@ -660,7 +643,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
        return total_len;
 }
 
-#if RELOADTEST
+#ifdef RELOADTEST
 static inline void iwashere(void)
 {
        mknod("/tmp/lxcfs-iwashere", S_IFREG, 0644);
@@ -815,12 +798,12 @@ static int proc_uptime_read(char *buf, size_t size, off_t offset,
        ssize_t total_len = 0, ret = 0;
        double busytime, idletime, reaperage;
 
-#if RELOADTEST
+#ifdef RELOADTEST
        iwashere();
 #endif
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -852,7 +835,7 @@ static int proc_uptime_read(char *buf, size_t size, off_t offset,
 
        d->cached = 1;
        d->size = total_len;
-       if (total_len > size)
+       if ((size_t)total_len > size)
                total_len = size;
        memcpy(buf, d->buf, total_len);
 
@@ -885,7 +868,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
        int cg_cpu_usage_size = 0;
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -959,7 +942,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
                        l = snprintf(cache, cache_size, "%s", line);
                        if (l < 0)
                                return log_error(0, "Failed to write cache");
-                       if (l >= cache_size)
+                       if ((size_t)l >= cache_size)
                                return log_error(0, "Write to cache was truncated");
 
                        cache += l;
@@ -996,7 +979,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
                        l = snprintf(cache, cache_size, "cpu%d%s", curcpu, c);
                        if (l < 0)
                                return log_error(0, "Failed to write cache");
-                       if (l >= cache_size)
+                       if ((size_t)l >= cache_size)
                                return log_error(0, "Write to cache was truncated");
 
                        cache += l;
@@ -1016,9 +999,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 
                        if (all_used >= cg_used) {
                                new_idle = idle + (all_used - cg_used);
-
                        } else {
-                               lxcfs_error("cpu%d from %s has unexpected cpu time: %" PRIu64 " in /proc/stat, %" PRIu64 " in cpuacct.usage_all; unable to determine idle time",
+                               lxcfs_debug("cpu%d from %s has unexpected cpu time: %" PRIu64 " in /proc/stat, %" PRIu64 " in cpuacct.usage_all; unable to determine idle time",
                                            curcpu, cg, all_used, cg_used);
                                new_idle = idle;
                        }
@@ -1029,7 +1011,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
                                     cg_cpu_usage[physcpu].system, new_idle);
                        if (l < 0)
                                return log_error(0, "Failed to write cache");
-                       if (l >= cache_size)
+                       if ((size_t)l >= cache_size)
                                return log_error(0, "Write to cache was truncated");
 
                        cache += l;
@@ -1161,8 +1143,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
        __do_free void *fopen_cache = NULL;
        __do_fclose FILE *f = NULL;
        struct fuse_context *fc = fuse_get_context();
-       struct lxcfs_opts *opts = (struct lxcfs_opts *)fuse_get_context()->private_data;
-       bool wants_swap = opts && !opts->swap_off && liblxcfs_can_use_swap();
+       bool wants_swap = lxcfs_has_opt(fuse_get_context()->private_data, LXCFS_SWAP_ON);
        struct file_info *d = INTTYPE_TO_PTR(fi->fh);
        uint64_t memlimit = 0, memusage = 0, memswlimit = 0, memswusage = 0,
                 hosttotal = 0, swfree = 0, swusage = 0, swtotal = 0,
@@ -1174,7 +1155,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
        int ret;
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -1295,7 +1276,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                        snprintf(lbuf, 100, "SwapFree:       %8" PRIu64 " kB\n", swfree);
                        printme = lbuf;
                } else if (startswith(line, "Slab:")) {
-                       snprintf(lbuf, 100, "Slab:        %8" PRIu64 " kB\n", (uint64_t)0);
+                       snprintf(lbuf, 100, "Slab:           %8" PRIu64 " kB\n", (uint64_t)0);
                        printme = lbuf;
                } else if (startswith(line, "Buffers:")) {
                        snprintf(lbuf, 100, "Buffers:        %8" PRIu64 " kB\n", (uint64_t)0);
@@ -1384,7 +1365,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                l = snprintf(cache, cache_size, "%s", printme);
                if (l < 0)
                        return log_error(0, "Failed to write cache");
-               if (l >= cache_size)
+               if ((size_t)l >= cache_size)
                        return log_error(0, "Write to cache was truncated");
 
                cache += l;
@@ -1416,7 +1397,7 @@ static int proc_slabinfo_read(char *buf, size_t size, off_t offset,
        pid_t initpid;
 
        if (offset) {
-               int left;
+               size_t left;
 
                if (offset > d->size)
                        return -EINVAL;
@@ -1453,7 +1434,7 @@ static int proc_slabinfo_read(char *buf, size_t size, off_t offset,
                ssize_t l = snprintf(cache, cache_size, "%s", line);
                if (l < 0)
                        return log_error(0, "Failed to write cache");
-               if (l >= cache_size)
+               if ((size_t)l >= cache_size)
                        return log_error(0, "Write to cache was truncated");
 
                cache += l;