summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-07-01 13:13:41 -0400
committerDwight <dmerriman@gmail.com>2008-07-01 13:13:41 -0400
commitfc0e91f68eed24a29f621604004dece18ee54875 (patch)
tree114a370fb0f6a4d410588f2b9eeafe40ae6afe9b /util
parent89b2164a18f1a5f08d401b58deabe860e49834b1 (diff)
downloadmongo-fc0e91f68eed24a29f621604004dece18ee54875.tar.gz
detect mmap failure properly; sigsegv fixes
Diffstat (limited to 'util')
-rw-r--r--util/mmap.cpp14
1 files changed, 12 insertions, 2 deletions
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;
}