From 1ab010cbadd8bfaff20204bc08a42cf1e09c7874 Mon Sep 17 00:00:00 2001 From: ZIHCO Date: Wed, 9 Apr 2025 10:45:42 +0100 Subject: [PATCH] nspawn: replace prefix_roota() with chase() --- src/nspawn/nspawn-cgroup.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index 09a581a42a2..cd5da76af4b 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -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); -- 2.47.3