summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-10-03 12:35:40 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-10-03 12:35:40 +0200
commit7228cc00e8eb4a64b3a307a3313364f309a1b10f (patch)
tree3831513fe39680c3efc153347a7c71486e107e95
parenta26416dca3c4ada1baf76712c43332bc960f9c20 (diff)
downloaddevtools-7228cc00e8eb4a64b3a307a3313364f309a1b10f.tar.xz
Use dedicated trap functions to avoid unsetting the trap when e.g. cleanup is called
-rw-r--r--lib/common.sh16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 5c144e2..74b251f 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -62,8 +62,6 @@ setup_workdir() {
}
cleanup() {
- trap - EXIT INT QUIT TERM HUP
-
[[ -n $WORKDIR ]] && rm -rf "$WORKDIR"
[[ $1 ]] && exit $1
}
@@ -73,13 +71,23 @@ abort() {
cleanup 0
}
+trap_abort() {
+ trap - EXIT INT QUIT TERM HUP
+ abort
+}
+
+trap_exit() {
+ trap - EXIT INT QUIT TERM HUP
+ cleanup 0
+}
+
die() {
error "$*"
cleanup 1
}
-trap abort INT QUIT TERM HUP
-trap 'cleanup 0' EXIT
+trap 'trap_abort' INT QUIT TERM HUP
+trap 'trap_exit' EXIT
##
# usage : in_array( $needle, $haystack )