From bded7ff92626801b36208fd7a215fdafbcd5b7e4 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 23 Jun 2016 11:52:45 +0200 Subject: [PATCH] cgroup: detect cgroup namespaces - define CLONE_NEWCGROUP - add fun to detect whether cgroup namespaces are supported --- src/basic/cgroup-util.c | 16 ++++++++++++++++ src/basic/cgroup-util.h | 2 ++ src/basic/missing.h | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 5e53f447d..a19995051 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -134,6 +134,22 @@ int cg_read_event(const char *controller, const char *path, const char *event, return -ENOENT; } +#if 0 /// UNNEEDED by elogind +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; +} +#endif //0 + int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) { _cleanup_free_ char *fs = NULL; int r; diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 56598d22b..2c91a8671 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -232,6 +232,8 @@ int cg_mask_supported(CGroupMask *ret); #if 0 /// UNNEEDED by elogind int cg_kernel_controllers(Set *controllers); + +bool cg_ns_supported(void); #endif // 0 int cg_unified(void); diff --git a/src/basic/missing.h b/src/basic/missing.h index f2a0e1d8b..848495ee2 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -450,6 +450,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 -- 2.30.2