| 1 |
#!/bin/sh |
|---|
| 2 |
|
|---|
| 3 |
# Actions for Cherokee-Panic: |
|---|
| 4 |
# mail - mail the error. You need a working MTA in the system. |
|---|
| 5 |
# stdout - just print it |
|---|
| 6 |
# |
|---|
| 7 |
if test "x$CHEROKEE_PANIC_OUTPUT" != "x"; then |
|---|
| 8 |
action="$CHEROKEE_PANIC_OUTPUT" |
|---|
| 9 |
else |
|---|
| 10 |
if [ -x /usr/sbin/sendmail ]; then |
|---|
| 11 |
action=mail |
|---|
| 12 |
else |
|---|
| 13 |
action=stdout |
|---|
| 14 |
fi |
|---|
| 15 |
fi |
|---|
| 16 |
|
|---|
| 17 |
# Redirect all output to our mail command |
|---|
| 18 |
( |
|---|
| 19 |
# Check the OS |
|---|
| 20 |
os=`uname` |
|---|
| 21 |
|
|---|
| 22 |
# We must be given a pid to look at |
|---|
| 23 |
if [ -z "$1" ]; then |
|---|
| 24 |
echo "$0 called with no arguments." |
|---|
| 25 |
exit 1 |
|---|
| 26 |
else |
|---|
| 27 |
pid=$1 |
|---|
| 28 |
fi |
|---|
| 29 |
|
|---|
| 30 |
# Check for a second argument |
|---|
| 31 |
if [ -n "$2" ]; then |
|---|
| 32 |
action="$2" |
|---|
| 33 |
fi |
|---|
| 34 |
|
|---|
| 35 |
# Mail header |
|---|
| 36 |
if [ x$action = xmail ]; then |
|---|
| 37 |
echo "To: root" |
|---|
| 38 |
echo "Subject: Segfault in Cherokee" |
|---|
| 39 |
echo |
|---|
| 40 |
fi |
|---|
| 41 |
|
|---|
| 42 |
if [ $os = "Linux" ]; then |
|---|
| 43 |
BINARYNAME=`readlink "/proc/$pid/exe"` |
|---|
| 44 |
known_os=yes |
|---|
| 45 |
elif [ $os = "SunOS" ]; then |
|---|
| 46 |
BINARYNAME=`perl -e "print readlink(\"/proc/$pid/path/a.out\");"` |
|---|
| 47 |
known_os=yes |
|---|
| 48 |
fi |
|---|
| 49 |
|
|---|
| 50 |
# Generic header for the report |
|---|
| 51 |
echo "The Cherokee 'panic action' script, $0," |
|---|
| 52 |
echo "was called for pid $pid ($BINARYNAME)." |
|---|
| 53 |
echo |
|---|
| 54 |
|
|---|
| 55 |
# Ensure /proc/$pid exists if it should |
|---|
| 56 |
if test "x${known_os}" = "xyes"; then |
|---|
| 57 |
if [ ! -d "/proc/$pid" ]; then |
|---|
| 58 |
echo "$0: No such process: $pid" |
|---|
| 59 |
exit 1 |
|---|
| 60 |
fi |
|---|
| 61 |
if test "x${BINARYNAME} " = "x"; then |
|---|
| 62 |
echo "This means there was a problem with the program, such as a segfault." |
|---|
| 63 |
echo "However, the executable could not be found for process $pid." |
|---|
| 64 |
echo "It may have died unexpectedly, or you may not have permission to" |
|---|
| 65 |
echo "debug the process." |
|---|
| 66 |
exit 1 |
|---|
| 67 |
fi |
|---|
| 68 |
fi |
|---|
| 69 |
|
|---|
| 70 |
# Check the debugger |
|---|
| 71 |
gdb=`which gdb` |
|---|
| 72 |
dbx=`which dbx` |
|---|
| 73 |
|
|---|
| 74 |
if [ x$gdb != x ]; then |
|---|
| 75 |
debugger=$gdb |
|---|
| 76 |
elif [ x$dbx != x ]; then |
|---|
| 77 |
debugger=$dbx |
|---|
| 78 |
else |
|---|
| 79 |
# No debugger |
|---|
| 80 |
echo "This means there was a problem with the program, such as a segfault." |
|---|
| 81 |
echo "However, gdb was not found on your system, so the error could not be" |
|---|
| 82 |
echo "debugged. Please install the gdb package so that debugging information is" |
|---|
| 83 |
echo "available the next time such a problem occurs." |
|---|
| 84 |
exit 1 |
|---|
| 85 |
fi |
|---|
| 86 |
|
|---|
| 87 |
echo "Below is a backtrace for this process generated with gdb, which shows" |
|---|
| 88 |
echo "the state of the program at the time the error occured. You are" |
|---|
| 89 |
echo "encouraged to submit this information as a bug report in the Cherokee" |
|---|
| 90 |
echo "bug traq system: http://bugs.cherokee-project.com" |
|---|
| 91 |
echo |
|---|
| 92 |
echo "Operating System: `uname -a`" |
|---|
| 93 |
echo "Debugger: $debugger" |
|---|
| 94 |
echo |
|---|
| 95 |
|
|---|
| 96 |
# Get the backtrace |
|---|
| 97 |
if [ x$debugger = x$gdb ]; then |
|---|
| 98 |
tmp_cmd=`mktemp -t 2>/dev/null` || |
|---|
| 99 |
tmp_cmd=`mktemp "/tmp/chrk.XXXXXX"` || exit 1 |
|---|
| 100 |
|
|---|
| 101 |
( echo "print cherokee_version" |
|---|
| 102 |
echo "thread apply all bt full" |
|---|
| 103 |
echo "quit" ) >> $tmp_cmd |
|---|
| 104 |
|
|---|
| 105 |
if [ -z $BINARYNAME ]; then |
|---|
| 106 |
$gdb -x $tmp_cmd -batch --pid=$pid |
|---|
| 107 |
else |
|---|
| 108 |
$gdb -x $tmp_cmd -batch "$BINARYNAME" "$pid" |
|---|
| 109 |
fi |
|---|
| 110 |
rm $tmp_cmd |
|---|
| 111 |
|
|---|
| 112 |
elif [ x$debugger = x$dbx ]; then |
|---|
| 113 |
$dbx -c "print (char *)cherokee_version; where -v -l ; quit" "$BINARYNAME" "$pid" |
|---|
| 114 |
fi |
|---|
| 115 |
|
|---|
| 116 |
) | ( |
|---|
| 117 |
case "$action" in |
|---|
| 118 |
mail) |
|---|
| 119 |
/usr/sbin/sendmail -t |
|---|
| 120 |
;; |
|---|
| 121 |
stdout) |
|---|
| 122 |
cat - |
|---|
| 123 |
;; |
|---|
| 124 |
*) |
|---|
| 125 |
echo "ERROR: Wrong action: \"$action\"" |
|---|
| 126 |
exit 1 |
|---|
| 127 |
esac; |
|---|
| 128 |
) |
|---|
| 129 |
|
|---|