Browse Source

[1704] Throw if NULL is passed to logger.setInterprocessSync()

Mukund Sivaraman 13 years ago
parent
commit
fcb63453e3

+ 16 - 7
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

+ 1 - 3
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_;

+ 5 - 7
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

+ 7 - 0
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