]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: cgroup v2 – read subtree_control of the leaf node
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 20 Dec 2022 16:09:08 +0000 (21:39 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 6 Jan 2023 15:07:23 +0000 (08:07 -0700)
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>
src/api.c

index cd0b5e4d019f2be188f833f02e3e7c5bf53c6ea8..5480c7a8fb748ded667a61d1bacbb757eb9c21af 100644 (file)
--- 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;
 }