]> git.proxmox.com Git - mirror_lxcfs.git/blobdiff - src/bindings.c
Fix build on ia64
[mirror_lxcfs.git] / src / bindings.c
index 70906c67d6d019b3997ce31dad5d85692f90ddc2..fe106a65c34ceb28e8a077525a661d0ffc6b1e3b 100644 (file)
@@ -1,27 +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
-
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <fuse.h>
 #include <inttypes.h>
 #include <libgen.h>
 #include <linux/magic.h>
@@ -46,8 +29,9 @@
 #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"
@@ -60,6 +44,7 @@ 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;
 
@@ -83,6 +68,11 @@ 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)
@@ -434,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
@@ -621,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;
 
@@ -664,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);
@@ -853,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__);
 
@@ -910,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)
@@ -942,10 +936,12 @@ static void __attribute__((destructor)) lxcfs_exit(void)
        cgroup_exit(cgroup_ops);
 }
 
-void *lxcfs_fuse_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
+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->private_data;
+       return fc ? fc->private_data : NULL;
 }