From: Kamalesh Babulal Date: Tue, 20 Dec 2022 16:09:08 +0000 (+0530) Subject: api: cgroup v2 – read subtree_control of the leaf node X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2955fad3981ad630a02a725f6aad3f02d5f3ea2;p=thirdparty%2Flibcgroup.git api: cgroup v2 – read subtree_control of the leaf node 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 --- 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; }