From: Mukund Sivaraman Date: Mon, 28 May 2012 06:02:41 +0000 (+0530) Subject: [1704] Throw if NULL is passed to logger.setInterprocessSync() X-Git-Tag: trac2351_base~226^2~60^2^2~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fcb63453e3d835fdca05146482d001035cdbd6af;p=thirdparty%2Fkea.git [1704] Throw if NULL is passed to logger.setInterprocessSync() --- diff --git a/src/lib/log/logger.h b/src/lib/log/logger.h index 77be7effba..6405488b47 100644 --- a/src/lib/log/logger.h +++ b/src/lib/log/logger.h @@ -99,6 +99,17 @@ public: {} }; +/// \brief Bad Interprocess Sync +/// +/// Exception thrown if a bad InterprocessSync object (such as NULL) is +/// used. +class BadInterprocessSync : public isc::Exception { +public: + BadInterprocessSync(const char* file, size_t line, const char* what) : + isc::Exception(file, line, what) + {} +}; + /// \brief Logger Class /// /// This class is the main class used for logging. Use comprises: @@ -240,15 +251,13 @@ public: /// \brief Replace the interprocess synchronization object /// - /// This method is exception-free. If this method is called with - /// NULL as the argument, it does nothing and the old sync object is - /// used as before. + /// If this method is called with NULL as the argument, it throws a + /// BadInterprocessSync exception. /// /// \param sync The logger uses this synchronization object for - /// synchronizing output of log messages. If NULL is passed, the old - /// synchronization object is used as before. When a non-NULL sync - /// object is passed, it should be deletable and the ownership is - /// transferred to the logger. + /// synchronizing output of log messages. It should be deletable and + /// the ownership is transferred to the logger. If NULL is passed, + /// a BadInterprocessSync exception is thrown. void setInterprocessSync(isc::util::InterprocessSync* sync); /// \brief Equality diff --git a/src/lib/log/logger_impl.cc b/src/lib/log/logger_impl.cc index 974d0c2176..d53e57d342 100644 --- a/src/lib/log/logger_impl.cc +++ b/src/lib/log/logger_impl.cc @@ -111,10 +111,8 @@ LoggerImpl::lookupMessage(const MessageID& ident) { void LoggerImpl::setInterprocessSync(isc::util::InterprocessSync* sync) { - // If we are passed NULL, change nothing. The old sync_ object will - // continue to be used. if (sync == NULL) { - return; + isc_throw(BadInterprocessSync, "NULL was passed to setInterprocessSync()"); } delete sync_; diff --git a/src/lib/log/logger_impl.h b/src/lib/log/logger_impl.h index 43d8aa25e2..10d3db4b58 100644 --- a/src/lib/log/logger_impl.h +++ b/src/lib/log/logger_impl.h @@ -171,15 +171,13 @@ public: /// \brief Replace the interprocess synchronization object /// - /// This method is exception-free. If this method is called with - /// NULL as the argument, it does nothing and the old sync object is - /// used as before. + /// If this method is called with NULL as the argument, it throws a + /// BadInterprocessSync exception. /// /// \param sync The logger uses this synchronization object for - /// synchronizing output of log messages. If NULL is passed, the old - /// synchronization object is used as before. When a non-NULL sync - /// object is passed, it should be deletable and the ownership is - /// transferred to the logger implementation. + /// synchronizing output of log messages. It should be deletable and + /// the ownership is transferred to the logger implementation. + /// If NULL is passed, a BadInterprocessSync exception is thrown. void setInterprocessSync(isc::util::InterprocessSync* sync); /// \brief Equality diff --git a/src/lib/log/tests/logger_unittest.cc b/src/lib/log/tests/logger_unittest.cc index 9416bfac9a..a9330a9a64 100644 --- a/src/lib/log/tests/logger_unittest.cc +++ b/src/lib/log/tests/logger_unittest.cc @@ -383,6 +383,13 @@ TEST_F(LoggerTest, LoggerNameLength) { #endif } +TEST_F(LoggerTest, setInterprocessSync) { + // Create a logger + Logger logger("alpha"); + + EXPECT_THROW(logger.setInterprocessSync(NULL), BadInterprocessSync); +} + class MockSync : public isc::util::InterprocessSync { public: /// \brief Constructor