<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7091">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins2: Verified
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit

</div><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, 109 insertions(+), 53 deletions(-)<br><br></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..1c4827f 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, 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> # 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..884ede7 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>@@ -130,6 +137,10 @@<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>  installation of the 'coreutils' and 'devel/gdb' packagess and minor<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>@@ -326,6 +350,10 @@<br> # Timestamp to use for output files<br> df=${tarball_uniqueid:-$(${DATEFORMAT})}<br> <br>+if [ -z "$asterisk_bin" ]; then<br>+      asterisk_bin=$(which asterisk)<br>+fi<br>+<br> if $running || $RUNNING ; then<br>       # We need to go through some gyrations to find the pid of the running<br>         # MAIN asterisk process and not someone or something running asterisk -r.<br>@@ -351,9 +379,9 @@<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>+                       ${GDB} ${asterisk_bin} -p $pid -q --batch --ex "gcore $cf" >/dev/null 2>&1<br>                        COREDUMPS+=("$cf")<br>          else<br>                  echo "Skipping dump of running process"<br>@@ -370,20 +398,22 @@<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>-      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>+<br>+    cfdir=`dirname ${cf}`<br>+        cfname=`basename ${cf}`<br>+      outputdir=${OUTPUTDIR:-${cfdir}}<br>+<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 +421,58 @@<br>                  echo -e $"$line" >> "$of"<br>           done<br>  )<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>+    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>-    for i in ${!COREDUMPS[@]} ; do<br>-               rm -rf "${COREDUMPS[$i]}"<br>-  done<br>-fi<br>+            rm -rf "${cf}"<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>+    if $delete_results_after ; then<br>+              rm -rf "${cf//:/-}"-{brief,full,thread1,locks}.txt<br>+ fi<br>+done<br> <br> exit<br> <br>@@ -463,6 +501,9 @@<br>         try:<br>             gdb.execute("p $_siginfo", from_tty)<br>             gdb.execute("info signal $_siginfo.si_signo")<br>+        except:<br>+            pass<br>+        try:<br>             gdb.execute("thread apply 1 bt full", from_tty)<br>         except:<br>             pass<br>@@ -470,6 +511,9 @@<br>         try:<br>             gdb.execute("p $_siginfo", from_tty)<br>             gdb.execute("info signal $_siginfo.si_signo")<br>+        except:<br>+            pass<br>+        try:<br>             gdb.execute("thread apply all bt", from_tty)<br>         except:<br>             pass<br>@@ -477,6 +521,9 @@<br>         try:<br>             gdb.execute("p $_siginfo", from_tty)<br>             gdb.execute("info signal $_siginfo.si_signo")<br>+        except:<br>+            pass<br>+        try:<br>             gdb.execute("thread apply all bt full", from_tty)<br>         except:<br>             pass<br>@@ -484,6 +531,9 @@<br>         try:<br>             gdb.execute("p $_siginfo", from_tty)<br>             gdb.execute("info signal $_siginfo.si_signo")<br>+        except:<br>+            pass<br>+        try:<br>             gdb.execute("show_locks", from_tty)<br>         except:<br>             pass<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7091">change 7091</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/7091"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I66b2553319df61caea5b313d084f51978f730b4c </div>
<div style="display:none"> Gerrit-Change-Number: 7091 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>