diff options
author | Dwight <dmerriman@gmail.com> | 2008-07-01 13:13:41 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-07-01 13:13:41 -0400 |
commit | fc0e91f68eed24a29f621604004dece18ee54875 (patch) | |
tree | 114a370fb0f6a4d410588f2b9eeafe40ae6afe9b | |
parent | 89b2164a18f1a5f08d401b58deabe860e49834b1 (diff) | |
download | mongo-fc0e91f68eed24a29f621604004dece18ee54875.tar.gz |
detect mmap failure properly; sigsegv fixes
-rw-r--r-- | db/db.cpp | 8 | ||||
-rw-r--r-- | util/mmap.cpp | 14 |
2 files changed, 19 insertions, 3 deletions
diff --git a/db/db.cpp b/db/db.cpp index 32ce707857b..904e0061231 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -696,7 +696,13 @@ void pipeSigHandler( int signal ) { psignal( signal, "Signal Received : "); } +int segvs = 0; void segvhandler(int x) { + if( ++segvs > 1 ) { + if( segvs == 2 ) + cout << " got 2nd SIGSEGV" << endl; + return; + } problem() << "got SIGSEGV " << x << ", terminating :-(" << endl; sayDbContext(); MemoryMappedFile::closeAllFiles(); @@ -709,7 +715,7 @@ void mysighandler(int x) { problem() << "got kill or ctrl c signal " << x << ", will terminate after current cmd ends" << endl; { lock lk(dbMutex); - problem() << "mysighandler now exiting" << endl; + problem() << " now exiting" << endl; exit(12); } } diff --git a/util/mmap.cpp b/util/mmap.cpp index ad628473e48..ab814f61f80 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -11,10 +11,17 @@ MemoryMappedFile::~MemoryMappedFile() { } /*static*/ +int closingAllFiles = 0; void MemoryMappedFile::closeAllFiles() { + if( closingAllFiles ) { + cout << "warning closingAllFiles=" << closingAllFiles << endl; + return; + } + ++closingAllFiles; for( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ) (*i)->close(); cout << " closeAllFiles() finished" << endl; + --closingAllFiles; } #if defined(_WIN32) @@ -96,7 +103,6 @@ MemoryMappedFile::MemoryMappedFile() { } void MemoryMappedFile::close() { - mmfiles.erase(this); if( view ) munmap(view, len); view = 0; @@ -114,7 +120,7 @@ void MemoryMappedFile::close() { void* MemoryMappedFile::map(const char *filename, int length) { len = length; - fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR); + fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR); if( !fd ) { cout << "couldn't open " << filename << ' ' << errno << endl; return 0; @@ -148,6 +154,10 @@ void* MemoryMappedFile::map(const char *filename, int length) { write(fd, "", 1); view = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if( view == MAP_FAILED ) { + cout << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl; + return 0; + } return view; } |