| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | # bail out if there's no "mail" command |
|---|
| 4 | type mail >/dev/null 2>&1 || exit 0 |
|---|
| 5 | |
|---|
| 6 | # Redirect all output to our mail command |
|---|
| 7 | ( |
|---|
| 8 | # We must be given a pid to look at |
|---|
| 9 | if [ -z "$1" ]; then |
|---|
| 10 | echo "$0 called with no arguments." |
|---|
| 11 | exit 1 |
|---|
| 12 | fi |
|---|
| 13 | |
|---|
| 14 | if [ ! -d "/proc/$1" ]; then |
|---|
| 15 | echo "$0: No such process: $1" |
|---|
| 16 | exit 1 |
|---|
| 17 | fi |
|---|
| 18 | |
|---|
| 19 | # Find out what binary we're debugging |
|---|
| 20 | BINARYNAME=`readlink "/proc/$1/exe"` |
|---|
| 21 | |
|---|
| 22 | # Generic header for our email |
|---|
| 23 | echo "The Samba 'panic action' script, $0," |
|---|
| 24 | echo "was called for PID $1 ($BINARYNAME)." |
|---|
| 25 | echo |
|---|
| 26 | |
|---|
| 27 | echo "This means there was a problem with the program, such as a segfault." |
|---|
| 28 | |
|---|
| 29 | if [ -z "$BINARYNAME" ]; then |
|---|
| 30 | echo "However, the executable could not be found for process $1." |
|---|
| 31 | echo "It may have died unexpectedly, or you may not have permission to debug" |
|---|
| 32 | echo "the process." |
|---|
| 33 | exit 1 |
|---|
| 34 | fi |
|---|
| 35 | |
|---|
| 36 | # No debugger |
|---|
| 37 | if [ ! -x /usr/bin/gdb ]; then |
|---|
| 38 | echo "However, gdb was not found on your system, so the error could not be" |
|---|
| 39 | echo "debugged. Please install the gdb package so that debugging information" |
|---|
| 40 | echo "is available the next time such a problem occurs." |
|---|
| 41 | exit 1 |
|---|
| 42 | fi |
|---|
| 43 | |
|---|
| 44 | echo "Below is a backtrace for this process generated with gdb, which shows" |
|---|
| 45 | echo "the state of the program at the time the error occurred. The Samba log" |
|---|
| 46 | echo "files may contain additional information about the problem." |
|---|
| 47 | echo |
|---|
| 48 | echo "If the problem persists, you are encouraged to first install the" |
|---|
| 49 | echo "samba-dbg package, which contains the debugging symbols for the Samba" |
|---|
| 50 | echo "binaries. Then submit the provided information as a bug report to" |
|---|
| 51 | if [ -x "`which lsb_release 2>/dev/null`" ] \ |
|---|
| 52 | && [ "`lsb_release -s -i`" = "Ubuntu" ] |
|---|
| 53 | then |
|---|
| 54 | echo "Ubuntu by visiting this link:" |
|---|
| 55 | echo "https://launchpad.net/ubuntu/+source/samba/+filebug" |
|---|
| 56 | else |
|---|
| 57 | echo "Debian. For information about the procedure for submitting bug reports," |
|---|
| 58 | echo "please see http://www.debian.org/Bugs/Reporting or the reportbug(1)" |
|---|
| 59 | echo "manual page." |
|---|
| 60 | fi |
|---|
| 61 | echo |
|---|
| 62 | gdb -x /etc/samba/gdbcommands -batch "$BINARYNAME" "$1" |
|---|
| 63 | ) | mail -s "Panic or segfault in Samba" root |
|---|