]> git.ipfire.org Git - people/ms/network.git/commitdiff
test: Be less patient if networkd does not want to terminate
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 08:20:41 +0000 (08:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 08:20:41 +0000 (08:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
test/networkd/test.sh

index a22aeb372d248155b141d0ca82d5e1537a0e80b4..7690978d8597710d8a87d4a62aec6026f5fe5e7b 100644 (file)
@@ -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