misleading source filename in error message
when ./stack.sh encounters error, the output may look like this:
[ERROR] ./stack.sh:698 nova-api did not start
The source filename is wrong. Actually, it should be like this:
[ERROR] /<path_of_devstack>/lib/nova:698 nova-api did not start
stack.sh uses bash as interpreter, which define "Shell Variables"
BASH_SOURCE:
An array variable whose members are the source filenames where
the corresponding shell function names in the FUNCNAME array
variable are defined. The shell function
${FUNCNAME[$i]} is defined in the file ${BASH_SOURCE[$i]}
and called from ${BASH_SOURCE[$i+1]}.
The function "err" is called by function "die" ( and "err_if_not_set",
and "err_if_not_set" is not used at all). ${BASH_SOURCE[2]} will
ignore the deepest two call entries, which corresponding to the shell
functions: "err" and "die".
In one sentence, this change will print the source filename where the
function is defined and exits via function "die".
Fixes bug #1207658
Change-Id: I2aa6642c5cf4cfe781afe278b3dec3e7cba277fa
diff --git a/functions b/functions
index 262f70f..43ff1a7 100644
--- a/functions
+++ b/functions
@@ -113,7 +113,7 @@
local exitcode=$?
errXTRACE=$(set +o | grep xtrace)
set +o xtrace
- local msg="[ERROR] $0:$1 $2"
+ local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
echo $msg 1>&2;
if [[ -n ${SCREEN_LOGDIR} ]]; then
echo $msg >> "${SCREEN_LOGDIR}/error.log"