"$1"
}
-dbus_can_freeze() {
- local name object_path suffix
-
- suffix="${1##*.}"
- name="${1%".$suffix"}"
- object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
-
- busctl get-property \
- org.freedesktop.systemd1 \
- "${object_path}" \
- org.freedesktop.systemd1.Unit \
- CanFreeze
-}
-
check_freezer_state() {
- local name object_path suffix
+ local name state expected
- suffix="${1##*.}"
- name="${1%".$suffix"}"
- object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
+ name="${1:?}"
+ expected="${2:?}"
+
+ # Ignore the intermediate freezing & thawing states in case we check the unit state too quickly.
+ timeout 10 bash -c "while [[ \"\$(systemctl show \"$name\" --property FreezerState --value)\" =~ (freezing|thawing) ]]; do sleep .5; done"
- for _ in {0..10}; do
- state=$(busctl get-property \
- org.freedesktop.systemd1 \
- "${object_path}" \
- org.freedesktop.systemd1.Unit \
- FreezerState | cut -d " " -f2 | tr -d '"')
-
- # Ignore the intermediate freezing & thawing states in case we check
- # the unit state too quickly
- [[ "$state" =~ ^(freezing|thawing) ]] || break
- sleep .5
- done
-
- [ "$state" = "$2" ] || {
- echo "error: unexpected freezer state, expected: $2, actual: $state" >&2
+ state="$(systemctl show "$name" --property FreezerState --value)"
+ [[ "$state" = "$expected" ]] || {
+ echo "error: unexpected freezer state, expected: $expected, actual: $state" >&2
exit 1
}
}
check_cgroup_state "$unit" 0
echo "[ OK ]"
- echo -n " - CanFreeze(): "
- output=$(dbus_can_freeze "${unit}")
- [ "$output" = "b true" ]
+ echo -n " - CanFreeze: "
+ [[ "$(systemctl show "${unit}" --property=CanFreeze --value)" == 'yes' ]]
echo "[ OK ]"
echo