summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2018-05-30 15:04:35 -0400
committerAndy Schwerin <schwerin@mongodb.com>2018-05-30 15:04:35 -0400
commitba5d89097503ad1c9ddb8b58ac371a7c3c394d9d (patch)
treeed6928ec1f16d9e4ffafb86d5b6aad66996b00db /src/mongo/db/storage/storage_engine_lock_file_posix.cpp
parentf0227671de94cd54a3d8e1653400aa1ee9d8b2fa (diff)
downloadmongo-ba5d89097503ad1c9ddb8b58ac371a7c3c394d9d.tar.gz
SERVER-35068 Properly release file descriptor in destructor of StorageEngineLockFile.
Diffstat (limited to 'src/mongo/db/storage/storage_engine_lock_file_posix.cpp')
-rw-r--r--src/mongo/db/storage/storage_engine_lock_file_posix.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
index 687d9f6b7a3..10e6b641e50 100644
--- a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
+++ b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
@@ -116,7 +116,9 @@ StorageEngineLockFile::StorageEngineLockFile(const std::string& dbpath)
boost::filesystem::file_size(_filespec) > 0),
_lockFileHandle(new LockFileHandle()) {}
-StorageEngineLockFile::~StorageEngineLockFile() {}
+StorageEngineLockFile::~StorageEngineLockFile() {
+ close();
+}
std::string StorageEngineLockFile::getFilespec() const {
return _filespec;
@@ -160,14 +162,7 @@ Status StorageEngineLockFile::open() {
<< _dbpath
<< " directory");
}
-#if !defined(__sun)
int ret = ::flock(lockFile, LOCK_EX | LOCK_NB);
-#else
- struct flock fileLockInfo = {0};
- fileLockInfo.l_type = F_WRLCK;
- fileLockInfo.l_whence = SEEK_SET;
- int ret = ::fcntl(lockFile, F_SETLK, &fileLockInfo);
-#endif // !defined(__sun)
if (ret != 0) {
int errorcode = errno;
::close(lockFile);
@@ -187,6 +182,7 @@ void StorageEngineLockFile::close() {
if (!_lockFileHandle->isValid()) {
return;
}
+ ::flock(_lockFileHandle->_fd, LOCK_UN);
::close(_lockFileHandle->_fd);
_lockFileHandle->clear();
}
@@ -256,14 +252,7 @@ void StorageEngineLockFile::clearPidAndUnlock() {
int errorcode = errno;
log() << "couldn't remove fs lock " << errnoWithDescription(errorcode);
}
-#if !defined(__sun)
- ::flock(_lockFileHandle->_fd, LOCK_UN);
-#else
- struct flock fileLockInfo = {0};
- fileLockInfo.l_type = F_UNLCK;
- fileLockInfo.l_whence = SEEK_SET;
- ::fcntl(_lockFileHandle->_fd, F_SETLK, &fileLockInfo);
-#endif // !defined(__sun)
+ close();
}
} // namespace mongo