return 0;
}
-int mount_cgroups(const char *dest) {
+int mount_cgroups(const char *dest, bool accept_existing) {
const char *p;
int r;
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)
return 0;
if (errno != ENOENT)
int userns_fd,
UserNamespaceMode userns_mode);
-int mount_cgroups(const char *dest);
+int mount_cgroups(const char *dest, bool accept_existing);
int bind_mount_cgroup_hierarchy(void);
if (r < 0)
return log_error_errno(errno, "Failed to unshare cgroup namespace: %m");
- r = mount_cgroups(/* dest = */ NULL);
+ r = mount_cgroups(/* dest = */ NULL, /* accept_existing = */ false);
} else
r = bind_mount_cgroup_hierarchy();
if (r < 0)
(void) write_string_filef(p, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MODE_0444, SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(arg_uuid));
if (!arg_use_cgns) {
- r = mount_cgroups(directory);
+ r = mount_cgroups(directory, /* accept_existing = */ true);
if (r < 0)
return r;
}