2011-08-12 02:56:49 +08:00
|
|
|
/*
|
|
|
|
* sigcatcher.c --- print a backtrace on a SIGSEGV, et. al
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 05:34:37 +08:00
|
|
|
#include "config.h"
|
2011-08-12 02:56:49 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "e2fsck.h"
|
|
|
|
|
|
|
|
struct str_table {
|
|
|
|
int num;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFINE_ENTRY(SYM) { SYM, #SYM },
|
|
|
|
#define END_TABLE { 0, 0 }
|
|
|
|
|
|
|
|
static struct str_table sig_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef SIGHUP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGHUP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGINT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGQUIT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGILL)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGTRAP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGABRT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGIOT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGBUS)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGFPE)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGKILL)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGUSR1)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGSEGV)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGUSR2)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGPIPE)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGALRM)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGTERM)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTKFLT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGSTKFLT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGCHLD)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGCONT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGSTOP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGTSTP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGTTIN)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGTTOU)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGURG)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGXCPU)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGXFSZ)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGVTALRM)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGPROF)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGWINCH)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGIO)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGPOLL)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGPWR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SIGSYS)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct str_table generic_code_table[] = {
|
2011-10-04 22:36:47 +08:00
|
|
|
#ifdef SI_ASYNCNL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_ASYNCNL)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_TKILL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_TKILL)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_SIGIO
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_SIGIO)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_ASYNCIO
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_ASYNCIO)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_MESGQ
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_MESGQ)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_TIMER
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_TIMER)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_QUEUE
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_QUEUE)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_USER
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_USER)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SI_KERNEL
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SI_KERNEL)
|
2011-10-04 22:36:47 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct str_table sigill_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef ILL_ILLOPC
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_ILLOPC)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_ILLOPN
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_ILLOPN)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_ILLADR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_ILLADR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_ILLTRP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_ILLTRP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_PRVOPC
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_PRVOPC)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_PRVREG
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_PRVREG)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_COPROC
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_COPROC)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_BADSTK
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(ILL_BADSTK)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_ADRALN
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_ADRALN)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_ADRERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_ADRERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_OBJERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_OBJERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct str_table sigfpe_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef FPE_INTDIV
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_INTDIV)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_INTOVF
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_INTOVF)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTDIV
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTDIV)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTOVF
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTOVF)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTUND
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTUND)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTRES
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTRES)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTINV
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTINV)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTSUB
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(FPE_FLTSUB)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct str_table sigsegv_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef SEGV_MAPERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SEGV_MAPERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SEGV_ACCERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(SEGV_ACCERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct str_table sigbus_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef BUS_ADRALN
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_ADRALN)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_ADRERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_ADRERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_OBJERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(BUS_OBJERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
2012-11-29 20:47:53 +08:00
|
|
|
#if 0 /* should this be hooked in somewhere? */
|
2011-08-12 02:56:49 +08:00
|
|
|
static struct str_table sigstrap_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef TRAP_BRKPT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(TRAP_BRKPT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef TRAP_TRACE
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(TRAP_TRACE)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
2012-11-29 20:47:53 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
|
|
|
|
static struct str_table sigcld_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef CLD_EXITED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_EXITED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CLD_KILLED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_KILLED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CLD_DUMPED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_DUMPED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CLD_TRAPPED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_TRAPPED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CLD_STOPPED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_STOPPED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CLD_CONTINUED
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(CLD_CONTINUED)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
|
|
|
|
2012-11-29 20:47:53 +08:00
|
|
|
#if 0 /* should this be hooked in somewhere? */
|
2011-08-12 02:56:49 +08:00
|
|
|
static struct str_table sigpoll_code_table[] = {
|
2011-09-29 10:09:14 +08:00
|
|
|
#ifdef POLL_IN
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_IN)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef POLL_OUT
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_OUT)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef POLL_MSG
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_MSG)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef POLL_ERR
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_ERR)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef POLL_PRI
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_PRI)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
|
|
|
#ifdef POLL_HUP
|
2011-08-12 02:56:49 +08:00
|
|
|
DEFINE_ENTRY(POLL_HUP)
|
2011-09-29 10:09:14 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
END_TABLE
|
|
|
|
};
|
2012-11-29 20:47:53 +08:00
|
|
|
#endif
|
2011-08-12 02:56:49 +08:00
|
|
|
|
|
|
|
static const char *lookup_table(int num, struct str_table *table)
|
|
|
|
{
|
|
|
|
struct str_table *p;
|
|
|
|
|
|
|
|
for (p=table; p->name; p++)
|
|
|
|
if (num == p->num)
|
|
|
|
return(p->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *lookup_table_fallback(int num, struct str_table *table)
|
|
|
|
{
|
|
|
|
static char buf[32];
|
|
|
|
const char *ret = lookup_table(num, table);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
snprintf(buf, sizeof(buf), "%d", num);
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:13:33 +08:00
|
|
|
static void die_signal_handler(int signum, siginfo_t *siginfo,
|
|
|
|
void *context EXT2FS_ATTR((unused)))
|
2011-08-12 02:56:49 +08:00
|
|
|
{
|
|
|
|
void *stack_syms[32];
|
|
|
|
int frames;
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
fprintf(stderr, "Signal (%d) %s ", signum,
|
|
|
|
lookup_table_fallback(signum, sig_table));
|
|
|
|
if (siginfo->si_code == SI_USER)
|
|
|
|
fprintf(stderr, "(sent from pid %u) ", siginfo->si_pid);
|
|
|
|
cp = lookup_table(siginfo->si_code, generic_code_table);
|
|
|
|
if (cp)
|
|
|
|
fprintf(stderr, "si_code=%s ", cp);
|
|
|
|
else if (signum == SIGILL)
|
|
|
|
fprintf(stderr, "si_code=%s ",
|
|
|
|
lookup_table_fallback(siginfo->si_code,
|
|
|
|
sigill_code_table));
|
|
|
|
else if (signum == SIGFPE)
|
|
|
|
fprintf(stderr, "si_code=%s ",
|
|
|
|
lookup_table_fallback(siginfo->si_code,
|
|
|
|
sigfpe_code_table));
|
|
|
|
else if (signum == SIGSEGV)
|
|
|
|
fprintf(stderr, "si_code=%s ",
|
|
|
|
lookup_table_fallback(siginfo->si_code,
|
|
|
|
sigsegv_code_table));
|
|
|
|
else if (signum == SIGBUS)
|
|
|
|
fprintf(stderr, "si_code=%s ",
|
|
|
|
lookup_table_fallback(siginfo->si_code,
|
|
|
|
sigbus_code_table));
|
2011-10-06 02:47:09 +08:00
|
|
|
else if (signum == SIGCHLD)
|
2011-08-12 02:56:49 +08:00
|
|
|
fprintf(stderr, "si_code=%s ",
|
|
|
|
lookup_table_fallback(siginfo->si_code,
|
|
|
|
sigcld_code_table));
|
|
|
|
else
|
|
|
|
fprintf(stderr, "si code=%d ", siginfo->si_code);
|
|
|
|
if ((siginfo->si_code != SI_USER) &&
|
|
|
|
(signum == SIGILL || signum == SIGFPE ||
|
|
|
|
signum == SIGSEGV || signum == SIGBUS))
|
|
|
|
fprintf(stderr, "fault addr=%p", siginfo->si_addr);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
#ifdef HAVE_BACKTRACE
|
|
|
|
frames = backtrace(stack_syms, 32);
|
|
|
|
backtrace_symbols_fd(stack_syms, frames, 2);
|
|
|
|
#endif
|
|
|
|
exit(FSCK_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sigcatcher_setup(void)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
2011-09-03 21:43:50 +08:00
|
|
|
memset(&sa, 0, sizeof(struct sigaction));
|
2011-08-12 02:56:49 +08:00
|
|
|
sa.sa_sigaction = die_signal_handler;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
|
|
|
|
sigaction(SIGFPE, &sa, 0);
|
|
|
|
sigaction(SIGILL, &sa, 0);
|
|
|
|
sigaction(SIGBUS, &sa, 0);
|
|
|
|
sigaction(SIGSEGV, &sa, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
void usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "tst_sigcatcher: [-akfn]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
char *p = 0;
|
|
|
|
int i, c;
|
|
|
|
volatile x=0;
|
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(struct sigaction));
|
|
|
|
sa.sa_sigaction = die_signal_handler;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
for (i=1; i < 31; i++)
|
|
|
|
sigaction(i, &sa, 0);
|
|
|
|
|
|
|
|
while ((c = getopt (argc, argv, "afkn")) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
printf("%d\n", 42/x);
|
|
|
|
case 'k':
|
|
|
|
kill(getpid(), SIGTERM);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
*p = 42;
|
|
|
|
default:
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Sleeping for 10 seconds, send kill signal to pid %u...\n",
|
|
|
|
getpid());
|
|
|
|
fflush(stdout);
|
|
|
|
sleep(10);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#endif
|