- added support for TMPDIR env variable
[ira/wip.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-1995
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 extern int DEBUGLEVEL;
24
25
26 static void (*cont_fn)();
27
28
29 /*******************************************************************
30 report a fault
31 ********************************************************************/
32 static void fault_report(int sig)
33 {
34   DEBUG(0,("===============================================================\n"));
35   DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)getpid(),VERSION));
36   DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n"));
37   DEBUG(0,("===============================================================\n"));
38   
39 #if AJT
40   ajt_panic();
41 #endif  
42
43   if (cont_fn)
44     {
45       fault_setup(cont_fn);
46       cont_fn(NULL);
47 #ifdef SIGSEGV
48       signal(SIGSEGV,SIGNAL_CAST SIG_DFL);
49 #endif
50 #ifdef SIGBUS
51       signal(SIGBUS,SIGNAL_CAST SIG_DFL);
52 #endif
53       return; /* this should cause a core dump */
54     }
55   exit(1);
56 }
57
58 /****************************************************************************
59 catch serious errors
60 ****************************************************************************/
61 static void sig_fault(int sig)
62 {
63   fault_report(sig);
64 }
65
66 /*******************************************************************
67 setup our fault handlers
68 ********************************************************************/
69 void fault_setup(void (*fn)())
70 {
71   cont_fn = fn;
72
73 #ifdef SIGSEGV
74   signal(SIGSEGV,SIGNAL_CAST sig_fault);
75 #endif
76 #ifdef SIGBUS
77   signal(SIGBUS,SIGNAL_CAST sig_fault);
78 #endif
79 }
80
81
82