The branch, master has been updated via 6e8b635 fault: fixed smb_panic() prototypes via 43a0762 fault: fixed call to fault_setup() to use new syntax via a65ba83 fault: moved fault.c into common library via 1ac079e fault: switch s4 to use the common fault.c via 580997e fault: get fault.c ready for use by s4 via 058c3bb fault: moved s3 fault.c to top level via cb2cc34 fault: rename fault.c to fault_s4.c from cfae1e7 s3:WHATSNEW: document changes of the id mapping system
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 6e8b6358ecc7dbebe9681d8e906f82993d0465df Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:37:54 2011 +1100 fault: fixed smb_panic() prototypes Autobuild-User: Andrew Tridgell <tri...@samba.org> Autobuild-Date: Wed Mar 23 01:51:44 CET 2011 on sn-devel-104 commit 43a07621bb26c1b6dbe8cfd848dd4d4863ca92b9 Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:30:36 2011 +1100 fault: fixed call to fault_setup() to use new syntax commit a65ba83ae6324ed1cbd81c81ddda7a60973aead7 Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:30:19 2011 +1100 fault: moved fault.c into common library commit 1ac079e3f6aa9fbbf904e9bdeab557f66487790d Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:27:40 2011 +1100 fault: switch s4 to use the common fault.c commit 580997ede06d587ecf00c6a3faff237806904cd3 Author: Andrew Tridgell <tri...@samba.org> Date: Tue Mar 22 16:17:39 2011 +1100 fault: get fault.c ready for use by s4 this moves the s3 specific dumpcore code into source3/lib/dumpcore.c, and uses a function pointer to setup which smb_panic call to use commit 058c3bb923c51ef3f1b4b6d698bea2b1220bdd10 Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:25:01 2011 +1100 fault: moved s3 fault.c to top level commit cb2cc34effedca2af4e9f6d57303ccc779a9cc04 Author: Andrew Tridgell <tri...@samba.org> Date: Wed Mar 23 10:22:15 2011 +1100 fault: rename fault.c to fault_s4.c this is in preparation for merging the s3 fault code into common ----------------------------------------------------------------------- Summary of changes: lib/util/fault.c | 248 ++++++++++++----------------------- lib/util/util.h | 13 +- lib/util/wscript_build | 4 +- source3/Makefile.in | 4 +- source3/include/includes.h | 1 - source3/include/proto.h | 6 +- source3/lib/{fault.c => dumpcore.c} | 85 +++---------- source3/lib/util.c | 2 +- source3/nmbd/nmbd.c | 2 +- source3/param/loadparm.c | 2 + source3/smbd/server.c | 2 +- source3/winbindd/winbindd.c | 2 +- source3/wscript_build | 3 +- source4/lib/cmdline/popt_common.c | 2 +- 14 files changed, 121 insertions(+), 255 deletions(-) rename source3/lib/{fault.c => dumpcore.c} (81%) Changeset truncated at 500 lines: diff --git a/lib/util/fault.c b/lib/util/fault.c index 29b45ee..086dc33 100644 --- a/lib/util/fault.c +++ b/lib/util/fault.c @@ -1,196 +1,101 @@ -/* +/* Unix SMB/CIFS implementation. Critical Fault handling Copyright (C) Andrew Tridgell 1992-1998 - + Copyright (C) Tim Prouty 2009 + 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 3 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, see <http://www.gnu.org/licenses/>. */ #include "includes.h" -#include "version.h" -#include "system/wait.h" #include "system/filesys.h" +#include "version.h" -/** - * @file - * @brief Fault handling - */ - -/* the registered fault handler */ -static struct { - const char *name; - void (*fault_handler)(int sig); -} fault_handlers; - -static const char *progname; - -#ifdef HAVE_BACKTRACE -#include <execinfo.h> -#elif HAVE_LIBEXC_H -#include <libexc.h> -#endif - -/** - * Write backtrace to debug log - */ -_PUBLIC_ void call_backtrace(void) -{ -#ifdef HAVE_BACKTRACE -#ifndef BACKTRACE_STACK_SIZE -#define BACKTRACE_STACK_SIZE 64 +#ifdef HAVE_SYS_SYSCTL_H +#include <sys/sysctl.h> #endif - void *backtrace_stack[BACKTRACE_STACK_SIZE]; - int 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 */ - } +#ifdef HAVE_SYS_PRCTL_H +#include <sys/prctl.h> +#endif -#elif HAVE_LIBEXC +static struct { + bool disabled; + smb_panic_handler_t panic_handler; +} fault_state; -#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 - * 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 +/******************************************************************* +setup variables used for fault handling +********************************************************************/ +void fault_configure(smb_panic_handler_t panic_handler) +{ + fault_state.panic_handler = panic_handler; } -_PUBLIC_ const char *panic_action = NULL; /** - Something really nasty happened - panic ! + disable setting up fault handlers + This is used for the bind9 dlz module, as we + don't want a Samba module in bind9 to override the bind + fault handling **/ -_PUBLIC_ _NORETURN_ void smb_panic(const char *why) +_PUBLIC_ void fault_setup_disable(void) { - int result; - - if (panic_action && *panic_action) { - char pidstr[20]; - char cmdstring[200]; - safe_strcpy(cmdstring, panic_action, sizeof(cmdstring)); - snprintf(pidstr, sizeof(pidstr), "%d", (int) 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, SIG_DFL); -#endif - abort(); + fault_state.disabled = true; } -/** + +/******************************************************************* report a fault -**/ -_NORETURN_ static void fault_report(int sig) +********************************************************************/ +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")); + counter++; + + DEBUGSEP(0); + DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),SAMBA_VERSION_STRING)); + DEBUG(0,("\nPlease read the Trouble-Shooting section of the Samba HOWTO\n")); + DEBUGSEP(0); smb_panic("internal error"); + /* smb_panic() never returns, so this is really redundent */ exit(1); } -/** +/**************************************************************************** catch serious errors -**/ -_NORETURN_ static void sig_fault(int sig) +****************************************************************************/ +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 doesn't exist, use regular reporter */ fault_report(sig); } -/** +/******************************************************************* setup our fault handlers -**/ -_PUBLIC_ void fault_setup(const char *pname) +********************************************************************/ +void fault_setup(void) { - if (progname != NULL) { + if (fault_state.disabled) { return; } - progname = pname; #ifdef SIGSEGV CatchSignal(SIGSEGV, sig_fault); #endif @@ -200,37 +105,50 @@ _PUBLIC_ void fault_setup(const char *pname) #ifdef SIGABRT CatchSignal(SIGABRT, sig_fault); #endif -#ifdef SIGFPE - CatchSignal(SIGFPE, sig_fault); -#endif } -/** - disable setting up fault handlers -**/ -_PUBLIC_ void fault_setup_disable(void) +_PUBLIC_ const char *panic_action = NULL; + +/* + default smb_panic() implementation +*/ +static void smb_panic_default(const char *why) { - progname = "fault disabled"; + int result; + + if (panic_action && *panic_action) { + char pidstr[20]; + char cmdstring[200]; + safe_strcpy(cmdstring, panic_action, sizeof(cmdstring)-1); + snprintf(pidstr, sizeof(pidstr), "%d", (int) getpid()); + all_string_sub(cmdstring, "%PID%", pidstr, 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)); + +#ifdef SIGABRT + CatchSignal(SIGABRT, SIG_DFL); +#endif + abort(); } /** - 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)) + Something really nasty happened - panic ! +**/ +_PUBLIC_ void smb_panic(const char *why) { - 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; + if (fault_state.panic_handler) { + fault_state.panic_handler(why); + _exit(1); } - - fault_handlers.name = name; - fault_handlers.fault_handler = fault_handler; - - DEBUG(2,("fault handler '%s' registered\n", name)); - return true; + smb_panic_default(why); } diff --git a/lib/util/util.h b/lib/util/util.h index 78071ad..58e6ffd 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -71,15 +71,14 @@ _PUBLIC_ void call_backtrace(void); /** Something really nasty happened - panic ! **/ -_PUBLIC_ _NORETURN_ void smb_panic(const char *why); +typedef void (*smb_panic_handler_t)(const char *why); -#if _SAMBA_BUILD_ == 4 -/** -setup our fault handlers -**/ -_PUBLIC_ void fault_setup(const char *pname); +_PUBLIC_ void fault_configure(smb_panic_handler_t panic_handler); +_PUBLIC_ void fault_setup(void); _PUBLIC_ void fault_setup_disable(void); -#endif +_PUBLIC_ void dump_core_setup(const char *progname, const char *logfile); +_PUBLIC_ void smb_panic(const char *reason); + /** register a fault handler. diff --git a/lib/util/wscript_build b/lib/util/wscript_build index 7c18075..7f5b1d2 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -7,7 +7,7 @@ bld.SAMBA_LIBRARY('samba-util-common', util_file.c time.c rbtree.c rfc1738.c select.c genrand.c fsusage.c blocking.c become_daemon.c signal.c system.c params.c util.c util_id.c util_net.c - util_strlist.c idtree.c debug.c''', + util_strlist.c idtree.c debug.c fault.c''', public_deps='talloc pthread LIBCRYPTO', # until we get all the dependencies in this library in common # we need to allow this library to be built with unresolved symbols @@ -20,7 +20,7 @@ bld.SAMBA_LIBRARY('samba-util-common', if bld.env._SAMBA_BUILD_ == 4: bld.SAMBA_LIBRARY('samba-util', - source='''dprintf.c fault.c data_blob.c + source='''dprintf.c data_blob.c ms_fnmatch.c parmlist.c substitute.c util_str.c ''', deps='samba-util-common', diff --git a/source3/Makefile.in b/source3/Makefile.in index 05f1ccd..065f0cb 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -442,8 +442,8 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \ lib/util_transfer_file.o ../lib/async_req/async_sock.o \ lib/addrchange.o \ $(TDB_LIB_OBJ) \ - $(VERSION_OBJ) lib/charcnv.o ../lib/util/debug.o ../lib/util/debug_s3.o lib/fault.o \ - lib/interface.o lib/pidfile.o \ + $(VERSION_OBJ) lib/charcnv.o ../lib/util/debug.o ../lib/util/debug_s3.o ../lib/util/fault.o \ + lib/interface.o lib/pidfile.o lib/dumpcore.o \ lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \ lib/username.o \ ../libds/common/flag_mapping.o \ diff --git a/source3/include/includes.h b/source3/include/includes.h index cda366f..b1b5dad 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -758,7 +758,6 @@ ssize_t readahead(int fd, off64_t offset, size_t count); #define CONST_DISCARD(type, ptr) ((type) ((void *) (ptr))) #endif -void smb_panic( const char *why ) _NORETURN_; void dump_core(void) _NORETURN_; void exit_server(const char *const reason) _NORETURN_; void exit_server_cleanly(const char *const reason) _NORETURN_; diff --git a/source3/include/proto.h b/source3/include/proto.h index b5b35a4..bb9241c 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -515,10 +515,6 @@ void display_set_stderr(void); NTSTATUS map_nt_error_from_unix(int unix_error); int map_errno_from_nt_status(NTSTATUS status); -/* The following definitions come from lib/fault.c */ -void fault_setup(void); -void dump_core_setup(const char *progname); - /* The following definitions come from lib/file_id.c */ struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf); @@ -1095,7 +1091,7 @@ const char *uidtoname(uid_t uid); char *gidtoname(gid_t gid); uid_t nametouid(const char *name); gid_t nametogid(const char *name); -void smb_panic(const char *const why); +void smb_panic_s3(const char *why); void log_stack_trace(void); const char *readdirname(SMB_STRUCT_DIR *p); bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensitive); diff --git a/source3/lib/fault.c b/source3/lib/dumpcore.c similarity index 81% rename from source3/lib/fault.c rename to source3/lib/dumpcore.c index 8bb2020..8a1c43a 100644 --- a/source3/lib/fault.c +++ b/source3/lib/dumpcore.c @@ -1,83 +1,34 @@ -/* +/* Unix SMB/CIFS implementation. - Critical Fault handling - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Tim Prouty 2009 - + Samba utility functions + + Copyright (C) Andrew Tridgell 1992-2011 + + based on old fault.c code, which had: + + Copyright (C) Jeremy Allison 2001-2007 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough <j...@us.ibm.com> 2003 + Copyright (C) James Peach 2006 + 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 3 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, see <http://www.gnu.org/licenses/>. */ #include "includes.h" -#ifdef HAVE_SYS_SYSCTL_H -#include <sys/sysctl.h> -#endif - - -#ifdef HAVE_SYS_PRCTL_H -#include <sys/prctl.h> -#endif - static char *corepath; -/******************************************************************* -report a fault -********************************************************************/ -static void fault_report(int sig) -{ - static int counter; - - if (counter) _exit(1); - - counter++; - - DEBUGSEP(0); - DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),samba_version_string())); - DEBUG(0,("\nPlease read the Trouble-Shooting section of the Samba3-HOWTO\n")); - DEBUG(0,("\nFrom: http://www.samba.org/samba/docs/Samba3-HOWTO.pdf\n")); - DEBUGSEP(0); - - smb_panic("internal error"); - - /* smb_panic() never returns, so this is really redundent */ - exit(1); -} - -/**************************************************************************** -- Samba Shared Repository