The test waited for the OnFailure= service's filesystem side effect (`rmdir` of the directory) and then immediately invoked `systemctl is-active`. Between `rmdir(2)` returning (which causes the shell loop to exit) and PID1 reaping the child and transitioning the oneshot service from `activating` to `active`, there is a small window where `is-active` can observe `activating` and fail the test. Wait directly on the unit state instead, matching the pattern used a few lines above for the `is-failed` case. [ 1880.326704] TEST-07-PID1.sh[21489]: + timeout --foreground 60 bash -c 'while [[ -d '\''/tmp/TEST-07-PID1-socket-8467/test'\'' ]]; do sleep .5; done' [ 1880.330482] TEST-07-PID1.sh[21489]: + [[ ! -e /tmp/TEST-07-PID1-socket-8467/test ]] [ 1880.330482] TEST-07-PID1.sh[21489]: + systemctl is-active TEST-07-PID1-socket-OnFailure.service [ 1880.347470] TEST-07-PID1.sh[21520]: activating [ 1880.349508] TEST-07-PID1.sh[21489]: + at_exit [ 1880.349508] TEST-07-PID1.sh[21489]: + systemctl stop TEST-07-PID1-socket-8467.socket [ 1880.367331] TEST-07-PID1.sh[107]: Subtest /usr/lib/systemd/tests/testdata/units/TEST-07-PID1.socket-on-failure.sh failed [ 1880.367331] TEST-07-PID1.sh[107]: + return 1 Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
1.8 KiB
Bash
Executable File
73 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
# shellcheck disable=SC2016
|
|
set -eux
|
|
set -o pipefail
|
|
|
|
# shellcheck source=test/units/util.sh
|
|
. "$(dirname "$0")"/util.sh
|
|
|
|
UNIT_NAME="TEST-07-PID1-socket-$RANDOM"
|
|
|
|
at_exit() {
|
|
systemctl stop "$UNIT_NAME.socket"
|
|
rm -f /run/systemd/system/"$UNIT_NAME".{socket,service} \
|
|
/run/systemd/system/TEST-07-PID1-socket-OnFailure.service
|
|
}
|
|
|
|
trap at_exit EXIT
|
|
|
|
# Test triggering OnFailure= when fails to listen on socket (#35635)
|
|
|
|
mkdir -p "/tmp/$UNIT_NAME"
|
|
|
|
cat >/run/systemd/system/"$UNIT_NAME.socket" <<EOF
|
|
[Unit]
|
|
OnFailure=TEST-07-PID1-socket-OnFailure.service
|
|
|
|
[Socket]
|
|
ListenStream=/tmp/$UNIT_NAME/test
|
|
EOF
|
|
|
|
cat >/run/systemd/system/"$UNIT_NAME.service" <<EOF
|
|
[Service]
|
|
ExecStart=true
|
|
EOF
|
|
|
|
cat >/run/systemd/system/TEST-07-PID1-socket-OnFailure.service <<EOF
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=rmdir /tmp/$UNIT_NAME/test
|
|
RemainAfterExit=yes
|
|
EOF
|
|
|
|
systemctl start "$UNIT_NAME.socket"
|
|
systemctl is-active "$UNIT_NAME.socket"
|
|
[[ -S "/tmp/$UNIT_NAME/test" ]]
|
|
|
|
systemctl stop "$UNIT_NAME.socket"
|
|
rm "/tmp/$UNIT_NAME/test"
|
|
|
|
chattr +i "/tmp/$UNIT_NAME"
|
|
|
|
(! systemctl start "$UNIT_NAME.socket")
|
|
systemctl is-failed "$UNIT_NAME.socket"
|
|
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "failed"
|
|
|
|
[[ ! -e "/tmp/$UNIT_NAME/test" ]]
|
|
timeout --foreground 60 bash -c "until systemctl is-failed TEST-07-PID1-socket-OnFailure.service; do sleep .5; done"
|
|
|
|
chattr -i "/tmp/$UNIT_NAME"
|
|
|
|
mkdir "/tmp/$UNIT_NAME/test"
|
|
|
|
(! systemctl start "$UNIT_NAME.socket")
|
|
systemctl is-failed "$UNIT_NAME.socket"
|
|
assert_eq "$(systemctl show "$UNIT_NAME.socket" -P SubState)" "failed"
|
|
|
|
timeout --foreground 60 bash -c "until systemctl is-active TEST-07-PID1-socket-OnFailure.service; do sleep .5; done"
|
|
[[ ! -e "/tmp/$UNIT_NAME/test" ]]
|
|
|
|
systemctl start "$UNIT_NAME.socket"
|
|
systemctl is-active "$UNIT_NAME.socket"
|