From 687e7f34d5fd10bb7e4f0dfbf61d28eb7703618e Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 4 Dec 2009 21:48:50 +0000 Subject: [PATCH] b=21514 i=wangyb i=yangsheng If lbuild is interrupted (i.e. LBATS "Cancel") then it should not call the ccache -s exit trap action because experience has shown that the ccache binary is gone by the time lbuild gets to calling it. Also, extend the API for the delete_exit_trap() to handle multiple action handles in a single call. This makes it easy to create a stack of actions and then delete them all in a single command. What would be even nicer would be (shell and pdsh style) glob handling so that one could do delete_exit_trap foo[1-10], assuming one pushed 10 actions on a stack to be unwound during an operation that is supposed to be atomic. Or more simply delete_exit_trap foo*. --- build/exit_traps.sh | 71 ++++++++++++++++++++++++++++++++++++----------------- build/lbuild | 4 ++- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/build/exit_traps.sh b/build/exit_traps.sh index 209c119..9be8212 100644 --- a/build/exit_traps.sh +++ b/build/exit_traps.sh @@ -26,12 +26,15 @@ push_exit_trap() { } delete_exit_trap() { - local trap_handle="$1" - - local var="exit_trap_handle_$trap_handle" - local trap_num=${!var} - exit_actions[$trap_num]="" - eval unset $var + local trap_handles="$@" + + local handle + for handle in $trap_handles; do + local var="exit_trap_handle_$handle" + local trap_num=${!var} + exit_actions[$trap_num]="" + eval unset $var + done } print_exit_traps() { @@ -60,19 +63,43 @@ run_exit_traps() { trap run_exit_traps EXIT -#if ! push_exit_trap "echo \"this is the first trap\"" "a"; then -# echo "failed to install trap 1" -# exit 1 -#fi -#if ! push_exit_trap "echo \"this is the second trap\"" "b"; then -# echo "failed to install trap 2" -# exit 2 -#fi -#delete_exit_trap "b" -#if ! push_exit_trap "echo \"this is the third trap\"" "b"; then -# echo "failed to install trap 3" -# exit 3 -#fi - -# to see the traps -#print_exit_traps +if [ "$1" = "unit_test" ]; then + if ! push_exit_trap "echo \"this is the first trap\"" "a"; then + echo "failed to install trap 1" + exit 1 + fi + if ! push_exit_trap "echo \"this is the second trap\"" "b"; then + echo "failed to install trap 2" + exit 2 + fi + delete_exit_trap "b" + if ! push_exit_trap "echo \"this is the third trap\"" "b"; then + echo "failed to install trap 3" + exit 3 + fi + + # to see the traps + print_exit_traps + echo "------------" + + delete_exit_trap "a" "b" + print_exit_traps + echo "------------" + + if ! push_exit_trap "echo \"this is the first trap\"" "a"; then + echo "failed to install trap 1" + exit 1 + fi + if ! push_exit_trap "echo \"this is the second trap\"" "b"; then + echo "failed to install trap 2" + exit 2 + fi + if ! push_exit_trap "echo \"this is the third trap\"" "c"; then + echo "failed to install trap 3" + exit 3 + fi + delete_exit_trap "a" "c" + + print_exit_traps + echo "------------" +fi diff --git a/build/lbuild b/build/lbuild index e48eb11..295fc25 100755 --- a/build/lbuild +++ b/build/lbuild @@ -1897,7 +1897,9 @@ if [ -n "$RDAC_VERSION" -a "$RDAC_VERSION" != "inkernel" ]; then fatal 1 "Error copying RDAC source tarball to RPM SOURCES dir" fi -push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache" +push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary" +# should remove the ccache trap if lbuild is interrupted +trap 'delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP # if an unpacked kernel source tree was given on the command line # just build lustre with it (nothing distro kernel specific here) -- 1.8.3.1