Skip to content

Commit 084e770

Browse files
committed
cgroup-util: introduce cg_is_threaded()
1 parent bf6ef6b commit 084e770

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/basic/cgroup-util.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,30 @@ int cg_slice_to_path(const char *unit, char **ret) {
16881688
return 0;
16891689
}
16901690

1691+
int cg_is_threaded(const char *controller, const char *path) {
1692+
_cleanup_free_ char *fs = NULL, *contents = NULL;
1693+
_cleanup_strv_free_ char **v = NULL;
1694+
int r;
1695+
1696+
r = cg_get_path(controller, path, "cgroup.type", &fs);
1697+
if (r < 0)
1698+
return r;
1699+
1700+
r = read_full_virtual_file(fs, &contents, NULL);
1701+
if (r == -ENOENT)
1702+
return false; /* Assume no. */
1703+
if (r < 0)
1704+
return r;
1705+
1706+
v = strv_split(contents, NULL);
1707+
if (!v)
1708+
return -ENOMEM;
1709+
1710+
/* If the cgroup is in the threaded mode, it contains "threaded".
1711+
* If one of the parents or siblings is in the threaded mode, it may contain "invalid". */
1712+
return strv_contains(v, "threaded") || strv_contains(v, "invalid");
1713+
}
1714+
16911715
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
16921716
_cleanup_free_ char *p = NULL;
16931717
int r;

src/basic/cgroup-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path);
205205

206206
int cg_rmdir(const char *controller, const char *path);
207207

208+
int cg_is_threaded(const char *controller, const char *path);
209+
208210
typedef enum {
209211
CG_KEY_MODE_GRACEFUL = 1 << 0,
210212
} CGroupKeyMode;

0 commit comments

Comments
 (0)