/
cherokee-panic
executable file
·177 lines (148 loc) · 3.82 KB
/
cherokee-panic
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/sh
# Actions for Cherokee-Panic:
# mail - mail the error. You need a working MTA in the system.
# stdout - just print it
#
if test "x$CHEROKEE_PANIC_OUTPUT" != "x"; then
action="$CHEROKEE_PANIC_OUTPUT"
else
if [ -x /usr/sbin/sendmail ]; then
action=mail
else
action=stdout
fi
fi
# Redirect stderr to stdout
exec 2>&1
# Redirect all output to our mail command
(
# Check the OS
os=`uname`
# We must be given a pid to look at
if [ x$1 = x ]; then
echo "$0 called with no arguments."
exit 1
else
pid=$1
fi
# Check for a second argument
if [ -n "$2" ]; then
action="$2"
fi
# Mail header
if [ x$action = xmail ]; then
echo "To: root"
echo "Subject: Segfault in Cherokee"
echo
fi
if [ $os = "Linux" ]; then
BINARYNAME=`readlink "/proc/$pid/exe"`
known_os=yes
elif [ $os = "SunOS" ]; then
BINARYNAME=`perl -e "print readlink(\"/proc/$pid/path/a.out\");"`
known_os=yes
fi
# Generic header for the report
echo "The Cherokee 'panic action' script, $0,"
echo "was called for pid $pid ($BINARYNAME)."
echo
# Ensure /proc/$pid exists if it should
if test "x${known_os}" = "xyes"; then
if [ ! -d "/proc/$pid" ]; then
echo "$0: No such process: $pid"
exit 1
fi
if test "x${BINARYNAME}" = "x"; then
echo "This means there was a problem with the program, such as a segfault."
echo "However, the executable could not be found for process $pid."
echo "It may have died unexpectedly, or you may not have permission to"
echo "debug the process."
exit 1
fi
fi
# Check the debugger
gdb=`which gdb`
dbx=`which dbx`
if [ x$gdb != x ]; then
debugger=$gdb
elif [ x$dbx != x ]; then
debugger=$dbx
else
# No debugger
echo "This means there was a problem with the program, such as a segfault."
echo "However, gdb was not found on your system, so the error could not be"
echo "debugged. Please install the gdb package so that debugging information is"
echo "available the next time such a problem occurs."
exit 1
fi
echo "Below is a backtrace for this process generated with gdb, which shows"
echo "the state of the program at the time the error occured. You are"
echo "encouraged to submit this information as a bug report in the Cherokee"
echo "bug traq system: http://bugs.cherokee-project.com"
echo
echo "Operating System: `uname -a`"
echo "Debugger: $debugger"
echo
# Get the backtrace
if [ x$debugger = x$gdb ]; then
# Use /dev/shm as temp dir
test -d /dev/shm && \
TMPDIR=/dev/shm || \
TMPDIR=/var/tmp
tmp_cmd=`mktemp "$TMPDIR/chrk.XXXXXX"` || (
echo "ERROR: Couldn't create temp file in ${TMPDIR}"
exit 1
)
( echo "set height 0"
echo "print cherokee_version"
echo "thread apply all bt full"
echo "quit" ) >> $tmp_cmd
if [ x$BINARYNAME = x ]; then
$gdb -x $tmp_cmd -batch --pid=$pid
else
$gdb -x $tmp_cmd -batch "$BINARYNAME" "$pid"
fi
rm -f $tmp_cmd
elif [ x$debugger = x$dbx ]; then
#Solaris
echo "Related processes were:"
/usr/bin/ptree $pid
echo
echo "Stack(s) were:"
/usr/bin/pstack $pid
echo
echo "Flags were:"
/usr/bin/pflags $pid
echo
echo "Credentials were:"
/usr/bin/pcred $pid
echo
echo "Libraries used were:"
/usr/bin/pldd $pid
echo
echo "Signal-handler settings were:"
/usr/bin/psig $pid
echo
echo "Files and devices in use were:"
/usr/bin/pfiles $pid
echo
echo "Directory in use was:"
/usr/bin/pwdx $pid
echo
echo "Backtrace"
$dbx -c "print (char *)cherokee_version; where -v -l ; quit" "$BINARYNAME" "$pid"
echo
fi
) | (
case "$action" in
mail)
/usr/sbin/sendmail -t
;;
stdout)
cat -
;;
*)
echo "ERROR: Wrong action: \"$action\""
exit 1
esac;
)