]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: introduce get_cgroup_hierarchy()
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 16 May 2023 17:11:51 +0000 (19:11 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 16 May 2023 20:43:52 +0000 (22:43 +0200)
test/units/util.sh

index 00b8c5e39309084f719b09d23cc873a09d9bf227..4e214251cc69179eca2328cba734123962e403fa 100755 (executable)
@@ -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
+}