From 2bf26ce5accf070bc513308637f95caaf8b37ac1 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Tue, 15 May 2018 07:45:20 -0600 Subject: [PATCH] ast_coredumper: Fix output directory and variable precedence The OUTPUTDIR variable in ast_debug_tools.conf.sample is now set to "/tmp" instead of "/some/directory". Variables set on the command line or that are already in the environment now take predecence over variables set in the config files. ASTERISK-27846 Reported by: Ted G Change-Id: Ie8baec52d531886bf5849ec1d59bb59dc87ad387 --- configs/samples/ast_debug_tools.conf.sample | 2 +- contrib/scripts/ast_coredumper | 26 +++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/configs/samples/ast_debug_tools.conf.sample b/configs/samples/ast_debug_tools.conf.sample index 1c4827f911..0f90f8518d 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 38d95ccaaf..b2ab4ace6a 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 <