From 606ef91a407ba439fe1d05c3843878dd7e4dc291 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 27 May 2025 14:19:41 +0200 Subject: [PATCH] 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. --- src/basic/cgroup-util.c | 11 ++--------- src/basic/cgroup-util.h | 4 +--- src/oom/oomd-manager.c | 6 ++---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 0c39660a9ae..c70b04650c1 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -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) { diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 6a5f92a1772..7c5e6e65559 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -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); diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index dae7a957e27..51fb5fe9dad 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -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); -- 2.47.3