From: Yu Watanabe Date: Fri, 29 Aug 2025 21:38:14 +0000 (+0900) Subject: tree-wide: replace cg_get_path_and_check() with cg_get_path() X-Git-Tag: v259-rc1~18^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ab90015e06d299afaff5474fb71c61f5f150bf6;p=thirdparty%2Fsystemd.git tree-wide: replace cg_get_path_and_check() with cg_get_path() We have dropped cgroup v1 support in v258. When running on cgroup v2, cg_get_path_and_check() with SYSTEMD_CGROUP_CONTROLLER as controller is equivalent with checking if we are running on cgroup v2 and then cg_get_path(). As we can assume we are running on cgroup v2, then the check is not necessary anymore, thus we can replace cg_get_path_and_check() with cg_get_path(). --- diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index a4e7c069b34..91c230208d3 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -575,33 +575,6 @@ static int controller_is_v1_accessible(const char *root, const char *controller) return access_nofollow(cpath, root ? W_OK : F_OK); } -int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **ret) { - int r; - - assert(controller); - assert(ret); - - if (!cg_controller_is_valid(controller)) - return -EINVAL; - - r = cg_all_unified(); - if (r < 0) - return r; - if (r > 0) { - /* In the unified hierarchy all controllers are considered accessible, - * except for the named hierarchies */ - if (startswith(controller, "name=")) - return -EOPNOTSUPP; - } else { - /* Check if the specified controller is actually accessible */ - r = controller_is_v1_accessible(NULL, controller); - if (r < 0) - return r; - } - - return cg_get_path(controller, path, suffix, ret); -} - int cg_set_xattr(const char *path, const char *name, const void *value, size_t size, int flags) { _cleanup_free_ char *fs = NULL; int r; diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 6f36194403d..27fa4cd2d76 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -172,7 +172,6 @@ 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_and_check(const char *controller, 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 35d3f8bfd9e..900e885bfac 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -2146,11 +2146,7 @@ int posix_spawn_wrapper( if (cgroup && have_clone_into_cgroup) { _cleanup_free_ char *resolved_cgroup = NULL; - r = cg_get_path_and_check( - SYSTEMD_CGROUP_CONTROLLER, - cgroup, - /* suffix= */ NULL, - &resolved_cgroup); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, /* suffix= */ NULL, &resolved_cgroup); if (r < 0) return r; diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 43962206d2f..e0fddd7973c 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -115,7 +115,7 @@ int cg_create(const char *path) { _cleanup_free_ char *fs = NULL; int r; - r = cg_get_path_and_check(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, 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_and_check(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs); if (r < 0) return r;