[Asterisk-code-review] ast coredumper: Fix output directory and variable precedence (asterisk[15])

Joshua Colp asteriskteam at digium.com
Thu May 31 05:16:19 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8993 )

Change subject: ast_coredumper:  Fix output directory and variable precedence
......................................................................

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
---
M configs/samples/ast_debug_tools.conf.sample
M contrib/scripts/ast_coredumper
2 files changed, 23 insertions(+), 5 deletions(-)

Approvals:
  Matthew Fredrickson: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/configs/samples/ast_debug_tools.conf.sample b/configs/samples/ast_debug_tools.conf.sample
index 1c4827f..0f90f85 100644
--- a/configs/samples/ast_debug_tools.conf.sample
+++ b/configs/samples/ast_debug_tools.conf.sample
@@ -24,7 +24,7 @@
 # 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 38d95cc..b2ab4ac 100755
--- a/contrib/scripts/ast_coredumper
+++ b/contrib/scripts/ast_coredumper
@@ -225,10 +225,28 @@
 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.

-- 
To view, visit https://gerrit.asterisk.org/8993
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie8baec52d531886bf5849ec1d59bb59dc87ad387
Gerrit-Change-Number: 8993
Gerrit-PatchSet: 3
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180531/ce033eb9/attachment.html>


More information about the asterisk-code-review mailing list