]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/btraceback.in
Backport from Bacula Enterprise
[bacula/bacula] / bacula / scripts / btraceback.in
1 #!/bin/sh
2 #
3 #   Bacula(R) - The Network Backup Solution
4 #
5 #   Copyright (C) 2000-2015 Kern Sibbald
6 #   Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
7 #
8 #   The original author of Bacula is Kern Sibbald, with contributions
9 #   from many others, a complete list can be found in the file AUTHORS.
10 #
11 #   You may use this file and others of this release according to the
12 #   license defined in the LICENSE file, which includes the Affero General
13 #   Public License, v3.0 ("AGPLv3") and some additional permissions and
14 #   terms pursuant to its AGPLv3 Section 7.
15 #
16 #   This notice must be preserved when any source code is 
17 #   conveyed and/or propagated.
18 #
19 #   Bacula(R) is a registered trademark of Kern Sibbald.
20 #
21 # Script to do a stackdump of a Bacula daemon/program.
22 #
23 # We attempt to attach to running program
24 #
25 # Arguments to this script are
26 #  $1 = path to executable
27 #  $2 = main pid of running program to be traced back.
28 #  $3 = working directory
29 #
30 PNAME=`basename $1`
31 WD="$3"
32 case `uname -s` in
33 SunOS)
34    #
35    # See what debuggers are available on this platform.
36    # We need to to some tricks to find out as a which on
37    # a non existing binary gives:
38    #
39    # no <debugger> in <PATH>
40    #
41    # So we use the return code which is 0 when it finds
42    # somethings and 1 if not.
43    #
44    which gdb > /dev/null 2>&1 && GDB=`which gdb` || GDB=''
45    which dbx > /dev/null 2>&1 && DBX=`which dbx` || DBX=''
46    which mdb > /dev/null 2>&1 && MDB=`which mdb` || MDB=''
47    gcore -o ${WD}/${PNAME} $2
48    if [ ! -z "${DBX}" ]; then
49       ${DBX} $1 $2 < @scriptdir@/btraceback.dbx > ${WD}/bacula.$2.traceback 2>&1
50    elif [ ! -z "${GDB}" ]; then
51       ${GDB} -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 > ${WD}/bacula.$2.traceback 2>&1
52    elif [ ! -z "${MDB}" ]; then
53       ${MDB} -u -p $2 < @scriptdir@/btraceback.mdb > ${WD}/bacula.$2.traceback 2>&1
54    fi
55    PNAME="${PNAME} on `hostname`"
56    cat ${WD}/bacula.$2.traceback \
57     | @sbindir@/bsmtp -h @smtp_host@ -f @dump_email@ -s "Bacula DBX traceback of ${PNAME}" @dump_email@
58    ;;
59 *)
60    gdb -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 >${WD}/bacula.$2.traceback 2>&1
61    PNAME="${PNAME} on `hostname`"
62    cat ${WD}/bacula.$2.traceback \
63     | @sbindir@/bsmtp -h @smtp_host@ -f @dump_email@ -s "Bacula GDB traceback of ${PNAME}" @dump_email@
64    ;;
65 esac