diff options
author | Mathias Stearn <mathias@10gen.com> | 2014-04-01 15:24:59 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2014-04-01 19:39:09 -0400 |
commit | 11e43325fa2b0139df1eb9c367b984a5b112dbb4 (patch) | |
tree | d9b145761d85ee68734f521559ae25c8b685eab0 | |
parent | 4e1eccfe64f424daead6ed22542377d2e1ce798e (diff) | |
download | mongo-11e43325fa2b0139df1eb9c367b984a5b112dbb4.tar.gz |
SERVER-13429 Remove printStackAndExit
All of the functions in signal_handlers.cpp were broken when logfiles or
syslog were in use. This commit removes them and all callers. The files were
left in place for a later commit to fill them back in with a unified signal
handling system.
-rw-r--r-- | src/mongo/client/sasl_client_session.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 16 | ||||
-rw-r--r-- | src/mongo/util/allocator.h | 6 | ||||
-rw-r--r-- | src/mongo/util/signal_handlers.cpp | 74 | ||||
-rw-r--r-- | src/mongo/util/signal_handlers.h | 9 |
5 files changed, 15 insertions, 92 deletions
diff --git a/src/mongo/client/sasl_client_session.cpp b/src/mongo/client/sasl_client_session.cpp index d1b14578bac..0ec7e34e407 100644 --- a/src/mongo/client/sasl_client_session.cpp +++ b/src/mongo/client/sasl_client_session.cpp @@ -44,7 +44,7 @@ namespace { void* saslOurCalloc(SaslAllocSize count, SaslAllocSize size) { void* ptr = calloc(count, size); - if (!ptr) printStackAndExit(0); + if (!ptr) abort(); return ptr; } diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 2d725e77af9..f8ba539807a 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -184,6 +184,12 @@ namespace mongo { dbexit(EXIT_CLEAN, (string("received signal ") + BSONObjBuilder::numStr(sig)).c_str()); } + void abruptQuit(int x) { + severe() << "Got signal: " << x << " (" << strsignal( x ) << ")."; + printStackTrace(severe().stream() << "Backtrace: \n"); + ::_exit(EXIT_ABRUPT); + } + // this gets called when new fails to allocate memory void my_new_handler() { printStackTrace(severe().stream() << "out of memory, printing stack and exiting:\n"); @@ -265,13 +271,13 @@ namespace mongo { #endif #if defined(SIGQUIT) - signal( SIGQUIT , printStackAndExit ); + signal( SIGQUIT , abruptQuit ); #endif - signal( SIGSEGV , printStackAndExit ); - signal( SIGABRT , printStackAndExit ); - signal( SIGFPE , printStackAndExit ); + signal( SIGSEGV , abruptQuit ); + signal( SIGABRT , abruptQuit ); + signal( SIGFPE , abruptQuit ); #if defined(SIGBUS) - signal( SIGBUS , printStackAndExit ); + signal( SIGBUS , abruptQuit ); #endif #if defined(SIGPIPE) signal( SIGPIPE , SIG_IGN ); diff --git a/src/mongo/util/allocator.h b/src/mongo/util/allocator.h index 894eb353ace..6868de5bb96 100644 --- a/src/mongo/util/allocator.h +++ b/src/mongo/util/allocator.h @@ -17,7 +17,7 @@ #pragma once -#include "mongo/util/signal_handlers.h" +#include <stdlib.h> // we need the "real" malloc here #include "mongo/client/undef_macros.h" @@ -26,13 +26,13 @@ namespace mongo { inline void * ourmalloc(size_t size) { void *x = malloc(size); - if ( x == 0 ) printStackAndExit(0); + if ( x == 0 ) abort(); return x; } inline void * ourrealloc(void *ptr, size_t size) { void *x = realloc(ptr, size); - if ( x == 0 ) printStackAndExit(0); + if ( x == 0 ) abort(); return x; } diff --git a/src/mongo/util/signal_handlers.cpp b/src/mongo/util/signal_handlers.cpp index 2aa0721bd0c..dd2ad2b1a7f 100644 --- a/src/mongo/util/signal_handlers.cpp +++ b/src/mongo/util/signal_handlers.cpp @@ -52,78 +52,4 @@ namespace mongo { * */ - static int rawWrite( int fd , char* c , int size ) { -#if !defined(_WIN32) - - int toWrite = size; - int writePos = 0; - int wrote; - while ( toWrite > 0 ) { - wrote = write( fd , &c[writePos] , toWrite ); - if ( wrote < 1 ) break; - toWrite -= wrote; - writePos += wrote; - } - return writePos; - -#else - - return -1; - -#endif - } - - static int formattedWrite( int fd , const char* format, ... ) { - const int MAX_ENTRY = 256; - static char entryBuf[MAX_ENTRY]; - - va_list ap; - va_start( ap , format ); - int entrySize = vsnprintf( entryBuf , MAX_ENTRY-1 , format , ap ); - if ( entrySize < 0 ) { - return -1; - } - - if ( rawWrite( fd , entryBuf , entrySize ) < 0 ) { - return -1; - } - - return 0; - } - - static void formattedBacktrace( int fd ) { - -#if !defined(_WIN32) - - int numFrames; - const int MAX_DEPTH = 20; - void* stackFrames[MAX_DEPTH]; - - numFrames = backtrace( stackFrames , 20 ); - for ( int i = 0; i < numFrames; i++ ) { - formattedWrite( fd , "%p " , stackFrames[i] ); - } - formattedWrite( fd , "\n" ); - - backtrace_symbols_fd( stackFrames , numFrames , fd ); - -#else - - formattedWrite( fd, "backtracing not implemented for this platform yet\n" ); - -#endif - - } - - void printStackAndExit( int signalNum ) { - const int fd = 1; // same as STDOUT_FILENO which doesn't exist on windows - - formattedWrite( fd , "Received signal %d\n" , signalNum ); - formattedWrite( fd , "Backtrace: " ); - formattedBacktrace( fd ); - formattedWrite( fd , "===\n" ); - - ::_exit( EXIT_ABRUPT ); - } - } // namespace mongo diff --git a/src/mongo/util/signal_handlers.h b/src/mongo/util/signal_handlers.h index da4deaa8698..01f59728868 100644 --- a/src/mongo/util/signal_handlers.h +++ b/src/mongo/util/signal_handlers.h @@ -32,13 +32,4 @@ namespace mongo { - /** - * Obtains the log file handler and writes the current thread's stack trace to - * it. This call issues an exit(). The function can safely be called from within a - * signal handler. - * - * @param signal that this hadler is called for - */ - void printStackAndExit( int signalNum ); - } // namespace mongo |