The process forked off by `systemd-notify --fork` is not a child of the
current shell, so using `wait` doesn't work. This then later causes a
race, when the test occasionally fails because it attempts to start a
new systemd-socket-activate instance before the old one is completely
gone:
[ 1488.947744] TEST-74-AUX-UTILS.sh[1938]: Child 1947 died with code 0
[ 1488.947952] TEST-74-AUX-UTILS.sh[1933]: + assert_eq hello hello
[ 1488.949716] TEST-74-AUX-UTILS.sh[1948]: + set +ex
[ 1488.950112] TEST-74-AUX-UTILS.sh[1950]: ++ cat /proc/1938/comm
[ 1488.945555] systemd[1]: Started systemd-networkd.service - Network Management.
[ 1488.950365] TEST-74-AUX-UTILS.sh[1933]: + assert_in systemd-socket systemd-socket-
[ 1488.950563] TEST-74-AUX-UTILS.sh[1951]: + set +ex
[ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + kill 1938
[ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + wait 1938
[ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: .//usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh: line 14: wait: pid 1938 is not a child of this shell
[ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + :
[ 1488.951486] TEST-74-AUX-UTILS.sh[1952]: ++ systemd-notify --fork -- systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE
[ 1488.952222] TEST-74-AUX-UTILS.sh[1953]: Failed to listen on [::]🔢 Address already in use
[ 1488.952222] TEST-74-AUX-UTILS.sh[1953]: Failed to open '1234': Address already in use
[ 1488.956831] TEST-74-AUX-UTILS.sh[1933]: + PID=1953
[ 1488.957078] TEST-74-AUX-UTILS.sh[102]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh failed'
[ 1488.957078] TEST-74-AUX-UTILS.sh[102]: Subtest /usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh failed
37 lines
1.2 KiB
Bash
Executable File
37 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
set -eux
|
|
set -o pipefail
|
|
|
|
# shellcheck source=test/units/util.sh
|
|
. "$(dirname "$0")"/util.sh
|
|
|
|
PID="$(systemd-notify --fork -- systemd-socket-activate -l 1234 --accept --inetd cat)"
|
|
assert_in systemd-socket "$(cat /proc/"$PID"/comm)"
|
|
assert_eq "$(echo -n hello | socat - 'TCP:localhost:1234')" hello
|
|
assert_in systemd-socket "$(cat /proc/"$PID"/comm)"
|
|
kill "$PID"
|
|
tail --pid="$PID" -f /dev/null
|
|
|
|
PID=$(systemd-notify --fork -- systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE)
|
|
for _ in {1..100}; do
|
|
sleep 0.1
|
|
if [[ ! -d "/proc/$PID" ]]; then
|
|
# ACCEPT-FD is available since socat v1.8
|
|
: "systemd-socket-activate or socat died. Maybe socat does not support ACCEPT-FD. Skipping test."
|
|
break
|
|
fi
|
|
|
|
if [[ "$(cat /proc/"$PID"/comm || :)" =~ socat ]]; then
|
|
assert_eq "$(echo -n bye | socat - 'TCP:localhost:1234')" bye
|
|
tail --pid="$PID" -f /dev/null
|
|
break
|
|
fi
|
|
done
|
|
|
|
# --accept is not allowed with --now
|
|
(! systemd-socket-activate -l 1234 --accept --now cat)
|
|
|
|
# Multiple fds are not allowed with --inetd
|
|
(! systemd-socket-activate -l 1234 -l 4321 --inetd cat)
|