From: Michael Tremer Date: Fri, 9 Jun 2023 08:20:41 +0000 (+0000) Subject: test: Be less patient if networkd does not want to terminate X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1e43a02719530f865fd7818b60b706c551d143c;p=network.git test: Be less patient if networkd does not want to terminate Signed-off-by: Michael Tremer --- diff --git a/test/networkd/test.sh b/test/networkd/test.sh index a22aeb37..7690978d 100644 --- a/test/networkd/test.sh +++ b/test/networkd/test.sh @@ -63,27 +63,43 @@ launch_networkd() { coproc networkd { ./networkd "$@"; } echo "networkd launched as PID ${networkd_PID}" + + sleep 1 } terminate_networkd() { - if [ -n "${networkd_PID}" ]; then - # Collect some status information - dump_status - - # Send SIGTERM - kill -TERM "${networkd_PID}" + local seconds=0 - # Wait until networkd has finished - echo "Waiting for networkd to terminate..." - wait "${networkd_PID}" + if [ -n "${networkd_PID}" ]; then + while [ -n "${networkd_PID}" ] && kill -0 "${networkd_PID}"; do + case "${seconds}" in + # Send SIGTERM in the beginning + 0) + echo "Sending SIGTERM to networkd" + kill -TERM "${networkd_PID}" + ;; + + # After 5 seconds, send SIGKILL + 5) + echo "Sending SIGKILL to networkd" + kill -KILL "${networkd_PID}" + + # It is an error, if we have to kill networkd + exit 1 + ;; + esac + + # Wait for a moment + sleep 1 + + # Increment seconds + (( seconds++ )) + done echo "networkd has terminated" fi } -# Make sure networkd has been terminated when this script exits -trap "terminate_networkd" EXIT - main() { local test="${1}" shift @@ -112,6 +128,9 @@ main() { # Terminate networkd terminate_networkd + # Collect some status information + dump_status + # Run cleanup script if ! run_script "${test}/cleanup.sh"; then return 1