]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: refuse cgroupv1 unless SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE
authorMike Yuan <me@yhndnzj.com>
Sun, 25 Feb 2024 01:10:51 +0000 (09:10 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 27 Feb 2024 15:10:49 +0000 (23:10 +0800)
Also, add a 30s sleep even if cgroup v1 is forced.

Closes #30852

src/core/main.c
src/shared/mount-setup.c

index 20937e565f401d3c051f2fd6d98409bff56ae619..be6d07b333ca429259ad3dd210891930dd49913d 100644 (file)
@@ -3017,11 +3017,21 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (!skip_setup) {
+                        /* Before we actually start deleting cgroup v1 code, make it harder to boot
+                         * in cgroupv1 mode first. See also #30852. */
+
                         r = mount_cgroup_legacy_controllers(loaded_policy);
                         if (r < 0) {
-                                error_message = "Failed to mount cgroup v1 hierarchy";
+                                if (r == -ERFKILL)
+                                        error_message = "Refusing to run under cgroup v1, SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE=1 not specified on kernel command line";
+                                else
+                                        error_message = "Failed to mount cgroup v1 hierarchy";
                                 goto finish;
                         }
+                        if (r > 0) {
+                                log_full(LOG_CRIT, "Legacy cgroup v1 support selected. This is no longer supported. Will proceed anyway after 30s.");
+                                (void) usleep_safe(30 * USEC_PER_SEC);
+                        }
                 }
 
                 /* The efivarfs is now mounted, let's lock down the system token. */
index 03690518c038f02184850e8d87e4aa8586fec18b..3c0132fd08653bbf60ad50c7c0463c539677159e 100644 (file)
@@ -518,6 +518,9 @@ int mount_cgroup_legacy_controllers(bool loaded_policy) {
         if (!cg_is_legacy_wanted())
                 return 0;
 
+        if (!cg_is_legacy_force_enabled())
+                return -ERFKILL;
+
         FOREACH_ARRAY(mp, cgroupv1_mount_table, ELEMENTSOF(cgroupv1_mount_table)) {
                 r = mount_one(mp, loaded_policy);
                 if (r < 0)