naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
aa0848
From 16908e1ec833d857cb418712c382c6f604426b36 Mon Sep 17 00:00:00 2001
aa0848
From: Frantisek Sumsal <frantisek@sumsal.cz>
aa0848
Date: Tue, 1 Feb 2022 20:18:29 +0100
aa0848
Subject: [PATCH] test: introduce `get_cgroup_hierarchy() helper
aa0848
aa0848
which returns the host's cgroup hierarchy (unified, hybrid, or legacy).
aa0848
aa0848
(cherry picked from commit f723740871bd3eb89d16a526a1ff77c04bb3787a)
aa0848
aa0848
Related: #2047768
aa0848
---
aa0848
 test/test-functions | 18 ++++++++++++++++++
aa0848
 1 file changed, 18 insertions(+)
aa0848
aa0848
diff --git a/test/test-functions b/test/test-functions
aa0848
index 35d8f074a9..4827b6bedf 100644
aa0848
--- a/test/test-functions
aa0848
+++ b/test/test-functions
aa0848
@@ -1996,6 +1996,24 @@ import_initdir() {
aa0848
     export initdir
aa0848
 }
aa0848
 
aa0848
+get_cgroup_hierarchy() {
aa0848
+    case "$(stat -c '%T' -f /sys/fs/cgroup)" in
aa0848
+        cgroup2fs)
aa0848
+            echo "unified"
aa0848
+            ;;
aa0848
+        tmpfs)
aa0848
+            if [[ -d /sys/fs/cgroup/unified && "$(stat -c '%T' -f /sys/fs/cgroup/unified)" == cgroup2fs ]]; then
aa0848
+                echo "hybrid"
aa0848
+            else
aa0848
+                echo "legacy"
aa0848
+            fi
aa0848
+            ;;
aa0848
+        *)
aa0848
+            dfatal "Failed to determine host's cgroup hierarchy"
aa0848
+            exit 1
aa0848
+    esac
aa0848
+}
aa0848
+
aa0848
 ## @brief Converts numeric logging level to the first letter of level name.
aa0848
 #
aa0848
 # @param lvl Numeric logging level in range from 1 to 6.