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