]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: replace cg_get_path_and_check() with cg_get_path()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Aug 2025 21:38:14 +0000 (06:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 17 Nov 2025 12:30:29 +0000 (21:30 +0900)
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().

src/basic/cgroup-util.c
src/basic/cgroup-util.h
src/basic/process-util.c
src/shared/cgroup-setup.c

index a4e7c069b34f05a33a5d85ce56f5593890e266b3..91c230208d30e5cb03fe074630276c6bd7bf645a 100644 (file)
@@ -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;
index 6f36194403dba4e2dc17ad8cf1c7bdae6515d5ed..27fa4cd2d767fe741865e362ed7710a2ce329773 100644 (file)
@@ -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);
index 35d3f8bfd9e1d5c771475aeceee58033e5b43c13..900e885bfaca046aea12d9f61c5d4ab07d4a052e 100644 (file)
@@ -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;
 
index 43962206d2ffbbcb99c53107f3a0f35d9d5d6e95..e0fddd7973cec3ff85b9fcf242a22512ea9e4201 100644 (file)
@@ -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;