1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * sigcatcher.c --- print a backtrace on a SIGSEGV, et. al
3*6a54128fSAndroid Build Coastguard Worker *
4*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 2011 Theodore Ts'o.
5*6a54128fSAndroid Build Coastguard Worker *
6*6a54128fSAndroid Build Coastguard Worker * %Begin-Header%
7*6a54128fSAndroid Build Coastguard Worker * This file may be redistributed under the terms of the GNU Public
8*6a54128fSAndroid Build Coastguard Worker * License.
9*6a54128fSAndroid Build Coastguard Worker * %End-Header%
10*6a54128fSAndroid Build Coastguard Worker */
11*6a54128fSAndroid Build Coastguard Worker
12*6a54128fSAndroid Build Coastguard Worker #include "config.h"
13*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
14*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
15*6a54128fSAndroid Build Coastguard Worker #include <signal.h>
16*6a54128fSAndroid Build Coastguard Worker #include <string.h>
17*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_EXECINFO_H
18*6a54128fSAndroid Build Coastguard Worker #include <execinfo.h>
19*6a54128fSAndroid Build Coastguard Worker #endif
20*6a54128fSAndroid Build Coastguard Worker
21*6a54128fSAndroid Build Coastguard Worker #include "e2fsck.h"
22*6a54128fSAndroid Build Coastguard Worker
23*6a54128fSAndroid Build Coastguard Worker struct str_table {
24*6a54128fSAndroid Build Coastguard Worker int num;
25*6a54128fSAndroid Build Coastguard Worker const char *name;
26*6a54128fSAndroid Build Coastguard Worker };
27*6a54128fSAndroid Build Coastguard Worker
28*6a54128fSAndroid Build Coastguard Worker #define DEFINE_ENTRY(SYM) { SYM, #SYM },
29*6a54128fSAndroid Build Coastguard Worker #define END_TABLE { 0, 0 }
30*6a54128fSAndroid Build Coastguard Worker
31*6a54128fSAndroid Build Coastguard Worker static struct str_table sig_table[] = {
32*6a54128fSAndroid Build Coastguard Worker #ifdef SIGHUP
33*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGHUP)
34*6a54128fSAndroid Build Coastguard Worker #endif
35*6a54128fSAndroid Build Coastguard Worker #ifdef SIGINT
36*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGINT)
37*6a54128fSAndroid Build Coastguard Worker #endif
38*6a54128fSAndroid Build Coastguard Worker #ifdef SIGQUIT
39*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGQUIT)
40*6a54128fSAndroid Build Coastguard Worker #endif
41*6a54128fSAndroid Build Coastguard Worker #ifdef SIGILL
42*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGILL)
43*6a54128fSAndroid Build Coastguard Worker #endif
44*6a54128fSAndroid Build Coastguard Worker #ifdef SIGTRAP
45*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGTRAP)
46*6a54128fSAndroid Build Coastguard Worker #endif
47*6a54128fSAndroid Build Coastguard Worker #ifdef SIGABRT
48*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGABRT)
49*6a54128fSAndroid Build Coastguard Worker #endif
50*6a54128fSAndroid Build Coastguard Worker #ifdef SIGIOT
51*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGIOT)
52*6a54128fSAndroid Build Coastguard Worker #endif
53*6a54128fSAndroid Build Coastguard Worker #ifdef SIGBUS
54*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGBUS)
55*6a54128fSAndroid Build Coastguard Worker #endif
56*6a54128fSAndroid Build Coastguard Worker #ifdef SIGFPE
57*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGFPE)
58*6a54128fSAndroid Build Coastguard Worker #endif
59*6a54128fSAndroid Build Coastguard Worker #ifdef SIGKILL
60*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGKILL)
61*6a54128fSAndroid Build Coastguard Worker #endif
62*6a54128fSAndroid Build Coastguard Worker #ifdef SIGUSR1
63*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGUSR1)
64*6a54128fSAndroid Build Coastguard Worker #endif
65*6a54128fSAndroid Build Coastguard Worker #ifdef SIGSEGV
66*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGSEGV)
67*6a54128fSAndroid Build Coastguard Worker #endif
68*6a54128fSAndroid Build Coastguard Worker #ifdef SIGUSR2
69*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGUSR2)
70*6a54128fSAndroid Build Coastguard Worker #endif
71*6a54128fSAndroid Build Coastguard Worker #ifdef SIGPIPE
72*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGPIPE)
73*6a54128fSAndroid Build Coastguard Worker #endif
74*6a54128fSAndroid Build Coastguard Worker #ifdef SIGALRM
75*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGALRM)
76*6a54128fSAndroid Build Coastguard Worker #endif
77*6a54128fSAndroid Build Coastguard Worker #ifdef SIGTERM
78*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGTERM)
79*6a54128fSAndroid Build Coastguard Worker #endif
80*6a54128fSAndroid Build Coastguard Worker #ifdef SIGSTKFLT
81*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGSTKFLT)
82*6a54128fSAndroid Build Coastguard Worker #endif
83*6a54128fSAndroid Build Coastguard Worker #ifdef SIGCHLD
84*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGCHLD)
85*6a54128fSAndroid Build Coastguard Worker #endif
86*6a54128fSAndroid Build Coastguard Worker #ifdef SIGCONT
87*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGCONT)
88*6a54128fSAndroid Build Coastguard Worker #endif
89*6a54128fSAndroid Build Coastguard Worker #ifdef SIGSTOP
90*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGSTOP)
91*6a54128fSAndroid Build Coastguard Worker #endif
92*6a54128fSAndroid Build Coastguard Worker #ifdef SIGTSTP
93*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGTSTP)
94*6a54128fSAndroid Build Coastguard Worker #endif
95*6a54128fSAndroid Build Coastguard Worker #ifdef SIGTTIN
96*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGTTIN)
97*6a54128fSAndroid Build Coastguard Worker #endif
98*6a54128fSAndroid Build Coastguard Worker #ifdef SIGTTOU
99*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGTTOU)
100*6a54128fSAndroid Build Coastguard Worker #endif
101*6a54128fSAndroid Build Coastguard Worker #ifdef SIGURG
102*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGURG)
103*6a54128fSAndroid Build Coastguard Worker #endif
104*6a54128fSAndroid Build Coastguard Worker #ifdef SIGXCPU
105*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGXCPU)
106*6a54128fSAndroid Build Coastguard Worker #endif
107*6a54128fSAndroid Build Coastguard Worker #ifdef SIGXFSZ
108*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGXFSZ)
109*6a54128fSAndroid Build Coastguard Worker #endif
110*6a54128fSAndroid Build Coastguard Worker #ifdef SIGVTALRM
111*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGVTALRM)
112*6a54128fSAndroid Build Coastguard Worker #endif
113*6a54128fSAndroid Build Coastguard Worker #ifdef SIGPROF
114*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGPROF)
115*6a54128fSAndroid Build Coastguard Worker #endif
116*6a54128fSAndroid Build Coastguard Worker #ifdef SIGWINCH
117*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGWINCH)
118*6a54128fSAndroid Build Coastguard Worker #endif
119*6a54128fSAndroid Build Coastguard Worker #ifdef SIGIO
120*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGIO)
121*6a54128fSAndroid Build Coastguard Worker #endif
122*6a54128fSAndroid Build Coastguard Worker #ifdef SIGPOLL
123*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGPOLL)
124*6a54128fSAndroid Build Coastguard Worker #endif
125*6a54128fSAndroid Build Coastguard Worker #ifdef SIGPWR
126*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGPWR)
127*6a54128fSAndroid Build Coastguard Worker #endif
128*6a54128fSAndroid Build Coastguard Worker #ifdef SIGSYS
129*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SIGSYS)
130*6a54128fSAndroid Build Coastguard Worker #endif
131*6a54128fSAndroid Build Coastguard Worker END_TABLE
132*6a54128fSAndroid Build Coastguard Worker };
133*6a54128fSAndroid Build Coastguard Worker
134*6a54128fSAndroid Build Coastguard Worker static struct str_table generic_code_table[] = {
135*6a54128fSAndroid Build Coastguard Worker #ifdef SI_ASYNCNL
136*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_ASYNCNL)
137*6a54128fSAndroid Build Coastguard Worker #endif
138*6a54128fSAndroid Build Coastguard Worker #ifdef SI_TKILL
139*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_TKILL)
140*6a54128fSAndroid Build Coastguard Worker #endif
141*6a54128fSAndroid Build Coastguard Worker #ifdef SI_SIGIO
142*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_SIGIO)
143*6a54128fSAndroid Build Coastguard Worker #endif
144*6a54128fSAndroid Build Coastguard Worker #ifdef SI_ASYNCIO
145*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_ASYNCIO)
146*6a54128fSAndroid Build Coastguard Worker #endif
147*6a54128fSAndroid Build Coastguard Worker #ifdef SI_MESGQ
148*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_MESGQ)
149*6a54128fSAndroid Build Coastguard Worker #endif
150*6a54128fSAndroid Build Coastguard Worker #ifdef SI_TIMER
151*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_TIMER)
152*6a54128fSAndroid Build Coastguard Worker #endif
153*6a54128fSAndroid Build Coastguard Worker #ifdef SI_QUEUE
154*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_QUEUE)
155*6a54128fSAndroid Build Coastguard Worker #endif
156*6a54128fSAndroid Build Coastguard Worker #ifdef SI_USER
157*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_USER)
158*6a54128fSAndroid Build Coastguard Worker #endif
159*6a54128fSAndroid Build Coastguard Worker #ifdef SI_KERNEL
160*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SI_KERNEL)
161*6a54128fSAndroid Build Coastguard Worker #endif
162*6a54128fSAndroid Build Coastguard Worker END_TABLE
163*6a54128fSAndroid Build Coastguard Worker };
164*6a54128fSAndroid Build Coastguard Worker
165*6a54128fSAndroid Build Coastguard Worker static struct str_table sigill_code_table[] = {
166*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_ILLOPC
167*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_ILLOPC)
168*6a54128fSAndroid Build Coastguard Worker #endif
169*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_ILLOPN
170*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_ILLOPN)
171*6a54128fSAndroid Build Coastguard Worker #endif
172*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_ILLADR
173*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_ILLADR)
174*6a54128fSAndroid Build Coastguard Worker #endif
175*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_ILLTRP
176*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_ILLTRP)
177*6a54128fSAndroid Build Coastguard Worker #endif
178*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_PRVOPC
179*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_PRVOPC)
180*6a54128fSAndroid Build Coastguard Worker #endif
181*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_PRVREG
182*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_PRVREG)
183*6a54128fSAndroid Build Coastguard Worker #endif
184*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_COPROC
185*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_COPROC)
186*6a54128fSAndroid Build Coastguard Worker #endif
187*6a54128fSAndroid Build Coastguard Worker #ifdef ILL_BADSTK
188*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(ILL_BADSTK)
189*6a54128fSAndroid Build Coastguard Worker #endif
190*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_ADRALN
191*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_ADRALN)
192*6a54128fSAndroid Build Coastguard Worker #endif
193*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_ADRERR
194*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_ADRERR)
195*6a54128fSAndroid Build Coastguard Worker #endif
196*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_OBJERR
197*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_OBJERR)
198*6a54128fSAndroid Build Coastguard Worker #endif
199*6a54128fSAndroid Build Coastguard Worker END_TABLE
200*6a54128fSAndroid Build Coastguard Worker };
201*6a54128fSAndroid Build Coastguard Worker
202*6a54128fSAndroid Build Coastguard Worker static struct str_table sigfpe_code_table[] = {
203*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_INTDIV
204*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_INTDIV)
205*6a54128fSAndroid Build Coastguard Worker #endif
206*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_INTOVF
207*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_INTOVF)
208*6a54128fSAndroid Build Coastguard Worker #endif
209*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTDIV
210*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTDIV)
211*6a54128fSAndroid Build Coastguard Worker #endif
212*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTOVF
213*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTOVF)
214*6a54128fSAndroid Build Coastguard Worker #endif
215*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTUND
216*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTUND)
217*6a54128fSAndroid Build Coastguard Worker #endif
218*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTRES
219*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTRES)
220*6a54128fSAndroid Build Coastguard Worker #endif
221*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTINV
222*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTINV)
223*6a54128fSAndroid Build Coastguard Worker #endif
224*6a54128fSAndroid Build Coastguard Worker #ifdef FPE_FLTSUB
225*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(FPE_FLTSUB)
226*6a54128fSAndroid Build Coastguard Worker #endif
227*6a54128fSAndroid Build Coastguard Worker END_TABLE
228*6a54128fSAndroid Build Coastguard Worker };
229*6a54128fSAndroid Build Coastguard Worker
230*6a54128fSAndroid Build Coastguard Worker static struct str_table sigsegv_code_table[] = {
231*6a54128fSAndroid Build Coastguard Worker #ifdef SEGV_MAPERR
232*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SEGV_MAPERR)
233*6a54128fSAndroid Build Coastguard Worker #endif
234*6a54128fSAndroid Build Coastguard Worker #ifdef SEGV_ACCERR
235*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(SEGV_ACCERR)
236*6a54128fSAndroid Build Coastguard Worker #endif
237*6a54128fSAndroid Build Coastguard Worker END_TABLE
238*6a54128fSAndroid Build Coastguard Worker };
239*6a54128fSAndroid Build Coastguard Worker
240*6a54128fSAndroid Build Coastguard Worker
241*6a54128fSAndroid Build Coastguard Worker static struct str_table sigbus_code_table[] = {
242*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_ADRALN
243*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_ADRALN)
244*6a54128fSAndroid Build Coastguard Worker #endif
245*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_ADRERR
246*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_ADRERR)
247*6a54128fSAndroid Build Coastguard Worker #endif
248*6a54128fSAndroid Build Coastguard Worker #ifdef BUS_OBJERR
249*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(BUS_OBJERR)
250*6a54128fSAndroid Build Coastguard Worker #endif
251*6a54128fSAndroid Build Coastguard Worker END_TABLE
252*6a54128fSAndroid Build Coastguard Worker };
253*6a54128fSAndroid Build Coastguard Worker
254*6a54128fSAndroid Build Coastguard Worker #if 0 /* should this be hooked in somewhere? */
255*6a54128fSAndroid Build Coastguard Worker static struct str_table sigstrap_code_table[] = {
256*6a54128fSAndroid Build Coastguard Worker #ifdef TRAP_BRKPT
257*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(TRAP_BRKPT)
258*6a54128fSAndroid Build Coastguard Worker #endif
259*6a54128fSAndroid Build Coastguard Worker #ifdef TRAP_TRACE
260*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(TRAP_TRACE)
261*6a54128fSAndroid Build Coastguard Worker #endif
262*6a54128fSAndroid Build Coastguard Worker END_TABLE
263*6a54128fSAndroid Build Coastguard Worker };
264*6a54128fSAndroid Build Coastguard Worker #endif
265*6a54128fSAndroid Build Coastguard Worker
266*6a54128fSAndroid Build Coastguard Worker static struct str_table sigcld_code_table[] = {
267*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_EXITED
268*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_EXITED)
269*6a54128fSAndroid Build Coastguard Worker #endif
270*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_KILLED
271*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_KILLED)
272*6a54128fSAndroid Build Coastguard Worker #endif
273*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_DUMPED
274*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_DUMPED)
275*6a54128fSAndroid Build Coastguard Worker #endif
276*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_TRAPPED
277*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_TRAPPED)
278*6a54128fSAndroid Build Coastguard Worker #endif
279*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_STOPPED
280*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_STOPPED)
281*6a54128fSAndroid Build Coastguard Worker #endif
282*6a54128fSAndroid Build Coastguard Worker #ifdef CLD_CONTINUED
283*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(CLD_CONTINUED)
284*6a54128fSAndroid Build Coastguard Worker #endif
285*6a54128fSAndroid Build Coastguard Worker END_TABLE
286*6a54128fSAndroid Build Coastguard Worker };
287*6a54128fSAndroid Build Coastguard Worker
288*6a54128fSAndroid Build Coastguard Worker #if 0 /* should this be hooked in somewhere? */
289*6a54128fSAndroid Build Coastguard Worker static struct str_table sigpoll_code_table[] = {
290*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_IN
291*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_IN)
292*6a54128fSAndroid Build Coastguard Worker #endif
293*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_OUT
294*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_OUT)
295*6a54128fSAndroid Build Coastguard Worker #endif
296*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_MSG
297*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_MSG)
298*6a54128fSAndroid Build Coastguard Worker #endif
299*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_ERR
300*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_ERR)
301*6a54128fSAndroid Build Coastguard Worker #endif
302*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_PRI
303*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_PRI)
304*6a54128fSAndroid Build Coastguard Worker #endif
305*6a54128fSAndroid Build Coastguard Worker #ifdef POLL_HUP
306*6a54128fSAndroid Build Coastguard Worker DEFINE_ENTRY(POLL_HUP)
307*6a54128fSAndroid Build Coastguard Worker #endif
308*6a54128fSAndroid Build Coastguard Worker END_TABLE
309*6a54128fSAndroid Build Coastguard Worker };
310*6a54128fSAndroid Build Coastguard Worker #endif
311*6a54128fSAndroid Build Coastguard Worker
lookup_table(int num,struct str_table * table)312*6a54128fSAndroid Build Coastguard Worker static const char *lookup_table(int num, struct str_table *table)
313*6a54128fSAndroid Build Coastguard Worker {
314*6a54128fSAndroid Build Coastguard Worker struct str_table *p;
315*6a54128fSAndroid Build Coastguard Worker
316*6a54128fSAndroid Build Coastguard Worker for (p=table; p->name; p++)
317*6a54128fSAndroid Build Coastguard Worker if (num == p->num)
318*6a54128fSAndroid Build Coastguard Worker return(p->name);
319*6a54128fSAndroid Build Coastguard Worker return NULL;
320*6a54128fSAndroid Build Coastguard Worker }
321*6a54128fSAndroid Build Coastguard Worker
lookup_table_fallback(int num,struct str_table * table)322*6a54128fSAndroid Build Coastguard Worker static const char *lookup_table_fallback(int num, struct str_table *table)
323*6a54128fSAndroid Build Coastguard Worker {
324*6a54128fSAndroid Build Coastguard Worker static char buf[32];
325*6a54128fSAndroid Build Coastguard Worker const char *ret = lookup_table(num, table);
326*6a54128fSAndroid Build Coastguard Worker
327*6a54128fSAndroid Build Coastguard Worker if (ret)
328*6a54128fSAndroid Build Coastguard Worker return ret;
329*6a54128fSAndroid Build Coastguard Worker snprintf(buf, sizeof(buf), "%d", num);
330*6a54128fSAndroid Build Coastguard Worker buf[sizeof(buf)-1] = 0;
331*6a54128fSAndroid Build Coastguard Worker return buf;
332*6a54128fSAndroid Build Coastguard Worker }
333*6a54128fSAndroid Build Coastguard Worker
die_signal_handler(int signum,siginfo_t * siginfo,void * context EXT2FS_ATTR ((unused)))334*6a54128fSAndroid Build Coastguard Worker static void die_signal_handler(int signum, siginfo_t *siginfo,
335*6a54128fSAndroid Build Coastguard Worker void *context EXT2FS_ATTR((unused)))
336*6a54128fSAndroid Build Coastguard Worker {
337*6a54128fSAndroid Build Coastguard Worker const char *cp;
338*6a54128fSAndroid Build Coastguard Worker
339*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "Signal (%d) %s ", signum,
340*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(signum, sig_table));
341*6a54128fSAndroid Build Coastguard Worker if (siginfo->si_code == SI_USER)
342*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "(sent from pid %u) ", siginfo->si_pid);
343*6a54128fSAndroid Build Coastguard Worker cp = lookup_table(siginfo->si_code, generic_code_table);
344*6a54128fSAndroid Build Coastguard Worker if (cp)
345*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ", cp);
346*6a54128fSAndroid Build Coastguard Worker else if (signum == SIGILL)
347*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ",
348*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(siginfo->si_code,
349*6a54128fSAndroid Build Coastguard Worker sigill_code_table));
350*6a54128fSAndroid Build Coastguard Worker else if (signum == SIGFPE)
351*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ",
352*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(siginfo->si_code,
353*6a54128fSAndroid Build Coastguard Worker sigfpe_code_table));
354*6a54128fSAndroid Build Coastguard Worker else if (signum == SIGSEGV)
355*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ",
356*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(siginfo->si_code,
357*6a54128fSAndroid Build Coastguard Worker sigsegv_code_table));
358*6a54128fSAndroid Build Coastguard Worker else if (signum == SIGBUS)
359*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ",
360*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(siginfo->si_code,
361*6a54128fSAndroid Build Coastguard Worker sigbus_code_table));
362*6a54128fSAndroid Build Coastguard Worker else if (signum == SIGCHLD)
363*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si_code=%s ",
364*6a54128fSAndroid Build Coastguard Worker lookup_table_fallback(siginfo->si_code,
365*6a54128fSAndroid Build Coastguard Worker sigcld_code_table));
366*6a54128fSAndroid Build Coastguard Worker else
367*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "si code=%d ", siginfo->si_code);
368*6a54128fSAndroid Build Coastguard Worker if ((siginfo->si_code != SI_USER) &&
369*6a54128fSAndroid Build Coastguard Worker (signum == SIGILL || signum == SIGFPE ||
370*6a54128fSAndroid Build Coastguard Worker signum == SIGSEGV || signum == SIGBUS))
371*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "fault addr=%p", siginfo->si_addr);
372*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "\n");
373*6a54128fSAndroid Build Coastguard Worker
374*6a54128fSAndroid Build Coastguard Worker #if defined(HAVE_BACKTRACE) && !defined(DISABLE_BACKTRACE)
375*6a54128fSAndroid Build Coastguard Worker {
376*6a54128fSAndroid Build Coastguard Worker void *stack_syms[32];
377*6a54128fSAndroid Build Coastguard Worker int frames;
378*6a54128fSAndroid Build Coastguard Worker
379*6a54128fSAndroid Build Coastguard Worker frames = backtrace(stack_syms, 32);
380*6a54128fSAndroid Build Coastguard Worker backtrace_symbols_fd(stack_syms, frames, 2);
381*6a54128fSAndroid Build Coastguard Worker }
382*6a54128fSAndroid Build Coastguard Worker #endif
383*6a54128fSAndroid Build Coastguard Worker exit(FSCK_ERROR);
384*6a54128fSAndroid Build Coastguard Worker }
385*6a54128fSAndroid Build Coastguard Worker
sigcatcher_setup(void)386*6a54128fSAndroid Build Coastguard Worker void sigcatcher_setup(void)
387*6a54128fSAndroid Build Coastguard Worker {
388*6a54128fSAndroid Build Coastguard Worker struct sigaction sa;
389*6a54128fSAndroid Build Coastguard Worker
390*6a54128fSAndroid Build Coastguard Worker memset(&sa, 0, sizeof(struct sigaction));
391*6a54128fSAndroid Build Coastguard Worker sa.sa_sigaction = die_signal_handler;
392*6a54128fSAndroid Build Coastguard Worker sa.sa_flags = SA_SIGINFO;
393*6a54128fSAndroid Build Coastguard Worker
394*6a54128fSAndroid Build Coastguard Worker sigaction(SIGFPE, &sa, 0);
395*6a54128fSAndroid Build Coastguard Worker sigaction(SIGILL, &sa, 0);
396*6a54128fSAndroid Build Coastguard Worker sigaction(SIGBUS, &sa, 0);
397*6a54128fSAndroid Build Coastguard Worker sigaction(SIGSEGV, &sa, 0);
398*6a54128fSAndroid Build Coastguard Worker sigaction(SIGABRT, &sa, 0);
399*6a54128fSAndroid Build Coastguard Worker }
400*6a54128fSAndroid Build Coastguard Worker
401*6a54128fSAndroid Build Coastguard Worker
402*6a54128fSAndroid Build Coastguard Worker #ifdef DEBUG
403*6a54128fSAndroid Build Coastguard Worker #include <getopt.h>
404*6a54128fSAndroid Build Coastguard Worker
usage(void)405*6a54128fSAndroid Build Coastguard Worker void usage(void)
406*6a54128fSAndroid Build Coastguard Worker {
407*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "tst_sigcatcher: [-akfn]\n");
408*6a54128fSAndroid Build Coastguard Worker exit(1);
409*6a54128fSAndroid Build Coastguard Worker }
410*6a54128fSAndroid Build Coastguard Worker
main(int argc,char ** argv)411*6a54128fSAndroid Build Coastguard Worker int main(int argc, char** argv)
412*6a54128fSAndroid Build Coastguard Worker {
413*6a54128fSAndroid Build Coastguard Worker struct sigaction sa;
414*6a54128fSAndroid Build Coastguard Worker char *p = 0;
415*6a54128fSAndroid Build Coastguard Worker int i, c;
416*6a54128fSAndroid Build Coastguard Worker volatile x=0;
417*6a54128fSAndroid Build Coastguard Worker
418*6a54128fSAndroid Build Coastguard Worker memset(&sa, 0, sizeof(struct sigaction));
419*6a54128fSAndroid Build Coastguard Worker sa.sa_sigaction = die_signal_handler;
420*6a54128fSAndroid Build Coastguard Worker sa.sa_flags = SA_SIGINFO;
421*6a54128fSAndroid Build Coastguard Worker for (i=1; i < 31; i++)
422*6a54128fSAndroid Build Coastguard Worker sigaction(i, &sa, 0);
423*6a54128fSAndroid Build Coastguard Worker
424*6a54128fSAndroid Build Coastguard Worker while ((c = getopt (argc, argv, "afkn")) != EOF)
425*6a54128fSAndroid Build Coastguard Worker switch (c) {
426*6a54128fSAndroid Build Coastguard Worker case 'a':
427*6a54128fSAndroid Build Coastguard Worker abort();
428*6a54128fSAndroid Build Coastguard Worker break;
429*6a54128fSAndroid Build Coastguard Worker case 'f':
430*6a54128fSAndroid Build Coastguard Worker printf("%d\n", 42/x);
431*6a54128fSAndroid Build Coastguard Worker case 'k':
432*6a54128fSAndroid Build Coastguard Worker kill(getpid(), SIGTERM);
433*6a54128fSAndroid Build Coastguard Worker break;
434*6a54128fSAndroid Build Coastguard Worker case 'n':
435*6a54128fSAndroid Build Coastguard Worker *p = 42;
436*6a54128fSAndroid Build Coastguard Worker default:
437*6a54128fSAndroid Build Coastguard Worker usage ();
438*6a54128fSAndroid Build Coastguard Worker }
439*6a54128fSAndroid Build Coastguard Worker
440*6a54128fSAndroid Build Coastguard Worker printf("Sleeping for 10 seconds, send kill signal to pid %u...\n",
441*6a54128fSAndroid Build Coastguard Worker getpid());
442*6a54128fSAndroid Build Coastguard Worker fflush(stdout);
443*6a54128fSAndroid Build Coastguard Worker sleep(10);
444*6a54128fSAndroid Build Coastguard Worker exit(0);
445*6a54128fSAndroid Build Coastguard Worker }
446*6a54128fSAndroid Build Coastguard Worker #endif
447