]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: move cgns_supported() to cgroup utilities
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 10:47:53 +0000 (11:47 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 15 Feb 2021 10:51:11 +0000 (11:51 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c
src/lxc/cgroups/cgroup_utils.h
src/lxc/lsm/apparmor.c
src/lxc/start.c
src/lxc/utils.c
src/lxc/utils.h
src/tests/lxc_raw_clone.c

index da4aa355735a9ba8332bec182e2ce59cbad0a5c5..3173ca535ecf4f74335d9e2056778bdbce6bcf70 100644 (file)
@@ -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"
index 818eead1de42453fa757f9da303e08e2e4f9866f..02f4b474904ad402fc6db0cb586e4613321cc4dc 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdio.h>
 
 #include "compiler.h"
+#include "file_utils.h"
 
 /* Retrieve the cgroup version of a given entry from /proc/<pid>/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 */
index 5c9c19905e917fc14e8082e3cebe869f6ef48cd1..54ffd157289df9d36f42cc8fb9135609e4f6b179 100644 (file)
@@ -13,6 +13,7 @@
 #include <unistd.h>
 
 #include "caps.h"
+#include "cgroups/cgroup_utils.h"
 #include "conf.h"
 #include "config.h"
 #include "initutils.h"
index 02cc7e0d3b18f8a5c6ccf6f77ecaf579083e1670..466897dad32f9c5d137a81296ad7f909b247fcf9 100644 (file)
@@ -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"
index 48a36edd7c1f89a1f4f280cf61132747775cfc3f..ce00104ed9ceb26867aabd9533cf8228e8b87fcc 100644 (file)
@@ -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.
  */
index a7c35c73c1ee8e21f69896f9cd9b36e69b7bc745..b8f23994c88e2e08296d65499052d402486aa4a2 100644 (file)
@@ -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);
index f72e20cccda6e4c16b09aff7d586800cfd839953..6b845b640e1528e525bc84a55a61ff0e3fc092cd 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "cgroups/cgroup_utils.h"
 #include "lxctest.h"
 #include "namespace.h"
 #include "process_utils.h"