]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
tests: Call stop_servers when the shell terminates.
authorSimon Ruderich <simon@ruderich.org>
Mon, 29 Jul 2013 10:58:17 +0000 (12:58 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 29 Jul 2013 10:58:17 +0000 (12:58 +0200)
For example when set -e terminates the shell due to a failed process or
the user sends SIGINT.

tests/common.sh
tests/tests-normal.sh
tests/tests-passthrough.sh

index 37c691beaf71bbb43480940b98dc58c9e17e1875..36dda8ed0dd77abba19eab35c611cd1bbd02c564 100644 (file)
 set -e
 
 
+# Terminate all running servers when the script terminates.
+trap 'stop_servers' 0
+# Same when the user presses Ctrl-C.
+trap 'abort SIGINT' INT
+
+
 cleanup() {
     rm -f \
         tmp tlsproxy-log \
@@ -26,8 +32,12 @@ cleanup() {
         proxy-ca-key.pem proxy-ca.pem proxy-invalid.pem proxy-key.pem
 }
 stop_servers() {
-    kill $pid_server || echo 'failed to kill gnutls-serv'
-    kill $pid_tlsproxy || echo 'failed to kill tlsproxy'
+    if test -n "$pid_server"; then
+        kill $pid_server || echo 'failed to kill gnutls-serv'
+    fi
+    if test -n "$pid_tlsproxy"; then
+        kill $pid_tlsproxy || echo 'failed to kill tlsproxy'
+    fi
 }
 abort() {
     echo "abort: $*"
index 83b63f484a1770694c5bf6f61077621a8e1a6f3b..57ce39a8a12b8dfbcd1797ee5b98fd147ed92386 100755 (executable)
@@ -109,7 +109,7 @@ test_proxy_successful
 test_invalid_certificate
 
 
-stop_servers
+# stop_servers in trap-handler
 cleanup
 
 exit 0
index 500fb1b2ea98b9356da2076bb17d507191b5e003..f96e782438c7276f76ef7181f4948e0750267d2c 100755 (executable)
@@ -113,7 +113,7 @@ test_proxy_successful
 test_invalid_certificate
 
 
-stop_servers
+# stop_servers in trap-handler
 cleanup
 
 exit 0