]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: make cg_get_attribute_as_bool() return 0/1 directly
authorMike Yuan <me@yhndnzj.com>
Tue, 27 May 2025 12:19:41 +0000 (14:19 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 27 May 2025 12:28:08 +0000 (14:28 +0200)
As with getenv_bool() and getxattr_at_bool(), to match
our usual style.

src/basic/cgroup-util.c
src/basic/cgroup-util.h
src/oom/oomd-manager.c

index 0c39660a9ae188ed90a19ca94afc4fcba07695dd..c70b04650c12981453498df977671fefdad59dbd 100644 (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) {
index 6a5f92a177293d258a240b5ba386d011a8c09338..7c5e6e65559f33f05c520c206b8ea5d5055946ad 100644 (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);
 
index dae7a957e27335f3b8a7a7cca910a960899e0334..51fb5fe9dad5a0be8f32e4384448410ec4ece9c6 100644 (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);