From a8156588fa1bc2e0f954ff2ecca562b308c3383c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 30 Aug 2025 08:38:59 +0900 Subject: [PATCH] cgroup-util: drop 'controller' argument from cg_get_path() The argument is not used anymore. Let's drop it. --- src/basic/cgroup-util.c | 41 ++++++++++++++++------------------ src/basic/cgroup-util.h | 2 +- src/basic/process-util.c | 2 +- src/cgtop/cgtop.c | 6 ++--- src/core/bpf-devices.c | 2 +- src/core/bpf-firewall.c | 2 +- src/core/bpf-foreign.c | 2 +- src/core/bpf-restrict-ifaces.c | 2 +- src/core/bpf-socket-bind.c | 2 +- src/core/cgroup.c | 10 ++++----- src/core/exec-invoke.c | 4 ++-- src/machine/machine.c | 2 +- src/nspawn/nspawn-cgroup.c | 2 +- src/oom/oomd-util.c | 4 ++-- src/shared/cgroup-setup.c | 12 +++++----- src/shared/cgroup-show.c | 2 +- src/shared/condition.c | 2 +- src/test/test-bpf-devices.c | 2 +- src/test/test-cgroup-setup.c | 2 +- 19 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index b01b7b6a3fb..2dfc9188fe0 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -67,7 +67,7 @@ int cg_path_open(const char *path) { _cleanup_free_ char *fs = NULL; int r; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, /* suffix= */ NULL, &fs); + r = cg_get_path(path, /* suffix= */ NULL, &fs); if (r < 0) return r; @@ -137,7 +137,7 @@ int cg_enumerate_processes(const char *path, FILE **ret) { assert(ret); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs); + r = cg_get_path(path, "cgroup.procs", &fs); if (r < 0) return r; @@ -241,7 +241,7 @@ int cg_enumerate_subgroups(const char *path, DIR **ret) { /* This is not recursive! */ - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -444,7 +444,7 @@ int cg_kill_kernel_sigkill(const char *path) { if (!cg_kill_supported()) return -EOPNOTSUPP; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.kill", &killfile); + r = cg_get_path(path, "cgroup.kill", &killfile); if (r < 0) return r; @@ -455,7 +455,7 @@ int cg_kill_kernel_sigkill(const char *path) { return 0; } -int cg_get_path(const char *controller, const char *path, const char *suffix, char **ret) { +int cg_get_path(const char *path, const char *suffix, char **ret) { char *t; assert(ret); @@ -463,10 +463,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch if (isempty(path)) path = TAKE_PTR(suffix); - if (controller) - t = path_join("/sys/fs/cgroup", path, suffix); - else - t = path_join(path, suffix); + t = path_join("/sys/fs/cgroup", path, suffix); if (!t) return -ENOMEM; @@ -482,7 +479,7 @@ int cg_set_xattr(const char *path, const char *name, const void *value, size_t s assert(name); assert(value || size <= 0); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -496,7 +493,7 @@ int cg_get_xattr(const char *path, const char *name, char **ret, size_t *ret_siz assert(path); assert(name); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -510,7 +507,7 @@ int cg_get_xattr_bool(const char *path, const char *name) { assert(path); assert(name); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -524,7 +521,7 @@ int cg_remove_xattr(const char *path, const char *name) { assert(path); assert(name); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -691,7 +688,7 @@ int cg_split_spec(const char *spec, char **ret_controller, char **ret_path) { } int cg_mangle_path(const char *path, char **ret) { - _cleanup_free_ char *c = NULL, *p = NULL; + _cleanup_free_ char *p = NULL; int r; assert(path); @@ -702,11 +699,11 @@ int cg_mangle_path(const char *path, char **ret) { return path_simplify_alloc(path, ret); /* Otherwise, treat it as cg spec */ - r = cg_split_spec(path, &c, &p); + r = cg_split_spec(path, /* ret_controller = */ NULL, &p); if (r < 0) return r; - return cg_get_path(c ?: SYSTEMD_CGROUP_CONTROLLER, p ?: "/", NULL, ret); + return cg_get_path(p, /* suffix = */ NULL, ret); } int cg_get_root_path(char **ret_path) { @@ -1439,7 +1436,7 @@ int cg_is_threaded(const char *path) { _cleanup_strv_free_ char **v = NULL; int r; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.type", &fs); + r = cg_get_path(path, "cgroup.type", &fs); if (r < 0) return r; @@ -1464,7 +1461,7 @@ int cg_set_attribute(const char *path, const char *attribute, const char *value) assert(attribute); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p); + r = cg_get_path(path, attribute, &p); if (r < 0) return r; @@ -1482,7 +1479,7 @@ int cg_get_attribute(const char *path, const char *attribute, char **ret) { assert(attribute); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p); + r = cg_get_path(path, attribute, &p); if (r < 0) return r; @@ -1535,7 +1532,7 @@ int cg_get_owner(const char *path, uid_t *ret_uid) { assert(ret_uid); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &f); + r = cg_get_path(path, /* suffix = */ NULL, &f); if (r < 0) return r; @@ -1569,7 +1566,7 @@ int cg_get_keyed_attribute( * * If the attribute file doesn't exist at all returns ENOENT, if any key is not found returns ENXIO. */ - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &filename); + r = cg_get_path(path, attribute, &filename); if (r < 0) return r; @@ -1714,7 +1711,7 @@ int cg_mask_supported_subtree(const char *root, CGroupMask *ret) { /* We can read the supported and accessible controllers from the top-level cgroup attribute */ _cleanup_free_ char *controllers = NULL, *path = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path); + r = cg_get_path(root, "cgroup.controllers", &path); if (r < 0) return r; diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 9c534ac594c..b25660c086a 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -164,7 +164,7 @@ int cg_kill_recursive(const char *path, int sig, CGroupFlags flags, Set *killed_ int cg_split_spec(const char *spec, char **ret_controller, char **ret_path); int cg_mangle_path(const char *path, char **ret); -int cg_get_path(const char *controller, const char *path, const char *suffix, char **ret); +int cg_get_path(const char *path, const char *suffix, char **ret); int cg_pid_get_path(pid_t pid, char **ret); int cg_pidref_get_path(const PidRef *pidref, char **ret); diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 900e885bfac..5759de38f4c 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -2146,7 +2146,7 @@ int posix_spawn_wrapper( if (cgroup && have_clone_into_cgroup) { _cleanup_free_ char *resolved_cgroup = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, /* suffix= */ NULL, &resolved_cgroup); + r = cg_get_path(cgroup, /* suffix= */ NULL, &resolved_cgroup); if (r < 0) return r; diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 99f1fe22aef..87806caeba1 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -172,7 +172,7 @@ static int process_memory(Group *g) { else { _cleanup_free_ char *p = NULL, *v = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, g->path, "memory.current", &p); + r = cg_get_path(g->path, "memory.current", &p); if (r < 0) return r; @@ -202,7 +202,7 @@ static int process_io(Group *g, unsigned iteration) { assert(g); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, g->path, "io.stat", &p); + r = cg_get_path(g->path, "io.stat", &p); if (r < 0) return r; @@ -395,7 +395,7 @@ static int process( } else { _cleanup_free_ char *p = NULL, *v = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "pids.current", &p); + r = cg_get_path(path, "pids.current", &p); if (r < 0) return r; diff --git a/src/core/bpf-devices.c b/src/core/bpf-devices.c index ef8ba3d5723..71ffd048986 100644 --- a/src/core/bpf-devices.c +++ b/src/core/bpf-devices.c @@ -236,7 +236,7 @@ int bpf_devices_apply_policy( if (r < 0) return log_error_errno(r, "Extending device control BPF program failed: %m"); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, NULL, &controller_path); + r = cg_get_path(cgroup_path, /* suffix = */ NULL, &controller_path); if (r < 0) return log_error_errno(r, "Failed to determine cgroup path: %m"); diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c index fce885da875..b2a4cd6e27b 100644 --- a/src/core/bpf-firewall.c +++ b/src/core/bpf-firewall.c @@ -696,7 +696,7 @@ int bpf_firewall_install(Unit *u) { return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EOPNOTSUPP), "bpf-firewall: BPF firewalling not supported, proceeding without."); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &path); + r = cg_get_path(crt->cgroup_path, /* suffix = */ NULL, &path); if (r < 0) return log_unit_error_errno(u, r, "bpf-firewall: Failed to determine cgroup path: %m"); diff --git a/src/core/bpf-foreign.c b/src/core/bpf-foreign.c index 2e8c07978ce..1da16a7b8d9 100644 --- a/src/core/bpf-foreign.c +++ b/src/core/bpf-foreign.c @@ -151,7 +151,7 @@ int bpf_foreign_install(Unit *u) { if (!crt) return 0; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_path); + r = cg_get_path(crt->cgroup_path, /* suffix = */ NULL, &cgroup_path); if (r < 0) return log_unit_error_errno(u, r, "bpf-foreign: Failed to get cgroup path: %m"); diff --git a/src/core/bpf-restrict-ifaces.c b/src/core/bpf-restrict-ifaces.c index 0c66ae06308..a0ed94ce3ad 100644 --- a/src/core/bpf-restrict-ifaces.c +++ b/src/core/bpf-restrict-ifaces.c @@ -115,7 +115,7 @@ static int restrict_ifaces_install_impl(Unit *u) { if (!crt) return 0; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_path); + r = cg_get_path(crt->cgroup_path, /* suffix = */ NULL, &cgroup_path); if (r < 0) return log_unit_error_errno(u, r, "restrict-interfaces: Failed to get cgroup path: %m"); diff --git a/src/core/bpf-socket-bind.c b/src/core/bpf-socket-bind.c index 1fc73c19ab7..1cba47306d9 100644 --- a/src/core/bpf-socket-bind.c +++ b/src/core/bpf-socket-bind.c @@ -179,7 +179,7 @@ static int socket_bind_install_impl(Unit *u) { if (!crt) return 0; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_path); + r = cg_get_path(crt->cgroup_path, /* suffix = */ NULL, &cgroup_path); if (r < 0) return log_unit_error_errno(u, r, "bpf-socket-bind: Failed to get cgroup path: %m"); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 6f3e61ea3af..7242734e5ae 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1989,7 +1989,7 @@ static int unit_watch_cgroup(Unit *u) { if (r < 0) return log_oom(); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, "cgroup.events", &events); + r = cg_get_path(crt->cgroup_path, "cgroup.events", &events); if (r < 0) return log_oom(); @@ -2044,7 +2044,7 @@ static int unit_watch_cgroup_memory(Unit *u) { if (r < 0) return log_oom(); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, "memory.events", &events); + r = cg_get_path(crt->cgroup_path, "memory.events", &events); if (r < 0) return log_oom(); @@ -2103,7 +2103,7 @@ static int unit_update_cgroup( CGroupRuntime *crt = ASSERT_PTR(unit_get_cgroup_runtime(u)); uint64_t cgroup_id = 0; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_full_path); + r = cg_get_path(crt->cgroup_path, /* suffix = */ NULL, &cgroup_full_path); if (r == 0) { r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id); if (r < 0) @@ -3769,7 +3769,7 @@ static int unit_get_io_accounting_raw( if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_IO)) return -ENODATA; - r = cg_get_path("io", crt->cgroup_path, "io.stat", &path); + r = cg_get_path(crt->cgroup_path, "io.stat", &path); if (r < 0) return r; @@ -4107,7 +4107,7 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) { assert_not_reached(); } - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, "cgroup.freeze", &path); + r = cg_get_path(crt->cgroup_path, "cgroup.freeze", &path); if (r < 0) return r; diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 88178a82f96..97a71073841 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -5579,7 +5579,7 @@ int exec_invoke( if (is_pressure_supported() > 0) { if (cgroup_context_want_memory_pressure(cgroup_context)) { - r = cg_get_path("memory", params->cgroup_path, "memory.pressure", &memory_pressure_path); + r = cg_get_path(params->cgroup_path, "memory.pressure", &memory_pressure_path); if (r < 0) { *exit_status = EXIT_MEMORY; return log_oom(); @@ -5597,7 +5597,7 @@ int exec_invoke( * memory_pressure_path != NULL in the conditional below. */ if (memory_pressure_path && needs_sandboxing && exec_needs_cgroup_namespace(context)) { memory_pressure_path = mfree(memory_pressure_path); - r = cg_get_path("memory", "/", "memory.pressure", &memory_pressure_path); + r = cg_get_path("/", "memory.pressure", &memory_pressure_path); if (r < 0) { *exit_status = EXIT_MEMORY; return log_oom(); diff --git a/src/machine/machine.c b/src/machine/machine.c index 0eb854f4abd..5cbe076506e 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -616,7 +616,7 @@ static int machine_watch_cgroup(Machine *m) { return 0; _cleanup_free_ char *p = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, m->cgroup, "cgroup.events", &p); + r = cg_get_path(m->cgroup, "cgroup.events", &p); if (r < 0) return log_error_errno(r, "Failed to get cgroup path for cgroup '%s': %m", m->cgroup); diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index caa55186efc..db99b7d8463 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -113,7 +113,7 @@ int create_subcgroup( return log_error_errno(r, "Failed to add cgroup %s to userns: %m", payload); } else { _cleanup_free_ char *fs = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, payload, NULL, &fs); + r = cg_get_path(payload, /* suffix = */ NULL, &fs); if (r < 0) return log_error_errno(r, "Failed to get file system path for container cgroup: %m"); diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index fcd00f8c16b..e463ce01f2c 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -240,7 +240,7 @@ int oomd_cgroup_kill(const char *path, bool recurse, bool dry_run) { if (dry_run) { _cleanup_free_ char *cg_path = NULL; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &cg_path); + r = cg_get_path(path, /* suffix = */ NULL, &cg_path); if (r < 0) return r; @@ -418,7 +418,7 @@ int oomd_cgroup_context_acquire(const char *path, OomdCGroupContext **ret) { is_root = empty_or_root(path); ctx->preference = MANAGED_OOM_PREFERENCE_NONE; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "memory.pressure", &p); + r = cg_get_path(path, "memory.pressure", &p); if (r < 0) return log_debug_errno(r, "Error getting cgroup memory pressure path from %s: %m", path); diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index e0fddd7973c..a3348058710 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -78,7 +78,7 @@ int cg_trim(const char *path, bool delete_root) { _cleanup_free_ char *fs = NULL; int r; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -115,7 +115,7 @@ int cg_create(const char *path) { _cleanup_free_ char *fs = NULL; int r; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -140,7 +140,7 @@ int cg_attach(const char *path, pid_t pid) { assert(path); assert(pid >= 0); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs); + r = cg_get_path(path, "cgroup.procs", &fs); if (r < 0) return r; @@ -216,7 +216,7 @@ int cg_set_access( return 0; /* Configure access to the cgroup itself */ - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -289,7 +289,7 @@ int cg_set_access_recursive( if (!uid_is_valid(uid) && !gid_is_valid(gid)) return 0; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(path, /* suffix = */ NULL, &fs); if (r < 0) return r; @@ -396,7 +396,7 @@ int cg_enable( return 0; } - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, p, "cgroup.subtree_control", &fs); + r = cg_get_path(p, "cgroup.subtree_control", &fs); if (r < 0) return r; diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 6a591d7192a..47ffaf725f2 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -313,7 +313,7 @@ int show_cgroup(const char *path, assert(path); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &p); + r = cg_get_path(path, /* suffix = */ NULL, &p); if (r < 0) return r; diff --git a/src/shared/condition.c b/src/shared/condition.c index a998c049cce..186f0b6c4a0 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -1110,7 +1110,7 @@ static int condition_test_psi(Condition *c, char **env) { free_and_replace(slice_path, slice_joined); } - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, slice_path, controller, &pressure_path); + r = cg_get_path(slice_path, controller, &pressure_path); if (r < 0) return log_debug_errno(r, "Error getting cgroup pressure path from %s: %m", slice_path); diff --git a/src/test/test-bpf-devices.c b/src/test/test-bpf-devices.c index fb8155c45db..78e74876554 100644 --- a/src/test/test-bpf-devices.c +++ b/src/test/test-bpf-devices.c @@ -275,7 +275,7 @@ int main(int argc, char *argv[]) { if (r < 0) return log_tests_skipped_errno(r, "Failed to prepare cgroup subtree"); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, NULL, &controller_path); + r = cg_get_path(cgroup, /* suffix = */ NULL, &controller_path); ASSERT_OK(r); _cleanup_(bpf_program_freep) BPFProgram *prog = NULL; diff --git a/src/test/test-cgroup-setup.c b/src/test/test-cgroup-setup.c index 5c162bbbf3a..ae33e1fcd13 100644 --- a/src/test/test-cgroup-setup.c +++ b/src/test/test-cgroup-setup.c @@ -54,7 +54,7 @@ TEST(cg_create) { ASSERT_TRUE(path_equal(path, test_d)); free(path); - ASSERT_OK_ZERO(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, test_d, NULL, &path)); + ASSERT_OK_ZERO(cg_get_path(test_d, /* suffix = */ NULL, &path)); log_debug("test_d: %s", path); ASSERT_TRUE(path_equal(path, strjoina("/sys/fs/cgroup", test_d))); free(path); -- 2.47.3