]> git.proxmox.com Git - mirror_lxcfs.git/blobdiff - src/bindings.c
Fix build on ia64
[mirror_lxcfs.git] / src / bindings.c
index 8dc885da777b1fecc1210f572c0315d54bff7489..fe106a65c34ceb28e8a077525a661d0ffc6b1e3b 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"
@@ -51,6 +42,9 @@
 
 static bool can_use_pidfd;
 static bool can_use_swap;
+static bool can_use_sys_cpu;
+static bool has_versioned_opts;
+static bool memory_is_cgroupv2;
 
 static volatile sig_atomic_t reload_successful;
 
@@ -64,6 +58,21 @@ 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;
+}
+
+bool liblxcfs_memory_is_cgroupv2(void)
+{
+       return memory_is_cgroupv2;
+}
+
 /* 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)
@@ -415,7 +424,7 @@ __returns_twice pid_t lxcfs_raw_clone(unsigned long flags, int *pidfd)
        }
 #elif defined(__ia64__)
        /* On ia64 the stack and stack size are passed as separate arguments. */
-       return syscall(__NR_clone, flags | SIGCHLD, NULL, prctl_arg(0), pidfd);
+       return syscall(__NR_clone, flags | SIGCHLD, NULL, 0, pidfd);
 #else
        return syscall(__NR_clone, flags | SIGCHLD, NULL, pidfd);
 #endif
@@ -602,7 +611,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;
 
@@ -645,7 +654,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);
@@ -822,9 +831,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;
 }
@@ -835,6 +843,7 @@ static void __attribute__((constructor)) lxcfs_init(void)
                                  pidfd = -EBADF;
        int i = 0;
        pid_t pid;
+       struct hierarchy *hierarchy;
 
        lxcfs_info("Running constructor %s to reload liblxcfs", __func__);
 
@@ -892,9 +901,12 @@ static void __attribute__((constructor)) lxcfs_init(void)
        else
                lxcfs_info("Kernel does not support swap accounting");
 
+       hierarchy = cgroup_ops->get_hierarchy(cgroup_ops, "memory");
+       memory_is_cgroupv2 = hierarchy && is_unified_hierarchy(hierarchy);
+
        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)
@@ -923,3 +935,13 @@ 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();
+#if HAVE_FUSE_RETURNS_DT_TYPE
+       can_use_sys_cpu = true;
+#endif
+       has_versioned_opts = true;
+       return fc ? fc->private_data : NULL;
+}