]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: introduce cg_is_threaded()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Feb 2022 11:39:04 +0000 (20:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 16 Feb 2022 06:55:32 +0000 (15:55 +0900)
src/basic/cgroup-util.c
src/basic/cgroup-util.h

index 289e4fe073a9d31cbb393cb5ec86ed4027e6a2d3..95bf177a6bd2656a781e638dc51bb371dc651b20 100644 (file)
@@ -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;
index 461c01b3c209080c2b112a038453e82964a975b2..4c413a8d174cc50ed96bb5a04c9c9ff8ec8793d3 100644 (file)
@@ -205,6 +205,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;