log_execution_mode(&first_boot);
+ r = cg_has_legacy();
+ if (r < 0) {
+ error_message = "Failed to check cgroup hierarchy";
+ goto finish;
+ }
+ if (r > 0) {
+ r = log_full_errno(LOG_EMERG, SYNTHETIC_ERRNO(EPROTO),
+ "Detected cgroup v1 hierarchy at /sys/fs/cgroup/, which is no longer supported by current version of systemd.\n"
+ "Please instruct your initrd to mount cgroup v2 (unified) hierarchy,\n"
+ "possibly by removing any stale kernel command line options, such as:\n"
+ " systemd.legacy_systemd_cgroup_controller=1\n"
+ " systemd.unified_cgroup_hierarchy=0");
+
+ error_message = "Detected unsupported legacy cgroup hierarchy, refusing execution";
+ goto finish;
+ }
+
r = initialize_runtime(skip_setup,
first_boot,
&saved_rlimit_nofile,
#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"
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);
+}
int cg_install_release_agent(const char *controller, const char *agent);
int cg_uninstall_release_agent(const char *controller);
+
+int cg_has_legacy(void);