Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header.
[samba.git] / source3 / lib / fault.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Critical Fault handling
5    Copyright (C) Andrew Tridgell 1992-1998
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 static void (*cont_fn)(void *);
25
26 /*******************************************************************
27 report a fault
28 ********************************************************************/
29 static void fault_report(int sig)
30 {
31         static int counter;
32
33         if (counter) _exit(1);
34
35         counter++;
36
37         DEBUG(0,("===============================================================\n"));
38         DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),VERSION));
39         DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n"));
40         DEBUG(0,("===============================================================\n"));
41   
42         smb_panic("internal error");
43
44         if (cont_fn) {
45                 cont_fn(NULL);
46 #ifdef SIGSEGV
47                 CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
48 #endif
49 #ifdef SIGBUS
50                 CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
51 #endif
52                 return; /* this should cause a core dump */
53         }
54         exit(1);
55 }
56
57 /****************************************************************************
58 catch serious errors
59 ****************************************************************************/
60 static void sig_fault(int sig)
61 {
62         fault_report(sig);
63 }
64
65 /*******************************************************************
66 setup our fault handlers
67 ********************************************************************/
68 void fault_setup(void (*fn)(void *))
69 {
70         cont_fn = fn;
71
72 #ifdef SIGSEGV
73         CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault);
74 #endif
75 #ifdef SIGBUS
76         CatchSignal(SIGBUS,SIGNAL_CAST sig_fault);
77 #endif
78 }
79
80
81