From 48f3ceb7b4329e311b3682679826486e5a3e152e Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 27 Sep 2024 12:15:09 +0530 Subject: [PATCH] api.c: add support to build procs path for cgroup.thread 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 Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/api.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/api.c b/src/api.c index 49ee1501..e3644ffc 100644 --- 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; -- 2.47.3