Trap SIGEXIT appropriately during exits

This commit is contained in:
Anirudha Bose 2014-06-24 13:51:42 +05:30 committed by sftnight
parent 3355f27235
commit c6deaeca86
4 changed files with 15 additions and 13 deletions

View File

@ -21,7 +21,6 @@
# Uncomment the following line to trace the execution of the shell commands
# set -o xtrace
set -o errexit
# TODO: Change workdir to a suitable path on your system (or Electric Commander)
workdir=~/ec/build
@ -36,7 +35,7 @@ source ${HOST_CLING_SRC_DIR}/debian/debianize.sh
source ${HOST_CLING_SRC_DIR}/windows/windows_dep.sh
# Trap exceptions, call function "cleanup" and exit
trap cleanup EXIT INT TERM
trap cleanup EXIT HUP INT QUIT TERM ERR
function usage {
cat <<- EOT
@ -56,13 +55,16 @@ function usage {
Supported values of "pkg-format": tar | deb | nsis
Supported values of "tag": Any Git tag in Cling's repository. Example, v0.1
EOT
# Reset trap on SIGEXIT. Nothing to cleanup here.
trap - EXIT
exit
}
while [ "${1}" != "" ]; do
if [ "${#}" != "1" ]; then
echo "Error: cannot handle multiple switches"
usage
exit
fi
echo "Cling Packaging Tool (CPT)"
@ -81,13 +83,14 @@ while [ "${1}" != "" ]; do
# Cannot cross-compile for Windows from any other OS
if [ "${OS}" != "Cygwin" -a "${VALUE}" = "nsis" ] || [ "${OS}" != "Cygwin" -a "${PARAM}" = "--nsis-tag" ]; then
echo "Error: Cross-compilation for Windows not supported (yet)"
# Reset trap on SIGEXIT. Nothing to cleanup here.
trap - EXIT
exit
fi
case ${PARAM} in
-h | --help)
usage
exit
;;
-c | --check-requirements)
box_draw "Check if required softwares are available on this system"
@ -116,6 +119,8 @@ EOT
;;
esac
done
# Reset trap on SIGEXIT. Nothing to cleanup here.
trap - EXIT
exit
elif [ "${OS}" = "Cygwin" ]; then
check_cygwin cygwin # Doesn't make much sense. This is for the appeasement of users.
@ -136,7 +141,6 @@ EOT
if [ "${VALUE}" = "" ]; then
echo "Error: Expected a value"
usage
exit
fi
fetch_llvm
fetch_clang
@ -173,7 +177,6 @@ EOT
if [ "${VALUE}" = "" ]; then
echo "Error: Expected a value"
usage
exit
fi
fetch_llvm
fetch_clang
@ -212,7 +215,6 @@ EOT
if [ "${VALUE}" = "" ]; then
echo "Error: Expected a value"
usage
exit
fi
fetch_llvm
fetch_clang
@ -228,7 +230,6 @@ EOT
if [ "${VALUE}" = "" ]; then
echo "Error: Expected a value"
usage
exit
fi
fetch_llvm
fetch_clang
@ -245,7 +246,6 @@ EOT
if [ "${VALUE}" = "" ]; then
echo "Error: Expected a value"
usage
exit
fi
fetch_llvm
fetch_clang
@ -272,7 +272,6 @@ EOT
*)
echo "Error: unknown parameter \"${PARAM}\""
usage
exit 1
;;
esac
shift

View File

@ -19,7 +19,6 @@
# Uncomment the following line to trace the execution of the shell commands
# set -o xtrace
set -o errexit
function tarball_deb {
box_draw "Compressing compiled binaries to produce a bzip2 tarball"

View File

@ -19,7 +19,6 @@
# Uncomment the following line to trace the execution of the shell commands
# set -o xtrace
set -o errexit
function platform_init {
OS=$(uname -o)
@ -297,6 +296,8 @@ function tarball {
}
function cleanup {
# Newline is required to align boxes prooperly when SIGINT is encountered
echo ""
box_draw "Clean up"
echo "Remove directory: ${workdir}/builddir"
rm -Rf ${workdir}/builddir
@ -313,6 +314,10 @@ function cleanup {
echo "Remove file: cling.nsi"
rm -Rf ${workdir}/cling.nsi
fi
# Reset trap on SIGEXIT, or else function "cleanup" will be executed twice.
trap - EXIT
exit
}
# Initialize variables with details of the platform and Operating System

View File

@ -19,7 +19,6 @@
# Uncomment the following line to trace the execution of the shell commands
# set -o xtrace
set -o errexit
function check_cygwin {
# Check for Cygwin