always install the exit trap in scripts

This moves the exit trap into grenade/functions, which means all
grenade scripts will get the exit trap registered on them. This also
adds stack tracing into the scripts so that we can determine where we
were when we failed.

Change-Id: I4100628180498ff8723a1af6c0a4c10b4d8244c8
This commit is contained in:
Sean Dague 2015-04-10 06:04:08 -04:00
parent 0c752781e8
commit 176ab63307
2 changed files with 25 additions and 17 deletions

View File

@ -45,5 +45,30 @@ function save_data {
}
# Setup Exit Traps for debug purposes
trap exit_trap EXIT
function exit_trap {
# really important that this is the *first* line in this
# function, otherwise we corrupt the exit code
local r=$?
# we don't need tracing during this
set +o xtrace
if [[ $r -ne 0 ]]; then
# unwind the call stack on failures
local frame=0
while caller $frame; do
((frame++));
done
echo "Exit code: $r"
if [[ -x $TARGET_DEVSTACK_DIR/tools/worlddump.py ]]; then
$TARGET_DEVSTACK_DIR/tools/worlddump.py -d $LOGDIR
sleep 1
fi
fi
exit $r
}
# Restore xtrace
$XTRACE

View File

@ -146,23 +146,6 @@ if [[ -n "$SCREEN_LOGDIR" ]]; then
fi
fi
# Setup Exit Traps for debug purposes
trap exit_trap EXIT
function exit_trap {
# really important that this is the *first* line in this
# function, otherwise we corrupt the exit code
local r=$?
# we don't need tracing during this
set +o xtrace
if [[ $r -ne 0 ]]; then
echo "Exit code: $r"
if [[ -x $TARGET_DEVSTACK_DIR/tools/worlddump.py ]]; then
$TARGET_DEVSTACK_DIR/tools/worlddump.py -d $LOGDIR
sleep 1
fi
fi
exit $r
}
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.