]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: detect cgroup namespaces
authorChristian Brauner <cbrauner@suse.de>
Thu, 23 Jun 2016 09:52:45 +0000 (11:52 +0200)
committerChristian Brauner <cbrauner@suse.de>
Sat, 9 Jul 2016 03:49:04 +0000 (05:49 +0200)
- define CLONE_NEWCGROUP
- add fun to detect whether cgroup namespaces are supported

src/basic/cgroup-util.c
src/basic/cgroup-util.h
src/basic/missing.h

index 7cdc97ee3cb8be7c56596b18e48061758b3311c8..0561a07ed968b708b395436b4dd54a22f0a419a7 100644 (file)
@@ -134,6 +134,20 @@ int cg_read_event(const char *controller, const char *path, const char *event,
         return -ENOENT;
 }
 
+bool cg_ns_supported(void) {
+        static thread_local int enabled = -1;
+
+        if (enabled >= 0)
+                return enabled;
+
+        if (access("/proc/self/ns/cgroup", F_OK) == 0)
+                enabled = 1;
+        else
+                enabled = 0;
+
+        return enabled;
+}
+
 int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
         _cleanup_free_ char *fs = NULL;
         int r;
index 4bb529129668d7f6394f04816ea95fe67aefe2fd..5c1c474112500b234989fe6f7437fb012e19f46c 100644 (file)
@@ -214,6 +214,8 @@ int cg_mask_supported(CGroupMask *ret);
 
 int cg_kernel_controllers(Set *controllers);
 
+bool cg_ns_supported(void);
+
 int cg_unified(void);
 void cg_unified_flush(void);
 
index b1272f87990f6692d611c3ee058cb04a53a4da05..f8e096605e811b017dd5f205d8656192371e968a 100644 (file)
@@ -445,6 +445,10 @@ struct btrfs_ioctl_quota_ctl_args {
 #define CGROUP2_SUPER_MAGIC 0x63677270
 #endif
 
+#ifndef CLONE_NEWCGROUP
+#define CLONE_NEWCGROUP 0x02000000
+#endif
+
 #ifndef TMPFS_MAGIC
 #define TMPFS_MAGIC 0x01021994
 #endif