]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: introduce `get_cgroup_hierarchy() helper
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 1 Feb 2022 19:18:29 +0000 (20:18 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 1 Feb 2022 21:13:45 +0000 (22:13 +0100)
which returns the host's cgroup hierarchy (unified, hybrid, or legacy).

test/test-functions

index 3ae8caed3fbfbc975450a4af395759352d27f404..d79c52c5911e524fbce64eb8331a291ccfac676a 100644 (file)
@@ -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.