From 7228cc00e8eb4a64b3a307a3313364f309a1b10f Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 3 Oct 2012 12:35:40 +0200 Subject: Use dedicated trap functions to avoid unsetting the trap when e.g. cleanup is called --- lib/common.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') 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 ) -- cgit v1.2.3-70-g09d2