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:
parent
0c752781e8
commit
176ab63307
25
functions
25
functions
|
@ -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
|
||||
|
|
17
grenade.sh
17
grenade.sh
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue