From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/util/fault.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 source4/lib/util/fault.c (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c new file mode 100644 index 0000000000..3670575dcc --- /dev/null +++ b/source4/lib/util/fault.c @@ -0,0 +1,213 @@ +/* + Unix SMB/CIFS implementation. + Critical Fault handling + Copyright (C) Andrew Tridgell 1992-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "version.h" +#include "system/wait.h" +#include "system/filesys.h" + +/* the registered fault handler */ +static struct { + const char *name; + void (*fault_handler)(int sig); +} fault_handlers; + +static const char *progname; + +#ifdef HAVE_BACKTRACE +#include +#define BACKTRACE_STACK_SIZE 64 +#elif HAVE_LIBEXC_H +#include +#endif + +void call_backtrace(void) +{ +#ifdef HAVE_BACKTRACE +#define BACKTRACE_STACK_SIZE 64 + void *backtrace_stack[BACKTRACE_STACK_SIZE]; + size_t backtrace_size; + char **backtrace_strings; + + /* get the backtrace (stack frames) */ + backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE); + backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size); + + DEBUG(0, ("BACKTRACE: %lu stack frames:\n", + (unsigned long)backtrace_size)); + + if (backtrace_strings) { + int i; + + for (i = 0; i < backtrace_size; i++) + DEBUGADD(0, (" #%u %s\n", i, backtrace_strings[i])); + + /* Leak the backtrace_strings, rather than risk what free() might do */ + } + +#elif HAVE_LIBEXC + +#define NAMESIZE 32 /* Arbitrary */ + + /* The IRIX libexc library provides an API for unwinding the stack. See + * libexc(3) for details. Apparantly trace_back_stack leaks memory, but + * since we are about to abort anyway, it hardly matters. + * + * Note that if we paniced due to a SIGSEGV or SIGBUS (or similar) this + * will fail with a nasty message upon failing to open the /proc entry. + */ + { + uint64_t addrs[BACKTRACE_STACK_SIZE]; + char * names[BACKTRACE_STACK_SIZE]; + char namebuf[BACKTRACE_STACK_SIZE * NAMESIZE]; + + int i; + int levels; + + ZERO_ARRAY(addrs); + ZERO_ARRAY(names); + ZERO_ARRAY(namebuf); + + for (i = 0; i < BACKTRACE_STACK_SIZE; i++) { + names[i] = namebuf + (i * NAMESIZE); + } + + levels = trace_back_stack(0, addrs, names, + BACKTRACE_STACK_SIZE, NAMESIZE); + + DEBUG(0, ("BACKTRACE: %d stack frames:\n", levels)); + for (i = 0; i < levels; i++) { + DEBUGADD(0, (" #%d 0x%llx %s\n", i, addrs[i], names[i])); + } + } +#undef NAMESIZE +#endif +} + +/******************************************************************* + Something really nasty happened - panic ! +********************************************************************/ +void smb_panic(const char *why) +{ + const char *cmd = lp_panic_action(); + int result; + + if (cmd && *cmd) { + char pidstr[20]; + char cmdstring[200]; + safe_strcpy(cmdstring, cmd, sizeof(cmdstring)); + snprintf(pidstr, sizeof(pidstr), "%u", getpid()); + all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring)); + if (progname) { + all_string_sub(cmdstring, "%PROG%", progname, sizeof(cmdstring)); + } + DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmdstring)); + result = system(cmdstring); + + if (result == -1) + DEBUG(0, ("smb_panic(): fork failed in panic action: %s\n", + strerror(errno))); + else + DEBUG(0, ("smb_panic(): action returned status %d\n", + WEXITSTATUS(result))); + } + DEBUG(0,("PANIC: %s\n", why)); + + call_backtrace(); + +#ifdef SIGABRT + CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL); +#endif + abort(); +} + +/******************************************************************* +report a fault +********************************************************************/ +static void fault_report(int sig) +{ + static int counter; + + if (counter) _exit(1); + + DEBUG(0,("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n")); + DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)getpid(),SAMBA_VERSION_STRING)); + DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n")); + DEBUG(0,("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n")); + + smb_panic("internal error"); + + exit(1); +} + +/**************************************************************************** +catch serious errors +****************************************************************************/ +static void sig_fault(int sig) +{ + if (fault_handlers.fault_handler) { + /* we have a fault handler, call it. It may not return. */ + fault_handlers.fault_handler(sig); + } + /* If it returns or doean't exist, use regular reporter */ + fault_report(sig); +} + +/******************************************************************* +setup our fault handlers +********************************************************************/ +void fault_setup(const char *pname) +{ + if (progname == NULL) { + progname = pname; + } +#ifdef SIGSEGV + CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGBUS + CatchSignal(SIGBUS,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGABRT + CatchSignal(SIGABRT,SIGNAL_CAST sig_fault); +#endif +#ifdef SIGFPE + CatchSignal(SIGFPE,SIGNAL_CAST sig_fault); +#endif +} + +/* + register a fault handler. + Should only be called once in the execution of smbd. +*/ +BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +{ + if (fault_handlers.name != NULL) { + /* it's already registered! */ + DEBUG(2,("fault handler '%s' already registered - failed '%s'\n", + fault_handlers.name, name)); + return False; + } + + fault_handlers.name = name; + fault_handlers.fault_handler = fault_handler; + + DEBUG(2,("fault handler '%s' registered\n", name)); + return True; +} -- cgit From aa04388943fe5d7d8c873a6ee8a4cc9af2491532 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 28 Feb 2006 13:12:39 +0000 Subject: r13752: Add doxyfile and fix formatting of comments. Current output is available at http://samba.org/~jelmer/util-api/ (This used to be commit 90812203df151a5e62394306827c72adfe13c63c) --- source4/lib/util/fault.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 3670575dcc..abe3f141ce 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -23,6 +23,11 @@ #include "system/wait.h" #include "system/filesys.h" +/** + * @file + * @brief Fault handling + */ + /* the registered fault handler */ static struct { const char *name; @@ -38,6 +43,9 @@ static const char *progname; #include #endif +/** + * Write backtrace to debug log + */ void call_backtrace(void) { #ifdef HAVE_BACKTRACE @@ -101,9 +109,9 @@ void call_backtrace(void) #endif } -/******************************************************************* +/** Something really nasty happened - panic ! -********************************************************************/ +**/ void smb_panic(const char *why) { const char *cmd = lp_panic_action(); @@ -138,9 +146,9 @@ void smb_panic(const char *why) abort(); } -/******************************************************************* +/** report a fault -********************************************************************/ +**/ static void fault_report(int sig) { static int counter; @@ -157,9 +165,9 @@ static void fault_report(int sig) exit(1); } -/**************************************************************************** +/** catch serious errors -****************************************************************************/ +**/ static void sig_fault(int sig) { if (fault_handlers.fault_handler) { @@ -170,9 +178,9 @@ static void sig_fault(int sig) fault_report(sig); } -/******************************************************************* +/** setup our fault handlers -********************************************************************/ +**/ void fault_setup(const char *pname) { if (progname == NULL) { @@ -192,7 +200,7 @@ void fault_setup(const char *pname) #endif } -/* +/** register a fault handler. Should only be called once in the execution of smbd. */ -- cgit From af30a32b6924b0f2b701186e435defbca2ebd1aa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:15:19 +0000 Subject: r13840: Mark some functions as public. (This used to be commit 9a188eb1f48a50d92a67a4fc2b3899b90074059a) --- source4/lib/util/fault.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index abe3f141ce..ff44b8a292 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -46,7 +46,7 @@ static const char *progname; /** * Write backtrace to debug log */ -void call_backtrace(void) +_PUBLIC_ void call_backtrace(void) { #ifdef HAVE_BACKTRACE #define BACKTRACE_STACK_SIZE 64 @@ -112,7 +112,7 @@ void call_backtrace(void) /** Something really nasty happened - panic ! **/ -void smb_panic(const char *why) +_PUBLIC_ void smb_panic(const char *why) { const char *cmd = lp_panic_action(); int result; @@ -181,7 +181,7 @@ static void sig_fault(int sig) /** setup our fault handlers **/ -void fault_setup(const char *pname) +_PUBLIC_ void fault_setup(const char *pname) { if (progname == NULL) { progname = pname; @@ -204,7 +204,7 @@ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ -- cgit From 18cddd580e04344e05593d9f63beb9ead53cfab2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Mar 2006 00:28:12 +0000 Subject: r14575: Move some path-related functions to libsamba-config so libsamba-util doesn't have to depend on the lp_* functions. (This used to be commit f97df7d90a41b77a9edd2d6bdc47c27bf1b6bb07) --- source4/lib/util/fault.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index ff44b8a292..8b447851dc 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -109,18 +109,19 @@ _PUBLIC_ void call_backtrace(void) #endif } +_PUBLIC_ const char *panic_action = NULL; + /** Something really nasty happened - panic ! **/ _PUBLIC_ void smb_panic(const char *why) { - const char *cmd = lp_panic_action(); int result; - if (cmd && *cmd) { + if (panic_action && *panic_action) { char pidstr[20]; char cmdstring[200]; - safe_strcpy(cmdstring, cmd, sizeof(cmdstring)); + safe_strcpy(cmdstring, panic_action, sizeof(cmdstring)); snprintf(pidstr, sizeof(pidstr), "%u", getpid()); all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring)); if (progname) { -- cgit From a485fa050c1b210847bb4867ade25afc5ca941c7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 09:49:09 +0000 Subject: r17783: fix compiler warnings metze (This used to be commit c999dd02100e59bfd34585850c354ac2e9708cbb) --- source4/lib/util/fault.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 8b447851dc..c7d6b7ede6 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -38,7 +38,6 @@ static const char *progname; #ifdef HAVE_BACKTRACE #include -#define BACKTRACE_STACK_SIZE 64 #elif HAVE_LIBEXC_H #include #endif @@ -49,7 +48,9 @@ static const char *progname; _PUBLIC_ void call_backtrace(void) { #ifdef HAVE_BACKTRACE +#ifndef BACKTRACE_STACK_SIZE #define BACKTRACE_STACK_SIZE 64 +#endif void *backtrace_stack[BACKTRACE_STACK_SIZE]; size_t backtrace_size; char **backtrace_strings; @@ -73,6 +74,9 @@ _PUBLIC_ void call_backtrace(void) #elif HAVE_LIBEXC #define NAMESIZE 32 /* Arbitrary */ +#ifndef BACKTRACE_STACK_SIZE +#define BACKTRACE_STACK_SIZE 64 +#endif /* The IRIX libexc library provides an API for unwinding the stack. See * libexc(3) for details. Apparantly trace_back_stack leaks memory, but -- cgit From c2781df0d5477be58c3189c6d3c17b261d7b8b89 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 1 Jun 2007 12:01:53 +0000 Subject: r23289: Provide support for GCC attributes _PURE_, _NONNULL_, _DEPRECATED_, _NORETURN_ and _WARN_UNUSED_RESULT_. (This used to be commit 44248f662f0b609dad6a7b437948f12d661a28f7) --- source4/lib/util/fault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index c7d6b7ede6..86a0b61a76 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -118,7 +118,7 @@ _PUBLIC_ const char *panic_action = NULL; /** Something really nasty happened - panic ! **/ -_PUBLIC_ void smb_panic(const char *why) +_PUBLIC_ _NORETURN_ void smb_panic(const char *why) { int result; -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/fault.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 86a0b61a76..8bfcdff0d1 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 4fb038b0b8e7a4bb69ac0d9022684eeaca8a491a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 17:21:16 +0000 Subject: r24710: Use standard boolean type for easier use by external users. (This used to be commit 99f4124137d4a61216e8189f26d4da32882c0f4a) --- source4/lib/util/fault.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 8bfcdff0d1..5cc9445407 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -208,18 +208,18 @@ _PUBLIC_ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -_PUBLIC_ BOOL register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ bool register_fault_handler(const char *name, void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ DEBUG(2,("fault handler '%s' already registered - failed '%s'\n", fault_handlers.name, name)); - return False; + return false; } fault_handlers.name = name; fault_handlers.fault_handler = fault_handler; DEBUG(2,("fault handler '%s' registered\n", name)); - return True; + return true; } -- cgit From cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/lib/util/fault.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index 5cc9445407..e9cd040ee6 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -153,7 +153,7 @@ _PUBLIC_ _NORETURN_ void smb_panic(const char *why) /** report a fault **/ -static void fault_report(int sig) +_NORETURN_ static void fault_report(int sig) { static int counter; @@ -172,7 +172,7 @@ static void fault_report(int sig) /** catch serious errors **/ -static void sig_fault(int sig) +_NORETURN_ static void sig_fault(int sig) { if (fault_handlers.fault_handler) { /* we have a fault handler, call it. It may not return. */ -- cgit From f26222df4db2055d267789655a7113a49c178071 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 Oct 2007 12:52:32 +0200 Subject: r25626: Move some debug-specific prototypes to debug.h. (This used to be commit 84a202754004ec618aa2663a4614d80eb2c7ce60) --- source4/lib/util/fault.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index e9cd040ee6..cd347a5ef9 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -208,7 +208,8 @@ _PUBLIC_ void fault_setup(const char *pname) register a fault handler. Should only be called once in the execution of smbd. */ -_PUBLIC_ bool register_fault_handler(const char *name, void (*fault_handler)(int sig)) +_PUBLIC_ bool register_fault_handler(const char *name, + void (*fault_handler)(int sig)) { if (fault_handlers.name != NULL) { /* it's already registered! */ -- cgit From e0a5fb8a9be9f3002d6f73c272793a75fa71d313 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Feb 2008 12:39:47 +0100 Subject: Fix typo. (This used to be commit 54e7d10fe0eb4837b00b9b049fbd59a56ee85bea) --- source4/lib/util/fault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/fault.c') diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index cd347a5ef9..cb51cbd859 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -178,7 +178,7 @@ _NORETURN_ static void sig_fault(int sig) /* we have a fault handler, call it. It may not return. */ fault_handlers.fault_handler(sig); } - /* If it returns or doean't exist, use regular reporter */ + /* If it returns or doesn't exist, use regular reporter */ fault_report(sig); } -- cgit