For example when set -e terminates the shell due to a failed process or
the user sends SIGINT.
+# 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 \
cleanup() {
rm -f \
tmp tlsproxy-log \
proxy-ca-key.pem proxy-ca.pem proxy-invalid.pem proxy-key.pem
}
stop_servers() {
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: $*"
}
abort() {
echo "abort: $*"
+# stop_servers in trap-handler
+# stop_servers in trap-handler