From f4f3efa4d7076a943598cce85f9b108427c65f87 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 25 Feb 2024 09:03:16 +0800 Subject: [PATCH] shared/cgroup-setup: introduce cg_is_legacy_force_enabled --- src/shared/cgroup-setup.c | 16 ++++++++++++++++ src/shared/cgroup-setup.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 934a16eaf38..ab76ee51027 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -154,6 +154,22 @@ bool cg_is_hybrid_wanted(void) { return (wanted = r > 0 ? !b : is_default); } +bool cg_is_legacy_force_enabled(void) { + bool force; + + if (!cg_is_legacy_wanted()) + return false; + + /* If in container, we have to follow host's cgroup hierarchy. */ + if (detect_container() > 0) + return true; + + if (proc_cmdline_get_bool("SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE", /* flags = */ 0, &force) < 0) + return false; + + return force; +} + int cg_weight_parse(const char *s, uint64_t *ret) { uint64_t u; int r; diff --git a/src/shared/cgroup-setup.h b/src/shared/cgroup-setup.h index 1b6f0716c63..c35884ee4d6 100644 --- a/src/shared/cgroup-setup.h +++ b/src/shared/cgroup-setup.h @@ -10,6 +10,7 @@ bool cg_is_unified_wanted(void); bool cg_is_legacy_wanted(void); bool cg_is_hybrid_wanted(void); +bool cg_is_legacy_force_enabled(void); int cg_weight_parse(const char *s, uint64_t *ret); int cg_cpu_weight_parse(const char *s, uint64_t *ret); -- 2.47.3