From: Frantisek Sumsal Date: Tue, 1 Feb 2022 19:18:29 +0000 (+0100) Subject: test: introduce `get_cgroup_hierarchy() helper X-Git-Tag: v251-rc1~382^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f723740871bd3eb89d16a526a1ff77c04bb3787a;p=thirdparty%2Fsystemd.git test: introduce `get_cgroup_hierarchy() helper which returns the host's cgroup hierarchy (unified, hybrid, or legacy). --- diff --git a/test/test-functions b/test/test-functions index 3ae8caed3fb..d79c52c5911 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2010,6 +2010,24 @@ import_initdir() { export initdir } +get_cgroup_hierarchy() { + case "$(stat -c '%T' -f /sys/fs/cgroup)" in + cgroup2fs) + echo "unified" + ;; + tmpfs) + if [[ -d /sys/fs/cgroup/unified && "$(stat -c '%T' -f /sys/fs/cgroup/unified)" == cgroup2fs ]]; then + echo "hybrid" + else + echo "legacy" + fi + ;; + *) + dfatal "Failed to determine host's cgroup hierarchy" + exit 1 + esac +} + ## @brief Converts numeric logging level to the first letter of level name. # # @param lvl Numeric logging level in range from 1 to 6.