From 446a58f9f3778bc3ac168f73fb9fd857a687c5f2 Mon Sep 17 00:00:00 2001 From: Eric F Crist Date: Tue, 2 Oct 2018 10:02:40 -0500 Subject: [PATCH] Broaden trap() functionality Resolves #236 and #247 * Broaden trapped signals to SIGHUB, SIGINT, SIGQUIT, SIGABRT * Turn echo back on upon exit. * Provide a newline at exit just to make the terminal look pretty. Signed-off-by: Eric F Crist --- easyrsa3/easyrsa | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index 68aaf3c..9e89baf 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -287,6 +287,14 @@ clean_temp() { done } # => clean_temp() +prog_exit() { + ESTAT=0 + [ ! -z "$1" ] && ESTAT=$1 + (set -o echo 2>/dev/null) || stty echo + echo "" # just to get a clean line + exit $ESTAT +} # => prog_exit() + # Make LibreSSL safe config file from OpenSSL config file make_ssl_config() { sed -e "s,ENV::,,g" \ @@ -1318,8 +1326,8 @@ done # Intelligent env-var detection and auto-loading: vars_setup -# Register clean_temp on EXIT -trap "clean_temp" EXIT +# Register clean_temp and prog_exit on SIGHUP, SIGINT, SIGQUIT, and SIGABRT +trap "clean_temp; prog_exit" 1 2 3 6 # determine how we were called, then hand off to the function responsible cmd="$1"