From: Kamalesh Babulal Date: Wed, 12 Apr 2023 14:51:17 +0000 (+0530) Subject: Revert "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=e4a750a3b8e4e139cb9cb6a73458d68f03e92ab6;p=thirdparty%2Flibcgroup.git Revert "api: cgroup v2 – read subtree_control of the leaf node" This reverts commit 39012eeefa454e09fc4192cacddb508ee00abee6. As per the no internal process constraint, of cgroup v2 no controller should be enabled in the leaf cgroup node. This patch breaks this constraint by assuming the controllers are enabled until the leaf node of the hierarchy. Let's revert to the original approach of reading until the parent of the leaf cgroup node. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit 59dff6c981b79ab5e92179e187fc065c53aef54f) --- diff --git a/src/api.c b/src/api.c index 8a2ccd3c..717678bf 100644 --- a/src/api.c +++ b/src/api.c @@ -1924,6 +1924,7 @@ 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; @@ -1949,13 +1950,24 @@ STATIC int cgroupv2_controller_enabled(const char * const cg_name, const char * if (!cg_build_path(cg_name, path, ctrl_name)) goto err; - error = cgroupv2_get_subtree_control(path, ctrl_name, &enabled); + parent = strdup(path); + if (!parent) { + error = ECGOTHER; + goto err; + } + + dname = dirname(parent); + + error = cgroupv2_get_subtree_control(dname, ctrl_name, &enabled); if (error) goto err; if (enabled) error = 0; err: + if (parent) + free(parent); + return error; }