Initial version imported to CVS
[Samba.git] / source / lib / fault.c
blob20c75f7876c18e15add401c676f2a956c83cf649
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Critical Fault handling
5 Copyright (C) Andrew Tridgell 1992-1995
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.
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.
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.
22 #ifdef LINUX
23 #define __KERNEL__
24 #endif
26 #include "includes.h"
27 extern int DEBUGLEVEL;
30 static void (*cont_fn)();
33 /*******************************************************************
34 report a fault
35 ********************************************************************/
36 static void fault_report(int sig)
38 DEBUG(0,("===============================================================\n"));
39 DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)getpid(),VERSION));
40 DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n"));
41 DEBUG(0,("===============================================================\n"));
43 #if AJT
44 ajt_panic();
45 #endif
47 if (cont_fn)
49 fault_setup(cont_fn);
50 cont_fn(NULL);
51 #ifdef SIGSEGV
52 signal(SIGSEGV,SIGNAL_CAST SIG_DFL);
53 #endif
54 #ifdef SIGBUS
55 signal(SIGBUS,SIGNAL_CAST SIG_DFL);
56 #endif
57 return; /* this should cause a core dump */
59 exit(1);
62 /****************************************************************************
63 catch serious errors
64 ****************************************************************************/
65 static void sig_fault(int sig)
67 fault_report(sig);
70 /*******************************************************************
71 setup our fault handlers
72 ********************************************************************/
73 void fault_setup(void (*fn)())
75 cont_fn = fn;
77 #ifdef SIGSEGV
78 signal(SIGSEGV,SIGNAL_CAST sig_fault);
79 #endif
80 #ifdef SIGBUS
81 signal(SIGBUS,SIGNAL_CAST sig_fault);
82 #endif