cleanup(): Exit correctly for SIGINT

Also, replace $die_error_exit with $confirm_aborted:
Make die() the default exit on error.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
This commit is contained in:
Richard T Bonhomme 2022-11-20 20:54:52 +00:00
parent 0ee7a6d75e
commit 3cb322049a
No known key found for this signature in database
GPG Key ID: 2D767DB92FB6C246

View File

@ -531,7 +531,6 @@ Easy-RSA error:
$1 $1
" 1>&2 " 1>&2
die_error_exit=1
exit "${2:-1}" exit "${2:-1}"
} # => die() } # => die()
@ -588,6 +587,7 @@ Type the word '$value' to continue, or any other input to abort."
read input read input
printf '\n' printf '\n'
[ "$input" = "$value" ] && return [ "$input" = "$value" ] && return
confirm_aborted=1
notice "Aborting without confirmation." notice "Aborting without confirmation."
exit 9 exit 9
} # => confirm() } # => confirm()
@ -742,10 +742,13 @@ Temporary session not preserved."
elif [ "$1" = ok ]; then elif [ "$1" = ok ]; then
# if there is no error then 'cleanup ok' is called # if there is no error then 'cleanup ok' is called
exit 0 exit 0
elif [ "$1" = 2 ]; then
# SIGINT
kill -2 "$$"
else else
# if 'cleanup' is called without 'ok' then an error occurred # if 'cleanup' is called without 'ok' then an error occurred
# Do not show_host() for confirm() aborted exit # Do not show_host() for confirm() aborted exit
[ "$die_error_exit" ] && show_host [ "$confirm_aborted" ] || show_host
exit 1 exit 1
fi fi
} # => cleanup() } # => cleanup()
@ -4964,7 +4967,7 @@ NL='
[ "$EASYRSA_NO_UMASK" ] || umask "${EASYRSA_UMASK:-077}" [ "$EASYRSA_NO_UMASK" ] || umask "${EASYRSA_UMASK:-077}"
# Register cleanup on EXIT # Register cleanup on EXIT
trap "cleanup" EXIT trap 'cleanup $?' EXIT
# When SIGHUP, SIGINT, SIGQUIT, SIGABRT and SIGTERM, # When SIGHUP, SIGINT, SIGQUIT, SIGABRT and SIGTERM,
# explicitly exit to signal EXIT (non-bash shells) # explicitly exit to signal EXIT (non-bash shells)
trap "exit 1" 1 trap "exit 1" 1
@ -4977,7 +4980,7 @@ trap "exit 14" 15
detect_host detect_host
# Initialisation requirements # Initialisation requirements
unset -v die_error_exit easyrsa_error_exit \ unset -v confirm_aborted easyrsa_error_exit \
user_san_true user_vars_true alias_days user_san_true user_vars_true alias_days
# Parse options # Parse options