add ident to admin checking, and add hope
[fillybot.git] / crash.c
blobe1ea92943c27f8ab0029d66f209faf3f3fa7d617
1 /* addr2line.c -- convert addresses to line number and function name
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Lauther <Ulrich.Lauther@mchp.siemens.de>
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #include "core.h"
25 #include <bfd.h>
27 sigjmp_buf crash_buf;
28 static int crash_nsymbol;
29 static void *crash_pointers[0x100];
30 static char **crash_symbols;
31 static unsigned crash_signal;
33 static void crash_handler(int sig, siginfo_t *si, void *ptr)
35 crash_nsymbol = backtrace(crash_pointers, sizeof(crash_pointers)/sizeof(void*));
36 crash_signal = sig;
37 siglongjmp(crash_buf, sig);
40 void set_signals(unsigned activate)
42 int handle[] = { SIGABRT, SIGSEGV, SIGALRM };
43 static struct sigaction oldsigs[sizeof(handle)/sizeof(*handle)];
44 struct sigaction newsig;
45 int i;
46 newsig.sa_sigaction = crash_handler;
47 sigemptyset(&newsig.sa_mask);
48 newsig.sa_flags = SA_SIGINFO;
49 if (!activate)
50 alarm(0);
51 for (i = 0; i < sizeof(handle)/sizeof(*handle); ++i) {
52 if (activate)
53 sigaction(handle[i], &newsig, oldsigs + i);
54 else
55 sigaction(handle[i], oldsigs+i, NULL);
57 if (activate)
58 alarm(ALARM_TIME);
61 void crash_write_backtrace(struct bio *b, const char *nick)
63 int i;
64 b->writeline(b, "PRIVMSG %s :Signal %i", nick, crash_signal);
65 for (i = 2; i < crash_nsymbol - 1; ++i)
66 b->writeline(b, "PRIVMSG %s :[%i] = %s", nick, i-2, crash_symbols[i]);
69 void crash_mod(struct bio *b, const char *target)
71 if (ponify)
72 b->writeline(b, "PRIVMSG %s :{ Help! A%csistance is required! I believe there is something wrong with me! }", target, crash_signal == 6 ? 'S' : 's');
73 else
74 b->writeline(b, "PRIVMSG %s :Signal %i caught", target, crash_signal);
75 free(crash_symbols);
76 crash_symbols = backtrace_symbols(crash_pointers, crash_nsymbol);
79 void crash_init(void)
83 void crash_fini(void)
85 free(crash_symbols);
86 crash_symbols = NULL;