summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-05-16 19:11:51 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-05-16 22:43:52 +0200
commit5ff1c6fcde1699637eb328c069ecc693688b4639 (patch)
treed609bea2236b85e036086869532e061b7fe805e9
parentcb153b4fe9046590eb8efba66b67a0db899cb96d (diff)
downloadsystemd-5ff1c6fcde1699637eb328c069ecc693688b4639.tar.gz
test: introduce get_cgroup_hierarchy()
-rwxr-xr-xtest/units/util.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/units/util.sh b/test/units/util.sh
index 00b8c5e393..4e214251cc 100755
--- a/test/units/util.sh
+++ b/test/units/util.sh
@@ -56,3 +56,21 @@ assert_rc() {(
rc=$?
assert_eq "$rc" "$exp"
)}
+
+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
+ ;;
+ *)
+ echo >&2 "Failed to determine host's cgroup hierarchy"
+ exit 1
+ esac
+}