diff options
author | Dwight <dmerriman@gmail.com> | 2009-01-06 18:25:38 -0500 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2009-01-06 18:25:38 -0500 |
commit | 1cc123561a34d39ba65c4969792def2fe598fd69 (patch) | |
tree | dcc66a1dbae63efd0c208cf177272b1b9209c5fb /db/db.cpp | |
parent | 1ca30aed27ed605a00c46655bd9c41860daa03b0 (diff) | |
download | mongo-1cc123561a34d39ba65c4969792def2fe598fd69.tar.gz |
try not to die in segv printouts with deadlocks and such
Diffstat (limited to 'db/db.cpp')
-rw-r--r-- | db/db.cpp | 101 |
1 files changed, 55 insertions, 46 deletions
diff --git a/db/db.cpp b/db/db.cpp index 619e9a43069..ca43813fd6f 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -42,6 +42,7 @@ extern OpLog _oplog; extern int ctr; extern int callDepth; +void setupSignals(); void closeAllSockets(); void startReplication(); void pairWith(const char *remoteEnd, const char *arb); @@ -239,52 +240,6 @@ void msg(const char *m, int extras = 0) { msg(m, "127.0.0.1", DBPort, extras); } -#if !defined(_WIN32) - -#include <signal.h> - -void pipeSigHandler( int signal ) { - psignal( signal, "Signal Received : "); -} - -int segvs = 0; -void segvhandler(int x) { - if ( ++segvs > 1 ) { - signal(x, SIG_DFL); - if ( segvs == 2 ) { - cout << "\n\n\n got 2nd SIGSEGV" << endl; - sayDbContext(); - } - return; - } - problem() << "got SIGSEGV " << x << ", terminating :-(" << endl; - sayDbContext(); -// closeAllSockets(); -// MemoryMappedFile::closeAllFiles(); -// flushOpLog(); - dbexit(14); -} - -void mysighandler(int x) { - signal(x, SIG_IGN); - log() << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl; - { - dblock lk; - problem() << " now exiting" << endl; - exit(12); - } -} - -void setupSignals() { - assert( signal(SIGINT, mysighandler) != SIG_ERR ); - assert( signal(SIGTERM, mysighandler) != SIG_ERR ); -} - -#else -void setupSignals() {} -#endif - - void repairDatabases() { dblock lk; vector< string > dbNames; @@ -317,6 +272,7 @@ void clearTmpFiles() { } } +void segvhandler(int x); void initAndListen(int listenPort, const char *appserverLoc = null) { clearTmpFiles(); @@ -355,6 +311,7 @@ void initAndListen(int listenPort, const char *appserverLoc = null) { //ofstream problems("dbproblems.log", ios_base::app | ios_base::out); int test2(); void testClient(); +void pipeSigHandler( int signal ); int main(int argc, char* argv[], char *envp[] ) { @@ -537,3 +494,55 @@ usage: return 0; } + +/* we do not use log() below as it uses a mutex and that could cause deadlocks. +*/ + +string getDbContext(); + +#undef cout + +#if !defined(_WIN32) + +#include <signal.h> + +void pipeSigHandler( int signal ) { + psignal( signal, "Signal Received : "); +} + +int segvs = 0; +void segvhandler(int x) { + if ( ++segvs > 1 ) { + signal(x, SIG_DFL); + if ( segvs == 2 ) { + cout << "\n\n\n got 2nd SIGSEGV" << endl; + sayDbContext(); + } + return; + } + cout << "got SIGSEGV " << x << ", terminating :-(" << endl; + sayDbContext(); +// closeAllSockets(); +// MemoryMappedFile::closeAllFiles(); +// flushOpLog(); + dbexit(14); +} + +void mysighandler(int x) { + signal(x, SIG_IGN); + cout << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl; + { + dblock lk; + problem() << " now exiting" << endl; + exit(12); + } +} + +void setupSignals() { + assert( signal(SIGINT, mysighandler) != SIG_ERR ); + assert( signal(SIGTERM, mysighandler) != SIG_ERR ); +} + +#else +void setupSignals() {} +#endif |