mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-28 19:16:14 +01:00
94462a3e8a
Signed-off-by: magic_rb <magic_rb@redalder.org>
93 lines
4.7 KiB
Diff
93 lines
4.7 KiB
Diff
From 77bbb3168c43f1f131193792d6a237284cc37312 Mon Sep 17 00:00:00 2001
|
|
From: magic_rb <richard@brezak.sk>
|
|
Date: Wed, 21 Feb 2024 15:21:45 +0100
|
|
Subject: [PATCH] Add env SYSTEMD_UNIFIED_CGROUP_HIERARCHY
|
|
|
|
Signed-off-by: magic_rb <richard@brezak.sk>
|
|
---
|
|
src/nspawn/nspawn.c | 64 +++++++++++++++++++++++++++++----------------
|
|
1 file changed, 41 insertions(+), 23 deletions(-)
|
|
|
|
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
|
|
index 8ac86eeb55..47b459e423 100644
|
|
--- a/src/nspawn/nspawn.c
|
|
+++ b/src/nspawn/nspawn.c
|
|
@@ -513,33 +513,51 @@ static int detect_unified_cgroup_hierarchy_from_environment(void) {
|
|
|
|
static int detect_unified_cgroup_hierarchy_from_image(const char *directory) {
|
|
int r;
|
|
+ const char* e;
|
|
+ int hierarchy_override = 0;
|
|
|
|
- /* Let's inherit the mode to use from the host system, but let's take into consideration what systemd
|
|
- * in the image actually supports. */
|
|
- r = cg_all_unified();
|
|
- if (r < 0)
|
|
- return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
|
|
- if (r > 0) {
|
|
- /* Unified cgroup hierarchy support was added in 230. Unfortunately the detection
|
|
- * routine only detects 231, so we'll have a false negative here for 230. */
|
|
- r = systemd_installation_has_version(directory, "230");
|
|
- if (r < 0)
|
|
- return log_error_errno(r, "Failed to determine systemd version in container: %m");
|
|
- if (r > 0)
|
|
- arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
|
|
- else
|
|
+ e = getenv("SYSTEMD_UNIFIED_CGROUP_HIERARCHY");
|
|
+ if (e) {
|
|
+ if (strcmp(e, "legacy") == 0) {
|
|
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
|
|
- } else if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) {
|
|
- /* Mixed cgroup hierarchy support was added in 233 */
|
|
- r = systemd_installation_has_version(directory, "233");
|
|
- if (r < 0)
|
|
- return log_error_errno(r, "Failed to determine systemd version in container: %m");
|
|
- if (r > 0)
|
|
+ hierarchy_override = 1;
|
|
+ } else if (strcmp(e, "hydrid") == 0) {
|
|
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD;
|
|
- else
|
|
+ hierarchy_override = 1;
|
|
+ } else if (strcmp(e, "unified") == 0) {
|
|
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
|
|
+ hierarchy_override = 1;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (!hierarchy_override) {
|
|
+ /* Let's inherit the mode to use from the host system, but let's take into consideration what systemd
|
|
+ * in the image actually supports. */
|
|
+ r = cg_all_unified();
|
|
+ if (r < 0)
|
|
+ return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
|
|
+ if (r > 0) {
|
|
+ /* Unified cgroup hierarchy support was added in 230. Unfortunately the detection
|
|
+ * routine only detects 231, so we'll have a false negative here for 230. */
|
|
+ r = systemd_installation_has_version(directory, "230");
|
|
+ if (r < 0)
|
|
+ return log_error_errno(r, "Failed to determine systemd version in container: %m");
|
|
+ if (r > 0)
|
|
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
|
|
+ else
|
|
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
|
|
+ } else if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) {
|
|
+ /* Mixed cgroup hierarchy support was added in 233 */
|
|
+ r = systemd_installation_has_version(directory, "233");
|
|
+ if (r < 0)
|
|
+ return log_error_errno(r, "Failed to determine systemd version in container: %m");
|
|
+ if (r > 0)
|
|
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD;
|
|
+ else
|
|
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
|
|
+ } else
|
|
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
|
|
- } else
|
|
- arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
|
|
+ }
|
|
|
|
log_debug("Using %s hierarchy for container.",
|
|
arg_unified_cgroup_hierarchy == CGROUP_UNIFIED_NONE ? "legacy" :
|
|
--
|
|
2.43.0
|
|
|