]> git.proxmox.com Git - mirror_lxcfs.git/blobdiff - src/bindings.c
tree-wide: set _GNU_SOURCE in meson.build
[mirror_lxcfs.git] / src / bindings.c
index 28da74b086a5e4b07bb2e155ca4612688d74c6ea..eb62ddbdbc656686aec33735056a4b131bd45c69 100644 (file)
@@ -1,19 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#ifndef FUSE_USE_VERSION
-#define FUSE_USE_VERSION 26
-#endif
-
-#define _FILE_OFFSET_BITS 64
+#include "config.h"
 
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <fuse.h>
 #include <inttypes.h>
 #include <libgen.h>
 #include <linux/magic.h>
 #include <unistd.h>
 #include <wait.h>
 
-#include "api_extensions.h"
 #include "bindings.h"
+
+#include "api_extensions.h"
 #include "cgroup_fuse.h"
 #include "cgroups/cgroup.h"
 #include "cgroups/cgroup_utils.h"
-#include "config.h"
 #include "memory_utils.h"
 #include "proc_cpuview.h"
 #include "syscall_numbers.h"
 #include "utils.h"
 
 static bool can_use_pidfd;
+static bool can_use_swap;
+static bool can_use_sys_cpu;
+static bool has_versioned_opts;
 
 static volatile sig_atomic_t reload_successful;
 
@@ -58,6 +52,21 @@ bool liblxcfs_functional(void)
        return reload_successful != 0;
 }
 
+bool liblxcfs_can_use_swap(void)
+{
+       return can_use_swap;
+}
+
+bool liblxcfs_can_use_sys_cpu(void)
+{
+       return can_use_sys_cpu;
+}
+
+bool liblxcfs_has_versioned_opts(void)
+{
+       return has_versioned_opts;
+}
+
 /* Define pivot_root() if missing from the C library */
 #ifndef HAVE_PIVOT_ROOT
 static int pivot_root(const char *new_root, const char *put_old)
@@ -596,7 +605,7 @@ static bool is_on_ramfs(void)
        return false;
 }
 
-static int pivot_enter()
+static int pivot_enter(void)
 {
        __do_close int oldroot = -EBADF, newroot = -EBADF;
 
@@ -639,7 +648,7 @@ static int pivot_enter()
        return 0;
 }
 
-static int chroot_enter()
+static int chroot_enter(void)
 {
        if (mount(ROOTDIR, "/", NULL, MS_REC | MS_BIND, NULL)) {
                lxcfs_error("Failed to recursively bind-mount %s into /.", ROOTDIR);
@@ -816,9 +825,8 @@ static void sigusr2_toggle_virtualization(int signo, siginfo_t *info, void *extr
 please_compiler:
        /*
         * The write() syscall is a function whose return value needs to be
-        * checked. Otherwise the compiler will warn. This is how we
-        * please our master. Another one could be to use
-        * syscall(__NR_write, ...) directly but whatever.
+        * checked. Otherwise the compiler will warn.Another one could be to
+        * use syscall(__NR_write, ...) directly but whatever.
         */
        return;
 }
@@ -880,9 +888,15 @@ static void __attribute__((constructor)) lxcfs_init(void)
                lxcfs_info("Kernel supports pidfds");
        }
 
+       can_use_swap = cgroup_ops->can_use_swap(cgroup_ops);
+       if (can_use_swap)
+               lxcfs_info("Kernel supports swap accounting");
+       else
+               lxcfs_info("Kernel does not support swap accounting");
+
        lxcfs_info("api_extensions:");
-       for (i = 0; i < nr_api_extensions; i++)
-               lxcfs_info("- %s", api_extensions[i]);
+       for (size_t nr = 0; nr < nr_api_extensions; nr++)
+               lxcfs_info("- %s", api_extensions[nr]);
 
        root_fd = open("/", O_PATH | O_CLOEXEC);
        if (root_fd < 0)
@@ -911,3 +925,11 @@ static void __attribute__((destructor)) lxcfs_exit(void)
        free_cpuview();
        cgroup_exit(cgroup_ops);
 }
+
+void *lxcfs_fuse_init(struct fuse_conn_info *conn, void *data)
+{
+       struct fuse_context *fc = fuse_get_context();
+       can_use_sys_cpu = true;
+       has_versioned_opts = true;
+       return fc->private_data;
+}