<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7092">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ast_coredumper: Add ability to use directory other than /tmp<br><br>The OUTPUTDIR environment variable can now be set either in the<br>environment itself or in ast_debug_tools.conf. If set, it's used<br>for all work products instead of /tmp.<br><br>Also added the --tarball-config option that includes the contents<br>of /etc/asterisk when either --tarball-coredumps or --tarball-results<br>are used.<br><br>Change-Id: I66b2553319df61caea5b313d084f51978f730b4c<br>---<br>M configs/samples/ast_debug_tools.conf.sample<br>M contrib/scripts/ast_coredumper<br>2 files changed, 95 insertions(+), 52 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/92/7092/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/configs/samples/ast_debug_tools.conf.sample b/configs/samples/ast_debug_tools.conf.sample<br>index f26626b..b530c98 100644<br>--- a/configs/samples/ast_debug_tools.conf.sample<br>+++ b/configs/samples/ast_debug_tools.conf.sample<br>@@ -20,6 +20,12 @@<br> # anyway.<br> COREDUMPS=(/tmp/core[-._]asterisk!(*.txt) /tmp/core[-._]$(hostname)!(*.txt))<br> <br>+# The directory to contain output files and work directories.<br>+# For output from existing core files, the default is the<br>+# directory that the core file is found in. For core files<br>+# produced from a running process, teh default is /tmp. <br>+OUTPUTDIR=/some/directory<br>+<br> # Date command for the "running" coredump and tarballs.<br> # DATEFORMAT will be executed to get the timestamp.<br> # Don't put quotes around the format string or they'll be<br>diff --git a/contrib/scripts/ast_coredumper b/contrib/scripts/ast_coredumper<br>index 9b01a42..d46d897 100755<br>--- a/contrib/scripts/ast_coredumper<br>+++ b/contrib/scripts/ast_coredumper<br>@@ -15,7 +15,7 @@<br> $prog [ --help ] [ --running | --RUNNING ] [ --latest ]<br> [ --tarball-coredumps ] [ --delete-coredumps-after ]<br> [ --tarball-results ] [ --delete-results-after ]<br>- [ --tarball-uniqueid="<uniqueid>" ]<br>+ [ --tarball-config ] [ --tarball-uniqueid="<uniqueid>" ]<br> [ --no-default-search ] [ --append-coredumps ]<br> [ --asterisk-bin="path" ]<br> [ <coredump> | <pattern> ... ]<br>@@ -51,7 +51,8 @@<br> Create a coredump from the running asterisk instance and<br> process it along with any other coredumps found (if any).<br> WARNING: This WILL interrupt call processing. You will be<br>- asked to confirm.<br>+ asked to confirm. The coredump will be written to /tmp if<br>+ $OUTPUTDIR is not defined.<br> <br> --RUNNING<br> Same as --running but without the confirmation prompt.<br>@@ -69,10 +70,11 @@<br> /usr/sbin/asterisk, /usr/lib(64)/libasterisk* and<br> /usr/lib(64)/asterisk as those files are needed to properly<br> examine the coredump. The file will be named<br>- /tmp/asterisk.<timestamp>.coredumps.tar.gz or<br>- /tmp/asterisk-<uniqueid>.coredumps.tar.gz if<br>+ $OUTPUTDIR/asterisk.<timestamp>.coredumps.tar.gz or<br>+ $OUTPUTDIR/asterisk-<uniqueid>.coredumps.tar.gz if<br> --tarball-uniqueid was specified.<br> WARNING: This file could 1gb in size!<br>+ Mutually exclusive with --tartball-results<br> <br> --delete-coredumps-after<br> Deletes all processed coredumps regardless of whether<br>@@ -81,13 +83,18 @@<br> --tarball-results<br> Creates a gzipped tarball of all result files produced.<br> The tarball name will be:<br>- /tmp/asterisk.<timestamp>.results.tar.gz<br>+ $OUTPUTDIR/asterisk.<timestamp>.results.tar.gz<br>+ Mutually exclusive with --tartball-coredumps<br> <br> --delete-results-after<br> Deletes all processed results regardless of whether<br> a tarball was created. It probably doesn't make sense<br> to use this option unless you have also specified<br> --tarball-results.<br>+<br>+ --tarball-config<br>+ Adds the contents of /etc/asterisk to the tarball created<br>+ with --tarball-coredumps or --tarball-results.<br> <br> --tarball-uniqueid="<uniqueid>"<br> Normally DATEFORMAT is used to make the tarballs unique<br>@@ -129,6 +136,10 @@<br> <br> NOTES<br> You must be root to use $prog.<br>+ <br>+ $OUTPUTDIR can be read from the current environment or from the<br>+ ast_debug_tools.conf file described below. If not specified,<br>+ work products are placed in the same directory as the core file.<br> <br> The script relies on not only bash, but also recent GNU date and<br> gdb with python support. *BSD operating systems may require<br>@@ -165,6 +176,12 @@<br> # demonstration purposes as non-coredumps will be ignored<br> # anyway.<br> COREDUMPS=(/tmp/core[-._]asterisk!(*.txt) /tmp/core[-._]\$(hostname)!(*.txt))<br>+<br>+ # The directory to contain output files and work directories.<br>+ # For output from existing core files, the default is the<br>+ # directory that the core file is found in. For core files<br>+ # produced from a running process, the default is /tmp. <br>+ OUTPUTDIR=/some/directory<br> <br> # Date command for the "running" coredump and tarballs.<br> # DATEFORMAT will be executed to get the timestamp.<br>@@ -225,6 +242,13 @@<br> if [ -z "$GDB" ] ; then<br> echo "No suitable gdb was found in $PATH"<br> exit 1<br>+fi<br>+<br>+if [ -n "$OUTPUTDIR" ] ; then<br>+ if [ ! -d "$OUTPUTDIR" ] ; then<br>+ echo "OUTPUTDIR $OUTPUTDIR doesn't exists or is not a directory"<br>+ exit 1<br>+ fi<br> fi<br> <br> if [ ${#COREDUMPS[@]} -eq 0 ] ; then<br>@@ -351,7 +375,7 @@<br> read -p "WARNING: Taking a core dump of the running asterisk instance will suspend call processing while the dump is saved. Do you wish to continue? (y/N) " answer<br> fi<br> if [[ "$answer" =~ ^[Yy] ]] ; then<br>- cf="/tmp/core-asterisk-running-$df"<br>+ cf="${OUTPUTDIR:-/tmp}/core-asterisk-running-$df"<br> echo "Dumping running asterisk process to $cf"<br> ${GDB} -p $pid -q --batch --ex "gcore $cf" >/dev/null 2>&1<br> COREDUMPS+=("$cf")<br>@@ -370,20 +394,25 @@<br> # and save them to /tmp/.gdbinit<br> <br> ss=`egrep -n "^#@@@SCRIPTSTART@@@" $0 |cut -f1 -d:`<br>-tail -n +${ss} $0 >/tmp/.ast_coredumper.gdbinit<br>+tail -n +${ss} $0 >${OUTPUTDIR:-/tmp}/.ast_coredumper.gdbinit<br> <br> # Now iterate over the coredumps and dump the debugging info<br> for i in ${!COREDUMPS[@]} ; do<br> cf=${COREDUMPS[$i]}<br> echo "Processing $cf"<br>+ <br>+ cfdir=`dirname ${cf}`<br>+ cfname=`basename ${cf}`<br>+ outputdir=${OUTPUTDIR:-${cfdir}}<br>+ <br> if [ -z "$asterisk_bin" ]; then<br> asterisk_bin=$(which asterisk)<br> fi<br>- ${GDB} -n --batch -q --ex "source /tmp/.ast_coredumper.gdbinit" "$asterisk_bin" "$cf" 2>/dev/null | (<br>+ ${GDB} -n --batch -q --ex "source ${OUTPUTDIR:-/tmp}/.ast_coredumper.gdbinit" "$asterisk_bin" "$cf" 2>/dev/null | (<br> of=/dev/null<br> while IFS= read line ; do<br> if [[ "$line" =~ !@!@!@!\ ([^\ ]+)\ !@!@!@! ]] ; then<br>- of=${cf}-${BASH_REMATCH[1]}<br>+ of=${outputdir}/${cfname}-${BASH_REMATCH[1]}<br> of=${of//:/-}<br> rm -f "$of"<br> echo "Creating $of"<br>@@ -391,50 +420,58 @@<br> echo -e $"$line" >> "$of"<br> done<br> )<br>+ <br>+ if $tarball_coredumps ; then<br>+ cfname=${cfname//:/-}<br>+ tf=${outputdir}/${cfname}.tar.gz<br>+ echo "Creating ${tf}"<br>+ <br>+ dest=${outputdir}/${cfname}.output<br>+ rm -rf ${dest} 2>/dev/null || :<br>+ <br>+ libdir=usr/lib<br>+ [ -d /usr/lib64 ] && libdir+=64<br>+ mkdir -p ${dest}/tmp ${dest}/${libdir}/asterisk ${dest}/etc ${dest}/usr/sbin<br>+ <br>+ ln -s ${cf} ${dest}/tmp/${cfname}<br>+ cp ${outputdir}/${cfname}*.txt ${dest}/tmp/<br>+ cp /etc/os-release ${dest}/etc/<br>+ if $tarball_config ; then<br>+ cp -a /etc/asterisk ${dest}/etc/<br>+ fi<br>+ cp -a /${libdir}/libasterisk* ${dest}/${libdir}/<br>+ cp -a /${libdir}/asterisk/* ${dest}/${libdir}/asterisk/<br>+ cp -a /usr/sbin/asterisk ${dest}/usr/sbin<br>+ rm -rf ${tf}<br>+ tar -chzf ${tf} --transform="s/^[.]/${cfname}/" -C ${dest} .<br>+ rm -rf ${dest}<br>+ echo "Created $tf"<br>+ elif $tarball_results ; then<br>+ cfname=${cfname//:/-}<br>+ tf=${outputdir}/${cfname}.tar.gz<br>+ echo "Creating ${tf}"<br>+<br>+ dest=${outputdir}/${cfname}.output<br>+ rm -rf ${dest} 2>/dev/null || :<br>+ mkdir -p ${dest}<br>+ cp ${outputdir}/${cfname}*.txt ${dest}/<br>+ if $tarball_config ; then<br>+ mkdir -p ${dest}/etc<br>+ cp -a /etc/asterisk ${dest}/etc/<br>+ fi<br>+ tar -chzf ${tf} --transform="s/^[.]/${cfname}/" -C ${dest} .<br>+ rm -rf ${dest}<br>+ echo "Created $tf"<br>+ fi<br>+ <br>+ if $delete_coredumps_after ; then<br>+ rm -rf "${cf}"<br>+ fi<br>+<br>+ if $delete_results_after ; then<br>+ rm -rf "${cf//:/-}"-{brief,full,thread1,locks}.txt<br>+ fi<br> done<br>-<br>-if $tarball_coredumps ; then<br>- tf=/tmp/asterisk-$df.coredumps.tar.gz<br>- echo "Creating $tf"<br>- dest=/tmp/asterisk-$df<br>- rm -rf $dest 2>/dev/null || :<br>- libdir=usr/lib<br>- [ -d /usr/lib64 ] && libdir+=64<br>- mkdir -p $dest/tmp $dest/$libdir/asterisk $dest/etc $dest/usr/sbin<br>- for i in ${!COREDUMPS[@]} ; do<br>- ln -s "${COREDUMPS[@]}" $dest/"${COREDUMPS[@]}"<br>- cp "${COREDUMPS[@]}"*.txt $dest/tmp/<br>- done<br>- cp /etc/os-release $dest/etc/<br>- cp -a /$libdir/libasterisk* $dest/$libdir/<br>- cp -a /$libdir/asterisk/* $dest/$libdir/asterisk/<br>- cp -a /usr/sbin/asterisk $dest/usr/sbin<br>- rm -rf $tf<br>- tar -chzf $tf --transform="s/^[.]/$df/" -C $dest .<br>- rm -rf $dest<br>- echo "Created $tf"<br>-fi<br>-<br>-if $delete_coredumps_after ; then<br>- for i in ${!COREDUMPS[@]} ; do<br>- rm -rf "${COREDUMPS[$i]}"<br>- done<br>-fi<br>-<br>-if $tarball_results ; then<br>- tf=/tmp/asterisk-$df-results.tar<br>- echo "Creating $tf.gz"<br>- for i in ${!COREDUMPS[@]} ; do<br>- tar -uvf $tf "${COREDUMPS[$i]//:/-}"-{brief,full,thread1,locks}.txt 2>/dev/null<br>- done<br>- gzip $tf<br>-fi<br>-<br>-if $delete_results_after ; then<br>- for i in ${!COREDUMPS[@]} ; do<br>- rm -rf "${COREDUMPS[$i]//:/-}"-{brief,full,thread1,locks}.txt<br>- done<br>-fi<br> <br> exit<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7092">change 7092</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7092"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I66b2553319df61caea5b313d084f51978f730b4c </div>
<div style="display:none"> Gerrit-Change-Number: 7092 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>