BIND 10 trac1704, updated. c7a947916fee9b583a94aff12e8f2d0ee5652b81 [1704] Open the logger lock file in the constructor for better performance
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 17 11:57:23 UTC 2012
The branch, trac1704 has been updated
via c7a947916fee9b583a94aff12e8f2d0ee5652b81 (commit)
from 8132536f3c982f0438c0d5ff199a57a18c826411 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c7a947916fee9b583a94aff12e8f2d0ee5652b81
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu May 17 17:05:34 2012 +0530
[1704] Open the logger lock file in the constructor for better performance
This avoids the access checks associated with open() every time a
message is logged.
Also, not having the lock file is not exactly fatal. So log a message,
but don't abort anything.
-----------------------------------------------------------------------
Summary of changes:
src/lib/log/logger.cc | 73 +++++++++++++++++++++++-------------------------
src/lib/log/logger.h | 1 +
2 files changed, 36 insertions(+), 38 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/log/logger.cc b/src/lib/log/logger.cc
index 31bcabd..7ce5976 100644
--- a/src/lib/log/logger.cc
+++ b/src/lib/log/logger.cc
@@ -55,6 +55,10 @@ Logger::Logger(const char* name) : loggerptr_(NULL) {
lockfile_path_ = env2;
lockfile_path_ += "/logger_lockfile";
+
+ // Open the lockfile in the constructor so it doesn't do the access
+ // checks every time a message is logged.
+ lock_fd_ = open(lockfile_path_.c_str(), O_CREAT | O_RDWR, 0600);
}
// Initialize underlying logger, but only if logging has been initialized.
@@ -70,6 +74,10 @@ void Logger::initLoggerImpl() {
// Destructor.
Logger::~Logger() {
+ if (lock_fd_ != -1)
+ close(lock_fd_);
+ // The lockfile will continue to exist, as we mustn't delete it.
+
delete loggerptr_;
}
@@ -157,48 +165,37 @@ Logger::output(const Severity& severity, const std::string& message) {
// Use a lock file for mutual exclusion from other processes to
// avoid log messages getting interspersed
- int fd;
struct flock lock;
int status;
- // Acquire the exclusive lock
- fd = open(lockfile_path_.c_str(), O_CREAT | O_RDWR, 0600);
- if (fd == -1) {
- getLoggerPtr()->outputRaw(isc::log::FATAL, "Unable to open logger lockfile: " + lockfile_path_);
- return;
- }
-
- memset(&lock, 0, sizeof lock);
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 1;
- status = fcntl(fd, F_SETLKW, &lock);
- if (status != 0) {
- getLoggerPtr()->outputRaw(isc::log::FATAL, "Unable to lock logger lockfile: " + lockfile_path_);
- close (fd);
- return;
- }
-
- // Output the message
- getLoggerPtr()->outputRaw(severity, message);
-
- // Release the exclusive lock
- memset(&lock, 0, sizeof lock);
- lock.l_type = F_UNLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 1;
- status = fcntl(fd, F_SETLKW, &lock);
- if (status != 0) {
- getLoggerPtr()->outputRaw(isc::log::FATAL, "Unable to unlock logger lockfile: " + lockfile_path_);
- close (fd);
- return;
+ if (lock_fd_ == -1) {
+ getLoggerPtr()->outputRaw(isc::log::WARN, "Unable to use logger lockfile: " + lockfile_path_);
+ } else {
+ memset(&lock, 0, sizeof lock);
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 1;
+ status = fcntl(lock_fd_, F_SETLKW, &lock);
+ if (status != 0) {
+ getLoggerPtr()->outputRaw(isc::log::WARN, "Unable to lock logger lockfile: " + lockfile_path_);
+ return;
+ }
+
+ // Output the message
+ getLoggerPtr()->outputRaw(severity, message);
+
+ // Release the exclusive lock
+ memset(&lock, 0, sizeof lock);
+ lock.l_type = F_UNLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 1;
+ status = fcntl(lock_fd_, F_SETLKW, &lock);
+ if (status != 0) {
+ getLoggerPtr()->outputRaw(isc::log::WARN, "Unable to unlock logger lockfile: " + lockfile_path_);
+ }
}
-
- close(fd);
-
- // The lockfile will continue to exist, as we mustn't delete it.
}
Logger::Formatter
diff --git a/src/lib/log/logger.h b/src/lib/log/logger.h
index b7362b3..1ade2ce 100644
--- a/src/lib/log/logger.h
+++ b/src/lib/log/logger.h
@@ -284,6 +284,7 @@ private:
LoggerImpl* loggerptr_; ///< Pointer to underlying logger
char name_[MAX_LOGGER_NAME_SIZE + 1]; ///< Copy of the logger name
std::string lockfile_path_;
+ int lock_fd_;
};
} // namespace log
More information about the bind10-changes
mailing list