From 39012eeefa454e09fc4192cacddb508ee00abee6 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 20 Dec 2022 21:39:08 +0530 Subject: [PATCH] =?utf8?q?api:=20cgroup=20v2=20=E2=80=93=20read=20subtree?= =?utf8?q?=5Fcontrol=20of=20the=20leaf=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Tom Hromatka --- src/api.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/api.c b/src/api.c index cd0b5e4d..5480c7a8 100644 --- a/src/api.c +++ b/src/api.c @@ -1850,7 +1850,6 @@ error: 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; @@ -1876,24 +1875,13 @@ STATIC int cgroupv2_controller_enabled(const char * const cg_name, const char * 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; } -- 2.47.2