r10400: commit merge patch from jra
[Samba/gbeck.git] / source / lib / fault.c
blob3cb66846393c4c51ed61960a21742d6480b35dae
1 /*
2 Unix SMB/CIFS implementation.
3 Critical Fault handling
4 Copyright (C) Andrew Tridgell 1992-1998
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.
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.
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.
21 #include "includes.h"
23 static void (*cont_fn)(void *);
25 /*******************************************************************
26 report a fault
27 ********************************************************************/
28 static void fault_report(int sig)
30 static int counter;
32 if (counter) _exit(1);
34 counter++;
36 DEBUG(0,("===============================================================\n"));
37 DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),SAMBA_VERSION_STRING));
38 DEBUG(0,("\nPlease read the Trouble-Shooting section of the Samba3-HOWTO\n"));
39 DEBUG(0,("\nFrom: http://www.samba.org/samba/docs/Samba3-HOWTO.pdf\n"));
40 DEBUG(0,("===============================================================\n"));
42 smb_panic("internal error");
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 #ifdef SIGABRT
53 CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
54 #endif
55 return; /* this should cause a core dump */
57 exit(1);
60 /****************************************************************************
61 catch serious errors
62 ****************************************************************************/
63 static void sig_fault(int sig)
65 fault_report(sig);
68 /*******************************************************************
69 setup our fault handlers
70 ********************************************************************/
71 void fault_setup(void (*fn)(void *))
73 cont_fn = fn;
75 #ifdef SIGSEGV
76 CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault);
77 #endif
78 #ifdef SIGBUS
79 CatchSignal(SIGBUS,SIGNAL_CAST sig_fault);
80 #endif
81 #ifdef SIGABRT
82 CatchSignal(SIGABRT,SIGNAL_CAST sig_fault);
83 #endif