cgroups: split out unified cgroup helpers

parent 91fae3ab
...@@ -3416,6 +3416,34 @@ static int cg_hybrid_init(struct cgroup_ops *ops, bool relative, bool unprivileg ...@@ -3416,6 +3416,34 @@ static int cg_hybrid_init(struct cgroup_ops *ops, bool relative, bool unprivileg
return 0; return 0;
} }
static inline bool __current_cgroup_unified_line(const char *line)
{
return *line == '0';
}
static inline char *__current_cgroup_unified(bool relative, char *line)
{
char *current_cgroup;
line += STRLITERALLEN("0::");
if (!abspath(line))
return ERR_PTR(-EINVAL);
/* remove init.scope */
if (!relative)
line = prune_init_scope(line);
/* create a relative path */
line = deabs(line);
current_cgroup = strdup(line);
if (!current_cgroup)
return ERR_PTR(-ENOMEM);
return current_cgroup;
}
/* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */ /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
static char *current_cgroup_unified(bool relative) static char *current_cgroup_unified(bool relative)
{ {
...@@ -3430,22 +3458,16 @@ static char *current_cgroup_unified(bool relative) ...@@ -3430,22 +3458,16 @@ static char *current_cgroup_unified(bool relative)
return NULL; return NULL;
lxc_iterate_parts(it, cgroup_info, "\n") { lxc_iterate_parts(it, cgroup_info, "\n") {
if (*it != '0') char *current_cgroup;
continue;
it += STRLITERALLEN("0::"); if (!__current_cgroup_unified_line(it))
continue;
if (!abspath(it))
return log_error(NULL, "Corrupt cgroup info for %s process", relative ? "current" : "init");
/* remove init.scope */
if (!relative)
it = prune_init_scope(it);
/* create a relative path */ current_cgroup = __current_cgroup_unified(relative, it);
it = deabs(it); if (IS_ERR(current_cgroup))
return NULL;
return strdup(it); return current_cgroup;
} }
return log_error(NULL, "Failed to retrieve current cgroup for %s process", return log_error(NULL, "Failed to retrieve current cgroup for %s process",
......
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