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.
23
#ifdef HAVE_SYS_PRCTL_H
24
#include <sys/prctl.h>
27
static void (*cont_fn)(void *);
28
static pstring corepath;
30
/*******************************************************************
32
********************************************************************/
33
static void fault_report(int sig)
37
if (counter) _exit(1);
42
DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),SAMBA_VERSION_STRING));
43
DEBUG(0,("\nPlease read the Trouble-Shooting section of the Samba3-HOWTO\n"));
44
DEBUG(0,("\nFrom: http://www.samba.org/samba/docs/Samba3-HOWTO.pdf\n"));
47
smb_panic("internal error");
52
CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
55
CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
58
CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
60
return; /* this should cause a core dump */
65
/****************************************************************************
67
****************************************************************************/
68
static void sig_fault(int sig)
73
/*******************************************************************
74
setup our fault handlers
75
********************************************************************/
76
void fault_setup(void (*fn)(void *))
81
CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault);
84
CatchSignal(SIGBUS,SIGNAL_CAST sig_fault);
87
CatchSignal(SIGABRT,SIGNAL_CAST sig_fault);
91
/*******************************************************************
92
make all the preparations to safely dump a core file
93
********************************************************************/
95
void dump_core_setup(const char *progname)
100
if (lp_logfile() && *lp_logfile()) {
101
snprintf(logbase, sizeof(logbase), "%s", lp_logfile());
102
if ((end = strrchr_m(logbase, '/'))) {
106
/* We will end up here is the log file is given on the command
107
* line by the -l option but the "log file" option is not set
110
snprintf(logbase, sizeof(logbase), "%s", dyn_LOGFILEBASE);
113
SMB_ASSERT(progname != NULL);
115
snprintf(corepath, sizeof(corepath), "%s/cores", logbase);
116
mkdir(corepath,0700);
118
snprintf(corepath, sizeof(corepath), "%s/cores/%s",
120
mkdir(corepath,0700);
122
sys_chown(corepath,getuid(),getgid());
123
chmod(corepath,0700);
125
#ifdef HAVE_GETRLIMIT
129
getrlimit(RLIMIT_CORE, &rlp);
130
rlp.rlim_cur = MAX(16*1024*1024,rlp.rlim_cur);
131
setrlimit(RLIMIT_CORE, &rlp);
132
getrlimit(RLIMIT_CORE, &rlp);
133
DEBUG(3,("Maximum core file size limits now %d(soft) %d(hard)\n",
134
(int)rlp.rlim_cur,(int)rlp.rlim_max));
139
#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
140
/* On Linux we lose the ability to dump core when we change our user
141
* ID. We know how to dump core safely, so let's make sure we have our
144
prctl(PR_SET_DUMPABLE, 1);
147
/* FIXME: if we have a core-plus-pid facility, configurably set
154
/* Note that even if core dumping has been disabled, we still set up
155
* the core path. This is to handle the case where core dumping is
156
* turned on in smb.conf and the relevant daemon is not restarted.
158
if (!lp_enable_core_files()) {
159
DEBUG(0, ("Exiting on internal error (core file administratively disabled\n"));
163
if (*corepath != '\0') {
164
/* The chdir might fail if we dump core before we finish
165
* processing the config file.
167
if (chdir(corepath) != 0) {
168
DEBUG(0, ("unable to change to %s", corepath));
169
DEBUGADD(0, ("refusing to dump core\n"));
173
DEBUG(0,("dumping core in %s\n", corepath));
179
/* Ensure we don't have a signal handler for abort. */
181
CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);