/* 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>
#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"
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;
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)
}
#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
return false;
}
-static int pivot_enter()
+static int pivot_enter(void)
{
__do_close int oldroot = -EBADF, newroot = -EBADF;
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);
pidfd = -EBADF;
int i = 0;
pid_t pid;
+ struct hierarchy *hierarchy;
lxcfs_info("Running constructor %s to reload liblxcfs", __func__);
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)
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;
}