From: Mike Yuan Date: Sun, 25 Feb 2024 01:03:16 +0000 (+0800) Subject: shared/cgroup-setup: introduce cg_is_legacy_force_enabled X-Git-Tag: v256-rc1~720^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4f3efa4d7076a943598cce85f9b108427c65f87;p=thirdparty%2Fsystemd.git shared/cgroup-setup: introduce cg_is_legacy_force_enabled --- 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);