File: btraceback.in

package info (click to toggle)
bacula 15.0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,780 kB
  • sloc: ansic: 194,276; cpp: 41,177; sh: 28,258; python: 6,669; makefile: 5,275; perl: 3,666; sql: 1,371; java: 345; xml: 196; awk: 51; sed: 25
file content (79 lines) | stat: -rwxr-xr-x 2,753 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
#
#   Bacula(R) - The Network Backup Solution
#
#   Copyright (C) 2000-2022 Kern Sibbald
#   Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
#
#   The original author of Bacula is Kern Sibbald, with contributions
#   from many others, a complete list can be found in the file AUTHORS.
#
#   You may use this file and others of this release according to the
#   license defined in the LICENSE file, which includes the Affero General
#   Public License, v3.0 ("AGPLv3") and some additional permissions and
#   terms pursuant to its AGPLv3 Section 7.
#
#   This notice must be preserved when any source code is 
#   conveyed and/or propagated.
#
#   Bacula(R) is a registered trademark of Kern Sibbald.
#
# Script to do a stackdump of a Bacula daemon/program.
#
# We attempt to attach to running program
#
# Arguments to this script are
#  $1 = path to executable
#  $2 = main pid of running program to be traced back.
#  $3 = working directory
#
PNAME=`basename $1`
WD="$3"
# When parsing the configuration, the working directory is not
# yet initialized
if [ "$WD" = "" ]; then
    WD=/tmp
fi

# Start constructing message. Point to log files for better user
# experience, append backtrace or message about missing debugger later
echo "Check the log files for more information." > ${WD}/bacula.$2.traceback
echo "" >> ${WD}/bacula.$2.traceback

case `uname -s` in
SunOS)
   #
   # See what debuggers are available on this platform.
   # We need to to some tricks to find out as a which on
   # a non existing binary gives:
   #
   # no <debugger> in <PATH>
   #
   # So we use the return code which is 0 when it finds
   # somethings and 1 if not.
   #
   which gdb > /dev/null 2>&1 && GDB=`which gdb` || GDB=''
   which dbx > /dev/null 2>&1 && DBX=`which dbx` || DBX=''
   which mdb > /dev/null 2>&1 && MDB=`which mdb` || MDB=''
   gcore -o ${WD}/${PNAME} $2
   if [ ! -z "${DBX}" ]; then
      ${DBX} $1 $2 < @scriptdir@/btraceback.dbx >> ${WD}/bacula.$2.traceback 2>&1
   elif [ ! -z "${GDB}" ]; then
      ${GDB} -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 >> ${WD}/bacula.$2.traceback 2>&1
   elif [ ! -z "${MDB}" ]; then
      ${MDB} -u -p $2 < @scriptdir@/btraceback.mdb >> ${WD}/bacula.$2.traceback 2>&1
   fi
   ;;
*)
    which gdb > /dev/null 2>&1 && GDB=`which gdb` || GDB=''
    if  [ ! -z "${GDB}" ]; then
        gdb -quiet -batch -x @scriptdir@/btraceback.gdb $1 $2 >> ${WD}/bacula.$2.traceback 2>&1
    else
        echo "Please install a debugger (gdb) to receive a traceback." >> ${WD}/bacula.$2.traceback 2>&1
    fi
   ;;
esac

PNAME="${PNAME} on `hostname`"
cat ${WD}/bacula.$2.traceback \
    | @sbindir@/bsmtp -h @smtp_host@ -f @dump_email@ -s "Bacula traceback. Process crashed ${PNAME}" @dump_email@