Skip to content

Commit b41dcc5

Browse files
committed
cgroup-util: add cg_get_attribute_as_bool() helper
1 parent 61ff739 commit b41dcc5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/basic/cgroup-util.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,26 @@ int cg_get_attribute_as_uint64(const char *controller, const char *path, const c
16851685
return 0;
16861686
}
16871687

1688+
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute, bool *ret) {
1689+
_cleanup_free_ char *value = NULL;
1690+
int r;
1691+
1692+
assert(ret);
1693+
1694+
r = cg_get_attribute(controller, path, attribute, &value);
1695+
if (r == -ENOENT)
1696+
return -ENODATA;
1697+
if (r < 0)
1698+
return r;
1699+
1700+
r = parse_boolean(value);
1701+
if (r < 0)
1702+
return r;
1703+
1704+
*ret = r;
1705+
return 0;
1706+
}
1707+
16881708
int cg_get_keyed_attribute_full(
16891709
const char *controller,
16901710
const char *path,

src/basic/cgroup-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ static inline int cg_get_keyed_attribute_graceful(
208208

209209
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret);
210210

211+
/* Does a parse_boolean() on the attribute contents and sets ret accordingly */
212+
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute, bool *ret);
213+
211214
int cg_set_access(const char *controller, const char *path, uid_t uid, gid_t gid);
212215

213216
int cg_set_xattr(const char *controller, const char *path, const char *name, const void *value, size_t size, int flags);

0 commit comments

Comments
 (0)