cgroups: rework cg_unified_init()

Cc: stable-4.0 Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 09ed8992
...@@ -3298,12 +3298,11 @@ static char *cg_unified_get_current_cgroup(bool relative) ...@@ -3298,12 +3298,11 @@ static char *cg_unified_get_current_cgroup(bool relative)
static int cg_unified_init(struct cgroup_ops *ops, bool relative, static int cg_unified_init(struct cgroup_ops *ops, bool relative,
bool unprivileged) bool unprivileged)
{ {
__do_free char *subtree_path = NULL; __do_close int cgroup_root_fd = -EBADF;
__do_free char *base_cgroup = NULL, *controllers_path = NULL;
int ret; int ret;
char *mountpoint;
char **delegatable; char **delegatable;
struct hierarchy *new; struct hierarchy *new;
char *base_cgroup = NULL;
ret = unified_cgroup_hierarchy(); ret = unified_cgroup_hierarchy();
if (ret == -ENOMEDIUM) if (ret == -ENOMEDIUM)
...@@ -3318,14 +3317,18 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative, ...@@ -3318,14 +3317,18 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative,
if (!relative) if (!relative)
prune_init_scope(base_cgroup); prune_init_scope(base_cgroup);
cgroup_root_fd = openat(-EBADF, DEFAULT_CGROUP_MOUNTPOINT,
O_NOCTTY | O_CLOEXEC | O_NOFOLLOW | O_DIRECTORY);
if (cgroup_root_fd < 0)
return -errno;
/* /*
* We assume that the cgroup we're currently in has been delegated to * We assume that the cgroup we're currently in has been delegated to
* us and we are free to further delege all of the controllers listed * us and we are free to further delege all of the controllers listed
* in cgroup.controllers further down the hierarchy. * in cgroup.controllers further down the hierarchy.
*/ */
mountpoint = must_copy_string(DEFAULT_CGROUP_MOUNTPOINT); controllers_path = must_make_path_relative(base_cgroup, "cgroup.controllers", NULL);
subtree_path = must_make_path(mountpoint, base_cgroup, "cgroup.controllers", NULL); delegatable = cg_unified_get_controllers(cgroup_root_fd, controllers_path);
delegatable = cg_unified_get_controllers(subtree_path);
if (!delegatable) if (!delegatable)
delegatable = cg_unified_make_empty_controller(); delegatable = cg_unified_make_empty_controller();
if (!delegatable[0]) if (!delegatable[0])
...@@ -3338,7 +3341,11 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative, ...@@ -3338,7 +3341,11 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative,
* controllers per container. * controllers per container.
*/ */
new = add_hierarchy(&ops->hierarchies, delegatable, mountpoint, base_cgroup, CGROUP2_SUPER_MAGIC); new = add_hierarchy(&ops->hierarchies,
delegatable,
must_copy_string(DEFAULT_CGROUP_MOUNTPOINT),
move_ptr(base_cgroup),
CGROUP2_SUPER_MAGIC);
if (unprivileged) if (unprivileged)
cg_unified_delegate(&new->cgroup2_chown); cg_unified_delegate(&new->cgroup2_chown);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment