core/main: refuse bootup with legacy cgroup hierarchy

First step towards a unified-only future (rework of internals
coming soon (TM))
This commit is contained in:
Mike Yuan
2025-03-16 15:30:39 +01:00
parent 8d538d3fbb
commit 2b61489e5a
3 changed files with 46 additions and 0 deletions
+27
View File
@@ -8,6 +8,7 @@
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "missing_magic.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
@@ -951,3 +952,29 @@ int cg_uninstall_release_agent(const char *controller) {
return 0;
}
int cg_has_legacy(void) {
struct statfs fs;
/* Checks if any legacy controller/hierarchy is mounted. */
if (statfs("/sys/fs/cgroup/", &fs) < 0) {
if (errno == ENOENT) /* sysfs not mounted? */
return false;
return log_error_errno(errno, "Failed to statfs /sys/fs/cgroup/: %m");
}
if (is_fs_type(&fs, CGROUP2_SUPER_MAGIC) ||
is_fs_type(&fs, SYSFS_MAGIC)) /* not mounted yet */
return false;
if (is_fs_type(&fs, TMPFS_MAGIC)) {
log_info("Found tmpfs on /sys/fs/cgroup/, assuming legacy hierarchy.");
return true;
}
return log_error_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
"Unknown filesystem type %llx mounted on /sys/fs/cgroup/.",
(unsigned long long) fs.f_type);
}