#include "alloc-util.h"
#include "cgroup-setup.h"
+#include "chase.h"
#include "fd-util.h"
#include "format-util.h"
#include "fs-util.h"
}
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);