From e4a750a3b8e4e139cb9cb6a73458d68f03e92ab6 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 12 Apr 2023 20:21:17 +0530 Subject: [PATCH] =?utf8?q?Revert=20"api:=20cgroup=20v2=20=E2=80=93=20read?= =?utf8?q?=20subtree=5Fcontrol=20of=20the=20leaf=20node"?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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) --- src/api.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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; } -- 2.47.2