BIND 10 trac1704_2, updated. d575fbaa4083182e8d6602bb042934451ae06c65 [1704] Add a comment about use of select() in the test

BIND 10 source code commits bind10-changes at lists.isc.org
Fri May 25 04:18:20 UTC 2012


The branch, trac1704_2 has been updated
       via  d575fbaa4083182e8d6602bb042934451ae06c65 (commit)
       via  bd5494fa3a4aded378c5e2167f6c9e1b7eaf2035 (commit)
       via  8b555fcb29378dcb0db476bf8f53804acae8fe77 (commit)
       via  93fb5cab3e4a0752e2471931e171937392c71ae0 (commit)
       via  caa5bb9a9b852631d1548460daef2b93cf48c64c (commit)
      from  227d01775bdb4dab84c97e5858c0812e2aa845c2 (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 d575fbaa4083182e8d6602bb042934451ae06c65
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri May 25 09:46:52 2012 +0530

    [1704] Add a comment about use of select() in the test
    
    This commit also:
    
     * Moves the parent's code to read the lock state into a helper
       function.
    
     * Describes the 5 second timeout as an arbitrary value.

commit bd5494fa3a4aded378c5e2167f6c9e1b7eaf2035
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri May 25 09:36:10 2012 +0530

    [1704] Initialize sync_ in the initialization list

commit 8b555fcb29378dcb0db476bf8f53804acae8fe77
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri May 25 09:34:27 2012 +0530

    [1704] Update comment about using locking in the logger

commit 93fb5cab3e4a0752e2471931e171937392c71ae0
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri May 25 09:32:56 2012 +0530

    [1704] Remove obsolete include

commit caa5bb9a9b852631d1548460daef2b93cf48c64c
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri May 25 09:31:56 2012 +0530

    [1704] Make InterprocessSyncFile's destructor virtual

-----------------------------------------------------------------------

Summary of changes:
 src/lib/log/logger_impl.cc                         |   12 ++--
 src/lib/util/interprocess_sync_file.h              |    2 +-
 .../util/tests/interprocess_sync_file_unittest.cc  |   63 ++++++++++----------
 3 files changed, 38 insertions(+), 39 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/log/logger_impl.cc b/src/lib/log/logger_impl.cc
index dff8b3e..16b4d52 100644
--- a/src/lib/log/logger_impl.cc
+++ b/src/lib/log/logger_impl.cc
@@ -15,7 +15,6 @@
 #include <iostream>
 #include <iomanip>
 #include <algorithm>
-#include <memory>
 
 #include <stdarg.h>
 #include <stdio.h>
@@ -50,10 +49,11 @@ namespace log {
 // one compiler requires that all member variables be constructed before the
 // constructor is run, but log4cplus::Logger (the type of logger_) has no
 // default constructor.
-LoggerImpl::LoggerImpl(const string& name) : name_(expandLoggerName(name)),
-    logger_(log4cplus::Logger::getInstance(name_))
+LoggerImpl::LoggerImpl(const string& name) :
+    name_(expandLoggerName(name)),
+    logger_(log4cplus::Logger::getInstance(name_)),
+    sync_(new InterprocessSyncFile("logger"))
 {
-    sync_ = new InterprocessSyncFile("logger");
 }
 
 // Destructor. (Here because of virtual declaration.)
@@ -117,8 +117,8 @@ LoggerImpl::lookupMessage(const MessageID& ident) {
 
 void
 LoggerImpl::outputRaw(const Severity& severity, const string& message) {
-    // Use a lock file for mutual exclusion from other processes to
-    // avoid log messages getting interspersed
+    // Use an interprocess sync locker for mutual exclusion from other
+    // processes to avoid log messages getting interspersed.
 
     InterprocessSyncLocker locker(*sync_);
 
diff --git a/src/lib/util/interprocess_sync_file.h b/src/lib/util/interprocess_sync_file.h
index c288cb0..cf8f4f1 100644
--- a/src/lib/util/interprocess_sync_file.h
+++ b/src/lib/util/interprocess_sync_file.h
@@ -40,7 +40,7 @@ public:
     {}
 
     /// \brief Destructor
-    ~InterprocessSyncFile();
+    virtual ~InterprocessSyncFile();
 
 protected:
     bool lock();
diff --git a/src/lib/util/tests/interprocess_sync_file_unittest.cc b/src/lib/util/tests/interprocess_sync_file_unittest.cc
index e070e38..a3a50e6 100644
--- a/src/lib/util/tests/interprocess_sync_file_unittest.cc
+++ b/src/lib/util/tests/interprocess_sync_file_unittest.cc
@@ -20,6 +20,35 @@ using namespace std;
 namespace isc {
 namespace util {
 
+static unsigned char
+parent_read_locked_state (int fd) {
+  unsigned char locked = 0xff;
+
+  fd_set rfds;
+  FD_ZERO(&rfds);
+  FD_SET(fd, &rfds);
+
+  // We use select() here to wait for new data on the input end of
+  // the pipe. We wait for 5 seconds (an arbitrary value) for input
+  // data, and continue if no data is available. This is done so
+  // that read() is not blocked due to some issue in the child
+  // process (and the tests continue running).
+
+  struct timeval tv;
+  tv.tv_sec = 5;
+  tv.tv_usec = 0;
+
+  const int nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
+  EXPECT_EQ(1, nfds);
+
+  if (nfds == 1) {
+      // Read status
+      read(fd, &locked, sizeof(locked));
+  }
+
+  return locked;
+}
+
 TEST(InterprocessSyncFileTest, TestLock) {
   InterprocessSyncFile sync("test");
   InterprocessSyncLocker locker(sync);
@@ -53,25 +82,10 @@ TEST(InterprocessSyncFileTest, TestLock) {
       close(fds[1]);
       exit(0);
   } else {
-      unsigned char locked = 0;
       // Parent reads from pipe
       close(fds[1]);
 
-      fd_set rfds;
-      FD_ZERO(&rfds);
-      FD_SET(fds[0], &rfds);
-
-      struct timeval tv;
-      tv.tv_sec = 5;
-      tv.tv_usec = 0;
-
-      const int nfds = select(fds[0] + 1, &rfds, NULL, NULL, &tv);
-      EXPECT_EQ(1, nfds);
-
-      if (nfds == 1) {
-          // Read status
-          read(fds[0], &locked, sizeof(locked));
-      }
+      const unsigned char locked = parent_read_locked_state(fds[0]);
 
       close(fds[0]);
 
@@ -121,25 +135,10 @@ TEST(InterprocessSyncFileTest, TestMultipleFilesForked) {
       close(fds[1]);
       exit(0);
   } else {
-      unsigned char locked = 0xff;
       // Parent reads from pipe
       close(fds[1]);
 
-      fd_set rfds;
-      FD_ZERO(&rfds);
-      FD_SET(fds[0], &rfds);
-
-      struct timeval tv;
-      tv.tv_sec = 5;
-      tv.tv_usec = 0;
-
-      const int nfds = select(fds[0] + 1, &rfds, NULL, NULL, &tv);
-      EXPECT_EQ(1, nfds);
-
-      if (nfds == 1) {
-          // Read status
-          read(fds[0], &locked, sizeof(locked));
-      }
+      const unsigned char locked = parent_read_locked_state(fds[0]);
 
       close(fds[0]);
 



More information about the bind10-changes mailing list