From c6bc10fa4e62fcc1eb21c9c2d9ba30ea28f13198 Mon Sep 17 00:00:00 2001 From: zhaoxiaohu Date: Wed, 11 Sep 2024 17:02:48 +0800 Subject: [PATCH] cgroup-util: introduce cg_is_threaded() Signed-off-by: zhaoxiaohu --- ...cgroup-util-introduce-cg_is_threaded.patch | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 backport-cgroup-util-introduce-cg_is_threaded.patch diff --git a/backport-cgroup-util-introduce-cg_is_threaded.patch b/backport-cgroup-util-introduce-cg_is_threaded.patch new file mode 100644 index 0000000..8989ae2 --- /dev/null +++ b/backport-cgroup-util-introduce-cg_is_threaded.patch @@ -0,0 +1,65 @@ +From 084e7706c25bf6cf0d6af4cc07fb1bb47e26b25e Mon Sep 17 00:00:00 2001 +From: Yu Watanabe +Date: Sun, 13 Feb 2022 20:39:04 +0900 +Subject: [PATCH] cgroup-util: introduce cg_is_threaded() + +Reference: https://github.com/systemd/systemd/pull/22498/commits/084e7706c25bf6cf0d6af4cc07fb1bb47e26b25e + +Signed-off-by: rpm-build +Signed-off-by: yuwang +--- + src/basic/cgroup-util.c | 24 ++++++++++++++++++++++++ + src/basic/cgroup-util.h | 2 ++ + 2 files changed, 26 insertions(+) + +diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c +index 79089ac..130536c 100644 +--- a/src/basic/cgroup-util.c ++++ b/src/basic/cgroup-util.c +@@ -1642,6 +1642,30 @@ int cg_slice_to_path(const char *unit, char **ret) { + return 0; + } + ++int cg_is_threaded(const char *controller, const char *path) { ++ _cleanup_free_ char *fs = NULL, *contents = NULL; ++ _cleanup_strv_free_ char **v = NULL; ++ int r; ++ ++ r = cg_get_path(controller, path, "cgroup.type", &fs); ++ if (r < 0) ++ return r; ++ ++ r = read_full_virtual_file(fs, &contents, NULL); ++ if (r == -ENOENT) ++ return false; /* Assume no. */ ++ if (r < 0) ++ return r; ++ ++ v = strv_split(contents, NULL); ++ if (!v) ++ return -ENOMEM; ++ ++ /* If the cgroup is in the threaded mode, it contains "threaded". ++ * If one of the parents or siblings is in the threaded mode, it may contain "invalid". */ ++ return strv_contains(v, "threaded") || strv_contains(v, "invalid"); ++} ++ + int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) { + _cleanup_free_ char *p = NULL; + int r; +diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h +index faa253b..baeb8c4 100644 +--- a/src/basic/cgroup-util.h ++++ b/src/basic/cgroup-util.h +@@ -188,6 +188,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path); + + int cg_rmdir(const char *controller, const char *path); + ++int cg_is_threaded(const char *controller, const char *path); ++ + typedef enum { + CG_KEY_MODE_GRACEFUL = 1 << 0, + } CGroupKeyMode; +-- +2.33.0 +