]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: port some code over to path_startswith_full()
authorLennart Poettering <lennart@poettering.net>
Thu, 22 May 2025 16:35:25 +0000 (18:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 May 2025 04:51:43 +0000 (06:51 +0200)
src/basic/cgroup-util.c
src/core/cgroup.c

index d8e94c3ed9d0bf2826924b4db8c6ab471d04147f..b68cab68a092536f97cc4ef1165302631e691199 100644 (file)
@@ -959,13 +959,12 @@ int cg_get_root_path(char **ret_path) {
 }
 
 int cg_shift_path(const char *cgroup, const char *root, const char **ret_shifted) {
-        _cleanup_free_ char *rt = NULL;
-        char *p;
         int r;
 
         assert(cgroup);
         assert(ret_shifted);
 
+        _cleanup_free_ char *rt = NULL;
         if (!root) {
                 /* If the root was specified let's use that, otherwise
                  * let's determine it from PID 1 */
@@ -977,12 +976,7 @@ int cg_shift_path(const char *cgroup, const char *root, const char **ret_shifted
                 root = rt;
         }
 
-        p = path_startswith(cgroup, root);
-        if (p && p > cgroup)
-                *ret_shifted = p - 1;
-        else
-                *ret_shifted = cgroup;
-
+        *ret_shifted = path_startswith_full(cgroup, root, PATH_STARTSWITH_RETURN_LEADING_SLASH) ?: cgroup;
         return 0;
 }
 
index 61a034641b324b2f3302f16d542ad767ed646dda..e9dade8eb34ef6a0fdd2502c4d8eacd6819bd2f2 100644 (file)
@@ -2808,19 +2808,13 @@ static int unit_prune_cgroup_via_bus(Unit *u) {
                 return -EOWNERDEAD;
 
         /* Determine this unit's cgroup path relative to our cgroup root */
-        const char *pp = path_startswith(crt->cgroup_path, u->manager->cgroup_root);
+        const char *pp = path_startswith_full(
+                        crt->cgroup_path,
+                        u->manager->cgroup_root,
+                        PATH_STARTSWITH_RETURN_LEADING_SLASH);
         if (!pp)
                 return -EINVAL;
 
-        _cleanup_free_ char *absolute = NULL;
-        if (!path_is_absolute(pp)) { /* RemoveSubgroupFromUnit() wants an absolute path */
-                absolute = strjoin("/", pp);
-                if (!absolute)
-                        return -ENOMEM;
-
-                pp = absolute;
-        }
-
         r = bus_call_method(u->manager->system_bus,
                             bus_systemd_mgr,
                             "RemoveSubgroupFromUnit",