From 006fd8d760834d161a978d0fe9d0d8c9160a58b1 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 24 Dec 2021 13:19:52 +0300 Subject: [PATCH] blockcheck: graceful quit when piping output --- blockcheck.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/blockcheck.sh b/blockcheck.sh index 7dcf9a2..efd23fc 100755 --- a/blockcheck.sh +++ b/blockcheck.sh @@ -782,11 +782,8 @@ check_dns() } -sigint() +unprepare_all() { - # make sure we are not in a middle state that impacts connectivity - echo - echo terminating... [ -n "$IPV" ] && { tpws_ipt_unprepare 80 tpws_ipt_unprepare 443 @@ -794,8 +791,23 @@ sigint() pktws_ipt_unprepare 443 } ws_kill +} + +sigint() +{ + # make sure we are not in a middle state that impacts connectivity + echo + echo terminating... + unprepare_all exitp 1 } +sigpipe() +{ + # make sure we are not in a middle state that impacts connectivity + # must not write anything here to stdout + unprepare_all + exit 1 +} check_system check_prerequisites @@ -804,10 +816,12 @@ check_dns ask_params PID= -trap 'sigint' 2 +trap sigint INT +trap sigpipe PIPE [ "$ENABLE_HTTP" = 1 ] && check_domain_http $DOMAIN [ "$ENABLE_HTTPS_TLS12" = 1 ] && check_domain_https_tls12 $DOMAIN [ "$ENABLE_HTTPS_TLS13" = 1 ] && check_domain_https_tls13 $DOMAIN -trap - 2 +trap - PIPE +trap - INT exitp 0