With cgroup v2, while checking if a controller is enabled for cgroup,
the tree is walked and checked up to the parent cgroup of the leaf node,
this guarantees that the controller available for the leaf cgroups in
the cgroup.controllers file, but this is incomplete because of the
controller can be both either enabled or disabled in the
cgroups.subtree_control file of the leaf cgroup.
Fix this ambiguity by reading until the leaf node's
cgroup.subtree_control file, instead.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
STATIC int cgroupv2_controller_enabled(const char * const cg_name, const char * const ctrl_name)
{
char path[FILENAME_MAX] = {0};
- char *parent = NULL, *dname;
enum cg_version_t version;
bool enabled;
int error;
if (!cg_build_path(cg_name, path, ctrl_name))
goto err;
- parent = strdup(path);
- if (!parent) {
- error = ECGOTHER;
- goto err;
- }
-
- dname = dirname(parent);
-
- error = cgroupv2_get_subtree_control(dname, ctrl_name, &enabled);
+ error = cgroupv2_get_subtree_control(path, ctrl_name, &enabled);
if (error)
goto err;
if (enabled)
error = 0;
err:
- if (parent)
- free(parent);
-
return error;
}