From: Kamalesh Babulal Date: Thu, 26 Sep 2024 10:45:09 +0000 (+0530) Subject: api: Add is_tid parameter to cgroup_get_cg_type() X-Git-Tag: v3.2.0~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=618872fd735fe9b6ab68085728517f18b749e6dc;p=thirdparty%2Flibcgroup.git api: Add is_tid parameter to cgroup_get_cg_type() Add new parameter bool is_tid to cgroup_get_cg_type(), this parameter gets set, when called from cgroup_attach_thread_tid() path. When set and cgroup.type is 'domain threaded', it returns 'cgroup.threads' instead of 'cgroup.procs'. Fixes: https://github.com/libcgroup/libcgroup/issues/441 Reported-by: Adriaan Schmidt Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 47b5b9a5..49ee1501 100644 --- a/src/api.c +++ b/src/api.c @@ -1829,7 +1829,7 @@ char *cg_build_path(const char *name, char *path, const char *type) } static int cgroup_get_cg_type(const char * const path, char * const type, - size_t type_sz) + size_t type_sz, bool is_tid) { char cg_type_path[FILENAME_MAX]; char cg_type[CGV2_CONTROLLERS_LL_MAX]; @@ -1858,17 +1858,24 @@ static int cgroup_get_cg_type(const char * const path, char * const type, len = strlen(cg_type) - 1; /* - * Append cgroup.threads to the path, if the cgroup.type is threaded - * and cgroup.procs for type domain, domain threaded. domain type is - * used for regular cgroup and domain threaded for root of threaded - * cgroup v2 subtree. Another possible type is domain invalid, it's - * an invalid state, under the threaded subtree. + * Append cgroup.threads to the path, if the cgroup.type is 'threaded' + * or 'domain threaded', with is_tid set. For cgroup.type 'domain' or + * 'domain invalid' or 'domain threaded', with is_tid is unset, append + * cgroup.procs to the path. + * + * domain type is used for regular cgroup and domain threaded for root + * of threaded cgroup v2 subtree. Another possible type is domain invalid, + * it's an invalid state, under the threaded subtree. is_tid is set when + * called from cgroup_attach_thread_tid() or unset other wise. + * Refer to Kernel's cgroup v2 documentation for more detailed explanation + * on domains types. */ - if (strncmp(cg_type, "domain", len) == 0 || - strncmp(cg_type, "domain threaded", len) == 0 || - strncmp(cg_type, "domain invalid", len) == 0) { + if (strncmp(cg_type, "domain", len) == 0 || + strncmp(cg_type, "domain invalid", len) == 0 || + (!is_tid && strncmp(cg_type, "domain threaded", len) == 0)) { snprintf(type, type_sz, "cgroup.procs"); - } else if (strncmp(cg_type, "threaded", len) == 0) { + } else if (strncmp(cg_type, "threaded", len) == 0 || + (is_tid && strncmp(cg_type, "domain threaded", len) == 0)) { snprintf(type, type_sz, "cgroup.threads"); } else { cgroup_warn("invalid %scgroup.type: %s\n", path, cg_type); @@ -1902,7 +1909,7 @@ int cgroup_build_tasks_procs_path(char * const path, size_t path_sz, const char err = 0; break; case CGROUP_V2: - err = cgroup_get_cg_type(path, cg_type, sizeof(cg_type)); + err = cgroup_get_cg_type(path, cg_type, sizeof(cg_type), 0); if (err) goto error;