]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: replace prefix_roota() with chase()
authorZIHCO <chizobajames21@gmail.com>
Wed, 9 Apr 2025 09:45:42 +0000 (10:45 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 9 Apr 2025 22:36:06 +0000 (00:36 +0200)
src/nspawn/nspawn-cgroup.c

index 09a581a42a27fce1c72ab396be9c0e4217b3c34b..cd5da76af4be2914bc841ac9ae0c601a34b09b59 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "cgroup-setup.h"
+#include "chase.h"
 #include "fd-util.h"
 #include "format-util.h"
 #include "fs-util.h"
@@ -135,21 +136,22 @@ int create_subcgroup(
 }
 
 int mount_cgroups(const char *dest, bool accept_existing) {
-        const char *p;
+        _cleanup_free_ char *p = NULL;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
-        p = prefix_roota(dest, "/sys/fs/cgroup");
-
-        (void) mkdir_p(p, 0755);
+        r = chase("/sys/fs/cgroup", dest, CHASE_PREFIX_ROOT | CHASE_MKDIR_0755, &p, &fd);
+        if (r < 0)
+                return log_error_errno(r, "Failed to chase %s/sys/fs/cgroup: %m", strempty(dest));
 
-        r = path_is_mount_point_full(p, dest, AT_SYMLINK_FOLLOW);
+        r = is_mount_point_at(fd, /* filename = */ NULL, /* flags = */ 0);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine if %s is mounted already: %m", p);
         if (r > 0) {
                 if (!accept_existing)
                         return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Refusing existing cgroupfs mount: %s", p);
 
-                if (access(strjoina(p, "/cgroup.procs"), F_OK) >= 0)
+                if (faccessat(fd, "cgroup.procs", F_OK, /* flags = */ 0) >= 0)
                         return 0;
                 if (errno != ENOENT)
                         return log_error_errno(errno, "Failed to determine if mount point %s contains the unified cgroup hierarchy: %m", p);