]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: unify checking for user xattrs support in cgroupfs
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 19 Oct 2023 10:28:37 +0000 (12:28 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 19 Oct 2023 17:01:07 +0000 (18:01 +0100)
Also, run the coredump forwarding test only if user xattrs are
supported.

test/test-functions
test/units/testsuite-04.LogFilterPatterns.sh
test/units/testsuite-55.sh
test/units/testsuite-74.coredump.sh
test/units/util.sh

index 3b26b0ca06dbface3d31a4d235c206ecc27518a1..7461703e85592ff404da2d20f956340838a04637 100644 (file)
@@ -173,6 +173,7 @@ BASICTOOLS=(
     getconf
     getent
     getfacl
+    getfattr
     grep
     gunzip
     gzip
index 41cf8a1fa1d3851f5c09b1e8d9e07fae3fc6d5af..d5d610fe02a7d187db777eb091a02d580222a7ec 100755 (executable)
@@ -3,6 +3,9 @@
 set -eux
 set -o pipefail
 
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
 add_logs_filtering_override() {
     local unit="${1:?}"
     local override_name="${2:?}"
@@ -27,20 +30,7 @@ run_service_and_fetch_logs() {
     systemctl stop "$unit"
 }
 
-is_xattr_supported() {
-    local start end
-
-    start="$(date '+%Y-%m-%d %T.%6N')"
-    systemd-run --unit text_xattr --property LogFilterPatterns=log sh -c "sleep .5"
-    sleep .5
-    journalctl --sync
-    end="$(date '+%Y-%m-%d %T.%6N')"
-    systemctl stop text_xattr
-
-    ! journalctl -q -u "text_xattr" -S "$start" -U "$end" --grep "Failed to set 'user.journald_log_filter_patterns' xattr.*not supported$"
-}
-
-if is_xattr_supported; then
+if cgroupfs_supports_user_xattrs; then
     # Accept all log messages
     add_logs_filtering_override "logs-filtering.service" "00-reset" ""
     [[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]]
index ffa9af2f6ac5fa880a0064833111d2842ac7e33e..afd3053e4da5bbd14099d09640192c7720be9430 100755 (executable)
@@ -3,6 +3,9 @@
 set -eux
 set -o pipefail
 
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
 systemd-analyze log-level debug
 
 # Ensure that the init.scope.d drop-in is applied on boot
@@ -149,7 +152,7 @@ if systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.ser
 if ! systemctl --machine "testuser@.host" --user status testsuite-55-testchill.service; then exit 24; fi
 
 # only run this portion of the test if we can set xattrs
-if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then
+if cgroupfs_supports_user_xattrs; then
     sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down
 
     mkdir -p /run/systemd/system/testsuite-55-testbloat.service.d/
index 534232a9fb3e3d54a9fd71bc1b7f0ff7ba805009..6552643ee9671089e91124b5bbefa39bf2d66ea4 100755 (executable)
@@ -3,6 +3,9 @@
 set -eux
 set -o pipefail
 
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
 # Make sure the binary name fits into 15 characters
 CORE_TEST_BIN="/tmp/test-dump"
 CORE_TEST_UNPRIV_BIN="/tmp/test-usr-dump"
@@ -89,15 +92,17 @@ ExecStart=systemd-nspawn --quiet --link-journal=try-guest --keep-unit --machine=
 EOF
 systemctl daemon-reload
 
-machinectl start "$CONTAINER"
-timeout 60 bash -xec "until systemd-run -M '$CONTAINER' -q --wait --pipe true; do sleep .5; done"
+if cgroupfs_supports_user_xattrs; then
+    machinectl start "$CONTAINER"
+    timeout 60 bash -xec "until systemd-run -M '$CONTAINER' -q --wait --pipe true; do sleep .5; done"
 
-[[ "$(systemd-run -M "$CONTAINER" -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l)" -eq 0 ]]
-machinectl copy-to "$CONTAINER" "$MAKE_DUMP_SCRIPT"
-systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGABRT"
-systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGTRAP"
-# Wait a bit for the coredumps to get processed
-timeout 30 bash -c "while [[ \$(systemd-run -M $CONTAINER -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l) -lt 2 ]]; do sleep 1; done"
+    [[ "$(systemd-run -M "$CONTAINER" -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l)" -eq 0 ]]
+    machinectl copy-to "$CONTAINER" "$MAKE_DUMP_SCRIPT"
+    systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGABRT"
+    systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGTRAP"
+    # Wait a bit for the coredumps to get processed
+    timeout 30 bash -c "while [[ \$(systemd-run -M $CONTAINER -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l) -lt 2 ]]; do sleep 1; done"
+fi
 
 coredumpctl
 SYSTEMD_LOG_LEVEL=debug coredumpctl
index 8a01c5c07a9ca4016a67686a436531e847d392a7..fee642fa9d897c94970331cd43f8d673c69d0b34 100755 (executable)
@@ -171,3 +171,14 @@ systemctl_final() {
 
     systemctl "$@"
 }
+
+cgroupfs_supports_user_xattrs() {
+    local xattr
+
+    xattr="user.supported_$RANDOM"
+    # shellcheck disable=SC2064
+    trap "setfattr --remove=$xattr /sys/fs/cgroup || :" RETURN
+
+    setfattr --name="$xattr" --value=254 /sys/fs/cgroup
+    [[ "$(getfattr --name="$xattr" --absolute-names --only-values /sys/fs/cgroup)" -eq 254 ]]
+}