cgroup-util: add cg_get_keyed_attribute_uint64() helper
Multiple callers of cg_get_keyed_attribute() follow the same pattern of reading a single keyed attribute and then parsing it as uint64_t with safe_atou64(). Add a helper that combines both steps. Convert all existing single-key + uint64 call sites in cgtop, cgroup.c, and oomd-util.c to use the new helper.
This commit is contained in:
@@ -1560,6 +1560,24 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
int cg_get_keyed_attribute_uint64(const char *path, const char *attribute, const char *key, uint64_t *ret) {
|
||||
_cleanup_free_ char *val = NULL;
|
||||
int r;
|
||||
|
||||
assert(key);
|
||||
assert(ret);
|
||||
|
||||
r = cg_get_keyed_attribute(path, attribute, STRV_MAKE(key), &val);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = safe_atou64(val, ret);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to parse value '%s' of key '%s' in cgroup attribute '%s': %m", val, key, attribute);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cg_mask_to_string(CGroupMask mask, char **ret) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
bool space = false;
|
||||
|
||||
@@ -165,6 +165,7 @@ int cg_get_attribute_as_uint64(const char *path, const char *attribute, uint64_t
|
||||
int cg_get_attribute_as_bool(const char *path, const char *attribute);
|
||||
|
||||
int cg_get_keyed_attribute(const char *path, const char *attribute, char * const *keys, char **values);
|
||||
int cg_get_keyed_attribute_uint64(const char *path, const char *attribute, const char *key, uint64_t *ret);
|
||||
|
||||
int cg_get_owner(const char *path, uid_t *ret_uid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user