]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: add support to build procs path for cgroup.thread
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 27 Sep 2024 06:45:09 +0000 (12:15 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 7 Oct 2024 20:55:37 +0000 (14:55 -0600)
In cgroup_build_tid_path(), add support for building path to write
tid into cgroup.thread instead of cgroup.procs, if the calling function
is cgroup_attach_thread_tid() or else build path to write into
cgroup.procs.

Fixes: https://github.com/libcgroup/libcgroup/issues/441
Reported-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 49ee1501c9e42616bae6a157e42990ab0a7d0b94..e3644ffc760dbe150d869f58ad80c54f5de35044 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2021,6 +2021,7 @@ err:
 
 static int cgroup_build_tid_path(const char * const ctrl_name, char *path)
 {
+       char cg_type[CGV2_CONTROLLERS_LL_MAX];
        enum cg_version_t version;
        size_t len;
        int ret;
@@ -2029,6 +2030,25 @@ static int cgroup_build_tid_path(const char * const ctrl_name, char *path)
        if (ret)
                return ret;
 
+       if (version == CGROUP_V2) {
+
+               len = strlen(path) - 12;
+               if (strncmp(path + len, "cgroup.procs", 12) != 0) {
+                       ret = ECGOTHER;
+                       return ret;
+               }
+
+               /* right trim cgroup.procs file name in the path */
+               path[len] = '\0';
+
+               ret = cgroup_get_cg_type(path, cg_type, sizeof(cg_type), 1);
+               if (ret)
+                       return ret;
+
+               strncat(path, cg_type, FILENAME_MAX - (len + 1));
+               path[FILENAME_MAX - 1] = '\0';
+       }
+
        if (version != CGROUP_V1)
                return ret;