cgroup: detect cgroup namespaces

- define CLONE_NEWCGROUP
- add fun to detect whether cgroup namespaces are supported
This commit is contained in:
Christian Brauner 2016-06-23 11:52:45 +02:00
parent d6cdc4cd4b
commit 3228995c53
3 changed files with 20 additions and 0 deletions

View 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;

View 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);

View 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