cgroup-util: make cg_get_attribute_as_bool() return 0/1 directly

As with getenv_bool() and getxattr_at_bool(), to match
our usual style.
This commit is contained in:
Mike Yuan
2025-05-27 14:28:08 +02:00
parent 7b4022bdb0
commit 606ef91a40
3 changed files with 5 additions and 16 deletions
+2 -9
View File
@@ -1638,24 +1638,17 @@ int cg_get_attribute_as_uint64(const char *controller, const char *path, const c
return 0;
}
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute, bool *ret) {
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute) {
_cleanup_free_ char *value = NULL;
int r;
assert(ret);
r = cg_get_attribute(controller, path, attribute, &value);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
r = parse_boolean(value);
if (r < 0)
return r;
*ret = r;
return 0;
return parse_boolean(value);
}
int cg_get_owner(const char *path, uid_t *ret_uid) {
+1 -3
View File
@@ -219,9 +219,7 @@ int cg_get_attribute(const char *controller, const char *path, const char *attri
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char * const *keys, char **values);
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret);
/* Does a parse_boolean() on the attribute contents and sets ret accordingly */
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute, bool *ret);
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute);
int cg_get_owner(const char *path, uid_t *ret_uid);
+2 -4
View File
@@ -228,7 +228,6 @@ static int recursively_get_cgroup_context(Hashmap *new_h, const char *path) {
do {
_cleanup_free_ char *cg_path = NULL;
bool oom_group;
cg_path = path_join(empty_to_root(path), subpath);
if (!cg_path)
@@ -236,7 +235,7 @@ static int recursively_get_cgroup_context(Hashmap *new_h, const char *path) {
subpath = mfree(subpath);
r = cg_get_attribute_as_bool("memory", cg_path, "memory.oom.group", &oom_group);
r = cg_get_attribute_as_bool("memory", cg_path, "memory.oom.group");
/* The cgroup might be gone. Skip it as a candidate since we can't get information on it. */
if (r == -ENOMEM)
return r;
@@ -244,8 +243,7 @@ static int recursively_get_cgroup_context(Hashmap *new_h, const char *path) {
log_debug_errno(r, "Failed to read memory.oom.group from %s, ignoring: %m", cg_path);
return 0;
}
if (oom_group)
if (r > 0)
r = oomd_insert_cgroup_context(NULL, new_h, cg_path);
else
r = recursively_get_cgroup_context(new_h, cg_path);