From f28aeaf9081885d79b9ca3927c7836e77559e4d4 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 12 Sep 2020 22:58:30 -0700 Subject: [PATCH] update.sh: cleanup the cleanup code a bit Put the cleanup code in a function and use the function name as the `trap` argument rather than trying to stuff all the code into a string. Also take this opportunity to make the code slightly more robust and trap more possible abnormal exits. Signed-off-by: Kyle J. McKay --- jobd/update.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/jobd/update.sh b/jobd/update.sh index 993d81c..e2d1dce 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -120,8 +120,21 @@ cd "$cfg_reporoot/$proj.git" # get the .needsgc flag set in a timely fashion to avoid excess pack build up. check_and_set_needsgc -trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT +bang_log= +cleanup_exit() { + ec=$? + if [ $ec != 0 ]; then + echo "update failed dir: $PWD" >&2 + fi + [ -z "$bang_log" ] || rm -f "$bang_log" +} +trap 'cleanup_exit' EXIT +trap 'exit 129' HUP trap 'exit 130' INT +trap 'exit 131' QUIT +trap 'exit 134' ABRT +trap 'exit 141' PIPE +trap 'exit 142' ALRM trap 'exit 143' TERM if [ "${force_update:-0}" = "0" ] && check_interval lastrefresh $cfg_min_mirror_interval; then -- 2.11.4.GIT