cgroup-util: drop 'controller' argument from cg_set_attribute(), cg_get_attribute() and friends

Non-null controller arguments are always ignored when running on cgroup v2.
Let's drop the argument.

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2025-11-17 21:30:29 +09:00
parent 4d1badbbc4
commit 4dbf06bd85
7 changed files with 31 additions and 31 deletions
+8 -8
View File
@@ -1623,13 +1623,13 @@ int cg_is_threaded(const char *path) {
return strv_contains(v, "threaded") || strv_contains(v, "invalid");
}
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
int cg_set_attribute(const char *path, const char *attribute, const char *value) {
_cleanup_free_ char *p = NULL;
int r;
assert(attribute);
r = cg_get_path(controller, path, attribute, &p);
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p);
if (r < 0)
return r;
@@ -1641,27 +1641,27 @@ int cg_set_attribute(const char *controller, const char *path, const char *attri
return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER|WRITE_STRING_FILE_OPEN_NONBLOCKING);
}
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) {
int cg_get_attribute(const char *path, const char *attribute, char **ret) {
_cleanup_free_ char *p = NULL;
int r;
assert(attribute);
r = cg_get_path(controller, path, attribute, &p);
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p);
if (r < 0)
return r;
return read_one_line_file(p, ret);
}
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret) {
int cg_get_attribute_as_uint64(const char *path, const char *attribute, uint64_t *ret) {
_cleanup_free_ char *value = NULL;
uint64_t v;
int r;
assert(ret);
r = cg_get_attribute(controller, path, attribute, &value);
r = cg_get_attribute(path, attribute, &value);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
@@ -1680,11 +1680,11 @@ 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) {
int cg_get_attribute_as_bool(const char *path, const char *attribute) {
_cleanup_free_ char *value = NULL;
int r;
r = cg_get_attribute(controller, path, attribute, &value);
r = cg_get_attribute(path, attribute, &value);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
+5 -5
View File
@@ -184,12 +184,12 @@ int cg_is_delegated_fd(int fd);
int cg_has_coredump_receive(const char *path);
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret);
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char * const *keys, char **values);
int cg_set_attribute(const char *path, const char *attribute, const char *value);
int cg_get_attribute(const char *path, const char *attribute, char **ret);
int cg_get_attribute_as_uint64(const char *path, const char *attribute, uint64_t *ret);
int cg_get_attribute_as_bool(const char *path, const char *attribute);
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret);
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute);
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char * const *keys, char **values);
int cg_get_owner(const char *path, uid_t *ret_uid);
+3 -3
View File
@@ -42,7 +42,7 @@ uint64_t physical_memory(void) {
return mem;
}
if (r > 0) {
r = cg_get_attribute("memory", root, "memory.max", &value);
r = cg_get_attribute(root, "memory.max", &value);
if (r == -ENOENT) /* Field does not exist on the system's top-level cgroup, hence don't
* complain. (Note that it might exist on our own root though, if we live
* in a cgroup namespace, hence check anyway instead of not even
@@ -56,7 +56,7 @@ uint64_t physical_memory(void) {
if (streq(value, "max"))
return mem;
} else {
r = cg_get_attribute("memory", root, "memory.limit_in_bytes", &value);
r = cg_get_attribute(root, "memory.limit_in_bytes", &value);
if (r < 0) {
log_debug_errno(r, "Failed to read memory.limit_in_bytes cgroup attribute, ignoring cgroup memory limit: %m");
return mem;
@@ -159,7 +159,7 @@ uint64_t system_tasks_max(void) {
/* We'll have the "pids.max" attribute on the our root cgroup only if we are in a
* CLONE_NEWCGROUP namespace. On the top-level namespace this attribute is missing, hence
* suppress any message about that */
r = cg_get_attribute_as_uint64("pids", root, "pids.max", &c);
r = cg_get_attribute_as_uint64(root, "pids.max", &c);
if (r < 0 && r != -ENODATA)
log_debug_errno(r, "Failed to read pids.max attribute of root cgroup, ignoring: %m");
}