diff --git a/configs/samples/ast_debug_tools.conf.sample b/configs/samples/ast_debug_tools.conf.sample index 1c4827f91105e51317384d54ae663b50dc03faca..0f90f8518d1a02d3ff913e4792523217e27706d8 100644 --- a/configs/samples/ast_debug_tools.conf.sample +++ b/configs/samples/ast_debug_tools.conf.sample @@ -24,7 +24,7 @@ COREDUMPS=(/tmp/core[-._]asterisk!(*.txt) /tmp/core[-._]$(hostname)!(*.txt)) # For output from existing core files, the default is the # directory that the core file is found in. For core files # produced from a running process, the default is /tmp. -OUTPUTDIR=/some/directory +OUTPUTDIR=/tmp # Date command for the "running" coredump and tarballs. # DATEFORMAT will be executed to get the timestamp. diff --git a/contrib/scripts/ast_coredumper b/contrib/scripts/ast_coredumper index 38d95ccaaf2aa91ae92262cce4139b71d8eb16a9..b2ab4ace6a7c79625a751428f3f939af5656858a 100755 --- a/contrib/scripts/ast_coredumper +++ b/contrib/scripts/ast_coredumper @@ -225,10 +225,28 @@ append_coredumps=false declare -a COREDUMPS declare -a ARGS_COREDUMPS -# Read config files from least important to most important -[ -f /etc/asterisk/ast_debug_tools.conf ] && source /etc/asterisk/ast_debug_tools.conf -[ -f ~/ast_debug_tools.conf ] && source ~/ast_debug_tools.conf -[ -f ./ast_debug_tools.conf ] && source ./ast_debug_tools.conf +# readconf reads a bash-sourceable file and sets variables +# that havn't already been set. This allows variables set +# on the command line or that are already in the environment +# to take precedence over those read from the file. +# +# Setting the values can't be done in a subshell so you can't +# just pipe the output of sed into the while. + +readconf() { + while read line ; do + declare -n v=${line%%=*} + [ -z "${v}" ] && eval $line || : + done <<EOF +$( sed -r -e "/\s*#/d" -e "/^\s*$/d" $1 ) +EOF +} + +# Read config files from most important to least important. +# Variable set on the command line or environment always take precedence. +[ -f ./ast_debug_tools.conf ] && readconf ./ast_debug_tools.conf +[ -f ~/ast_debug_tools.conf ] && readconf ~/ast_debug_tools.conf +[ -f /etc/asterisk/ast_debug_tools.conf ] && readconf /etc/asterisk/ast_debug_tools.conf # For *BSD, the preferred gdb may be in /usr/local/bin so we # need to search for one that supports python.