From 5841b9d8399fc5bead59276aa751b85ce064a6cb Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 19 Sep 2015 04:48:57 -0700 Subject: [PATCH] tg.sh: make sure temporary directory is removed on signal Only /bin/bash seems to trap all signals and run an EXIT trap before terminating a script because of an uncaught signal. Other shells just die. However, we rely on the EXIT trap to remove our temporary directory. Fix this by explicitly trapping the signals we expect could terminate the script and explicitly calling exit in the handler which will guarantee the EXIT trap runs and does its thing. When a process run by the shell dies of a signal, the exit status is 128+signal, so use that as the exit status for the various signals we trap on. Additionally, POSIX defines 7 well-known signal numbers that can be used. We omit traps on ALRM and KILL. Signed-off-by: Kyle J. McKay --- tg.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tg.sh b/tg.sh index cc27b24..383067b 100644 --- a/tg.sh +++ b/tg.sh @@ -734,8 +734,14 @@ initial_setup() # create global temporary directories, inside GIT_DIR + tg_tmp_dir= + trap 'rm -rf "$tg_tmp_dir"' EXIT + trap 'exit 129' HUP + trap 'exit 130' INT + trap 'exit 131' QUIT + trap 'exit 134' ABRT + trap 'exit 143' TERM tg_tmp_dir="$(mktemp -d "$git_dir/tg-tmp.XXXXXX")" - trap "rm -rf \"$tg_tmp_dir\"" EXIT } # return the "realpath" for the item except the leaf is not resolved if it's -- 2.11.4.GIT