From: Christian Brauner Date: Mon, 15 Feb 2021 10:47:53 +0000 (+0100) Subject: cgroups: move cgns_supported() to cgroup utilities X-Git-Tag: lxc-5.0.0~287^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c988c8b1ceb45c8104af501961468a7b8b1d92cd;p=thirdparty%2Flxc.git cgroups: move cgns_supported() to cgroup utilities Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index da4aa3557..3173ca535 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -27,7 +27,8 @@ #include "af_unix.h" #include "attach.h" #include "caps.h" -#include "cgroup.h" +#include "cgroups/cgroup.h" +#include "cgroups/cgroup_utils.h" #include "commands.h" #include "conf.h" #include "config.h" diff --git a/src/lxc/cgroups/cgroup_utils.h b/src/lxc/cgroups/cgroup_utils.h index 818eead1d..02f4b4749 100644 --- a/src/lxc/cgroups/cgroup_utils.h +++ b/src/lxc/cgroups/cgroup_utils.h @@ -7,6 +7,7 @@ #include #include "compiler.h" +#include "file_utils.h" /* Retrieve the cgroup version of a given entry from /proc//mountinfo. */ __hidden extern int get_cgroup_version(char *line); @@ -32,4 +33,14 @@ __hidden extern int unified_cgroup_hierarchy(void); __hidden extern int unified_cgroup_fd(int fd); +static inline bool cgns_supported(void) +{ + static int supported = -1; + + if (supported == -1) + supported = file_exists("/proc/self/ns/cgroup"); + + return supported == 1; +} + #endif /* __LXC_CGROUP_UTILS_H */ diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 5c9c19905..54ffd1572 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -13,6 +13,7 @@ #include #include "caps.h" +#include "cgroups/cgroup_utils.h" #include "conf.h" #include "config.h" #include "initutils.h" diff --git a/src/lxc/start.c b/src/lxc/start.c index 02cc7e0d3..466897dad 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -27,7 +27,8 @@ #include "af_unix.h" #include "caps.h" -#include "cgroup.h" +#include "cgroups/cgroup.h" +#include "cgroups/cgroup_utils.h" #include "commands.h" #include "commands_utils.h" #include "compiler.h" diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 48a36edd7..ce00104ed 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -747,11 +747,6 @@ char *on_path(const char *cmd, const char *rootfs) return NULL; } -bool cgns_supported(void) -{ - return file_exists("/proc/self/ns/cgroup"); -} - /* historically lxc-init has been under /usr/lib/lxc and under * /usr/lib/$ARCH/lxc. It now lives as $prefix/sbin/init.lxc. */ diff --git a/src/lxc/utils.h b/src/lxc/utils.h index a7c35c73c..b8f23994c 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -138,7 +138,6 @@ __hidden extern bool is_shared_mountpoint(const char *path); __hidden extern int detect_shared_rootfs(void); __hidden extern bool detect_ramfs_rootfs(void); __hidden extern char *on_path(const char *cmd, const char *rootfs); -__hidden extern bool cgns_supported(void); __hidden extern char *choose_init(const char *rootfs); __hidden extern bool switch_to_ns(pid_t pid, const char *ns); __hidden extern char *get_template_path(const char *t); diff --git a/src/tests/lxc_raw_clone.c b/src/tests/lxc_raw_clone.c index f72e20ccc..6b845b640 100644 --- a/src/tests/lxc_raw_clone.c +++ b/src/tests/lxc_raw_clone.c @@ -37,6 +37,7 @@ #include #include +#include "cgroups/cgroup_utils.h" #include "lxctest.h" #include "namespace.h" #include "process_utils.h"