summaryrefslogtreecommitdiff
path: root/src/basic/cgroup-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-13 20:39:04 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-16 15:55:32 +0900
commit084e7706c25bf6cf0d6af4cc07fb1bb47e26b25e (patch)
tree6342559bdf40b149a28af634e9b3fd18f34d04f9 /src/basic/cgroup-util.c
parentbf6ef6b6a9156e5f52ee69ce0c529a246f103e54 (diff)
downloadsystemd-084e7706c25bf6cf0d6af4cc07fb1bb47e26b25e.tar.gz
cgroup-util: introduce cg_is_threaded()
Diffstat (limited to 'src/basic/cgroup-util.c')
-rw-r--r--src/basic/cgroup-util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 289e4fe073..95bf177a6b 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -1688,6 +1688,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;