]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
t_server_null: forcibly kill misbehaving servers
authorSamuli Seppänen <samuli.seppanen@gmail.com>
Fri, 25 Oct 2024 10:36:31 +0000 (12:36 +0200)
committerGert Doering <gert@greenie.muc.de>
Fri, 25 Oct 2024 10:56:05 +0000 (12:56 +0200)
Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Signed-off-by: Samuli Seppänen <samuli.seppanen@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20241025103632.4413-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29655.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
tests/t_server_null.sh
tests/t_server_null_client.sh
tests/t_server_null_default.rc
tests/t_server_null_server.sh

index d4311d4ed300c1d9c4a32d3cdc98a870c98e1827..3c0fc4bea551236572f4c157375b10957b1028f2 100755 (executable)
@@ -71,4 +71,10 @@ retval=$?
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
index 846f79067bce6f7c258cb973e72ffe1c054d41ea..2210e63462097ebed5009f7f5f6ed98cb83bc9fa 100755 (executable)
@@ -53,11 +53,11 @@ get_client_test_result() {
         echo "PASS ${test_name} (test failure)"
     elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
         echo "FAIL ${test_name} (test failure)"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
         echo "FAIL ${test_name}"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     fi
 }
index 825bb529994cef1fe81ff2779b95ae1d455fdf40..cbf4877c33ef9591e0d088e9871d902071d8798b 100755 (executable)
@@ -20,6 +20,10 @@ SERVER_CERT="${sample_keys}/server.crt"
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
index f8ba3a3c9b8d7fe7f083a060564a2c770d690ac6..ab01dd2eb22f576a6ef9f1a97afa33f9abb55dfa 100755 (executable)
@@ -8,6 +8,9 @@ launch_server() {
     status="${server_name}.status"
     pid="${server_name}.pid"
 
+    # Allow reading this file even umask values are strict
+    touch "$log"
+
     if [ -z "${RUN_SUDO}" ]; then
         "${server_exec}" \
          $server_conf \
@@ -34,6 +37,9 @@ umask 022
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +81,7 @@ echo "All clients have disconnected from all servers"
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +92,25 @@ do
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done