BIND 10 master, updated. aa528462f0f90a589d7773e8d952c51226fc0b96 [master] Merge branch 'trac2899-2'
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed May 15 16:20:41 UTC 2013
The branch, master has been updated
via aa528462f0f90a589d7773e8d952c51226fc0b96 (commit)
via 3471a0a39ec45a25c96905ce634e142fd4a06902 (commit)
via 2f81b4961e70a653a09dc24d8b07bd9eac1ecd04 (commit)
via eacf6593309211e0cdc1867d69d4eeae86bc450c (commit)
via 25e6b90892b1b93c129606f175a905c30ec62a6f (commit)
via 6ed2d962ac93a626c7fe4494a0a060858c4125d0 (commit)
via 00cd04ff09dd403968633193ad51ce81bbd1c5d1 (commit)
via 55f6c351193ff5aa17a2729bd58d6e74fcd17933 (commit)
from e561cb2ebdabe6a41ee3e702f407c853a88857ff (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 aa528462f0f90a589d7773e8d952c51226fc0b96
Merge: e561cb2 3471a0a
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed May 15 08:59:28 2013 -0700
[master] Merge branch 'trac2899-2'
-----------------------------------------------------------------------
Summary of changes:
configure.ac | 2 ++
src/lib/log/Makefile.am | 4 ++--
src/lib/log/interprocess/Makefile.am | 21 ++++++++++++++++++++
src/lib/log/interprocess/README | 13 ++++++++++++
.../{util => log/interprocess}/interprocess_sync.h | 6 ++++--
.../interprocess}/interprocess_sync_file.cc | 8 +++++---
.../interprocess}/interprocess_sync_file.h | 8 +++++---
.../interprocess}/interprocess_sync_null.cc | 8 +++++---
.../interprocess}/interprocess_sync_null.h | 8 +++++---
.../lib/log/interprocess}/tests/Makefile.am | 20 ++++++++++---------
.../tests/interprocess_sync_file_unittest.cc | 14 +++++--------
.../tests/interprocess_sync_null_unittest.cc | 9 ++++-----
.../interprocess}/tests/run_unittests.cc | 2 +-
src/lib/log/logger.cc | 2 +-
src/lib/log/logger.h | 14 ++++++++++---
src/lib/log/logger_impl.cc | 10 +++++-----
src/lib/log/logger_impl.h | 7 +++----
src/lib/log/logger_manager.cc | 5 +++--
src/lib/log/tests/Makefile.am | 6 ++----
src/lib/log/tests/buffer_logger_test.cc | 5 +++--
src/lib/log/tests/logger_example.cc | 10 +++++-----
src/lib/log/tests/logger_lock_test.cc | 6 ++++--
src/lib/log/tests/logger_unittest.cc | 5 ++---
src/lib/util/Makefile.am | 4 ----
src/lib/util/tests/Makefile.am | 3 ---
.../util/tests/memory_segment_mapped_unittest.cc | 4 ++--
src/lib/util/tests/run_unittests.cc | 1 -
src/lib/util/unittests/Makefile.am | 1 +
.../util/{tests => unittests}/interprocess_util.cc | 2 +-
.../util/{tests => unittests}/interprocess_util.h | 2 +-
30 files changed, 127 insertions(+), 83 deletions(-)
create mode 100644 src/lib/log/interprocess/Makefile.am
create mode 100644 src/lib/log/interprocess/README
rename src/lib/{util => log/interprocess}/interprocess_sync.h (98%)
rename src/lib/{util => log/interprocess}/interprocess_sync_file.cc (95%)
rename src/lib/{util => log/interprocess}/interprocess_sync_file.h (95%)
rename src/lib/{util => log/interprocess}/interprocess_sync_null.cc (88%)
rename src/lib/{util => log/interprocess}/interprocess_sync_null.h (93%)
copy {tests/tools/badpacket => src/lib/log/interprocess}/tests/Makefile.am (51%)
rename src/lib/{util => log/interprocess}/tests/interprocess_sync_file_unittest.cc (95%)
rename src/lib/{util => log/interprocess}/tests/interprocess_sync_null_unittest.cc (95%)
copy src/lib/{util/threads => log/interprocess}/tests/run_unittests.cc (93%)
rename src/lib/util/{tests => unittests}/interprocess_util.cc (98%)
rename src/lib/util/{tests => unittests}/interprocess_util.h (98%)
-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 159841f..7912819 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1297,6 +1297,8 @@ AC_CONFIG_FILES([Makefile
src/lib/xfr/Makefile
src/lib/xfr/tests/Makefile
src/lib/log/Makefile
+ src/lib/log/interprocess/Makefile
+ src/lib/log/interprocess/tests/Makefile
src/lib/log/compiler/Makefile
src/lib/log/tests/Makefile
src/lib/resolve/Makefile
diff --git a/src/lib/log/Makefile.am b/src/lib/log/Makefile.am
index 18d5f90..cc00beb 100644
--- a/src/lib/log/Makefile.am
+++ b/src/lib/log/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . compiler tests
+SUBDIRS = interprocess . compiler tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
@@ -49,6 +49,6 @@ libb10_log_la_CXXFLAGS += -Wno-error
endif
libb10_log_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
libb10_log_la_LIBADD = $(top_builddir)/src/lib/util/libb10-util.la
-libb10_log_la_LIBADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
+libb10_log_la_LIBADD += interprocess/libb10-log_interprocess.la
libb10_log_la_LIBADD += $(LOG4CPLUS_LIBS)
libb10_log_la_LDFLAGS = -no-undefined -version-info 1:0:0
diff --git a/src/lib/log/interprocess/Makefile.am b/src/lib/log/interprocess/Makefile.am
new file mode 100644
index 0000000..567ff09
--- /dev/null
+++ b/src/lib/log/interprocess/Makefile.am
@@ -0,0 +1,21 @@
+SUBDIRS = . tests
+
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += -DLOCKFILE_DIR=\"${localstatedir}/${PACKAGE_NAME}\"
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+noinst_LTLIBRARIES = libb10-log_interprocess.la
+
+libb10_log_interprocess_la_SOURCES = interprocess_sync.h
+libb10_log_interprocess_la_SOURCES += interprocess_sync_file.h
+libb10_log_interprocess_la_SOURCES += interprocess_sync_file.cc
+libb10_log_interprocess_la_SOURCES += interprocess_sync_null.h
+libb10_log_interprocess_la_SOURCES += interprocess_sync_null.cc
+
+libb10_log_interprocess_la_LIBADD = $(top_builddir)/src/lib/util/threads/libb10-threads.la
+
+EXTRA_DIST = README
diff --git a/src/lib/log/interprocess/README b/src/lib/log/interprocess/README
new file mode 100644
index 0000000..e910a3a
--- /dev/null
+++ b/src/lib/log/interprocess/README
@@ -0,0 +1,13 @@
+The files in this directory implement a helper sub-library of the
+inter process locking for the log library. We use our own locks
+because such locks are only available in relatively recent versions of
+log4cplus. Also (against our usual practice) we somehow re-invented
+an in-house version of such a general purose library rather than
+existing proven tools such as boost::interprocess. While we decided
+to go with the in-house version for the log library at least until we
+completely swith to log4cplus's native lock support, no other BIND 10
+module should use this; they should use existing external
+tools/libraries.
+
+This sub-library is therefore "hidden" here. As such, none of these
+files should be installed.
diff --git a/src/lib/log/interprocess/interprocess_sync.h b/src/lib/log/interprocess/interprocess_sync.h
new file mode 100644
index 0000000..10453cc
--- /dev/null
+++ b/src/lib/log/interprocess/interprocess_sync.h
@@ -0,0 +1,151 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef INTERPROCESS_SYNC_H
+#define INTERPROCESS_SYNC_H
+
+#include <string>
+
+namespace isc {
+namespace log {
+namespace interprocess {
+
+class InterprocessSyncLocker; // forward declaration
+
+/// \brief Interprocess Sync Class
+///
+/// This class specifies an interface for mutual exclusion among
+/// co-operating processes. This is an abstract class and a real
+/// implementation such as InterprocessSyncFile should be used
+/// in code. Usage is as follows:
+///
+/// 1. Client instantiates a sync object of an implementation (such as
+/// InterprocessSyncFile).
+/// 2. Client then creates an automatic (stack) object of
+/// InterprocessSyncLocker around the sync object. Such an object
+/// destroys itself and releases any acquired lock when it goes out of extent.
+/// 3. Client calls lock() method on the InterprocessSyncLocker.
+/// 4. Client performs task that needs mutual exclusion.
+/// 5. Client frees lock with unlock(), or simply returns from the basic
+/// block which forms the scope for the InterprocessSyncLocker.
+///
+/// NOTE: All implementations of InterprocessSync should keep the
+/// is_locked_ member variable updated whenever their
+/// lock()/tryLock()/unlock() implementations are called.
+class InterprocessSync {
+ // InterprocessSyncLocker is the only code outside this class that
+ // should be allowed to call the lock(), tryLock() and unlock()
+ // methods.
+ friend class InterprocessSyncLocker;
+
+public:
+ /// \brief Constructor
+ ///
+ /// Creates an interprocess synchronization object
+ ///
+ /// \param task_name Name of the synchronization task. This has to be
+ /// identical among the various processes that need to be
+ /// synchronized for the same task.
+ InterprocessSync(const std::string& task_name) :
+ task_name_(task_name), is_locked_(false)
+ {}
+
+ /// \brief Destructor
+ virtual ~InterprocessSync() {}
+
+protected:
+ /// \brief Acquire the lock (blocks if something else has acquired a
+ /// lock on the same task name)
+ ///
+ /// \return Returns true if the lock was acquired, false otherwise.
+ virtual bool lock() = 0;
+
+ /// \brief Try to acquire a lock (doesn't block)
+ ///
+ /// \return Returns true if the lock was acquired, false otherwise.
+ virtual bool tryLock() = 0;
+
+ /// \brief Release the lock
+ ///
+ /// \return Returns true if the lock was released, false otherwise.
+ virtual bool unlock() = 0;
+
+ const std::string task_name_; ///< The task name
+ bool is_locked_; ///< Is the lock taken?
+};
+
+/// \brief Interprocess Sync Locker Class
+///
+/// This class is used for making automatic stack objects to manage
+/// locks that are released automatically when the block is exited
+/// (RAII). It is meant to be used along with InterprocessSync objects. See
+/// the description of InterprocessSync.
+class InterprocessSyncLocker {
+public:
+ /// \brief Constructor
+ ///
+ /// Creates a lock manager around a interprocess synchronization object
+ ///
+ /// \param sync The sync object which has to be locked/unlocked by
+ /// this locker object.
+ InterprocessSyncLocker(InterprocessSync& sync) :
+ sync_(sync)
+ {}
+
+ /// \brief Destructor
+ ~InterprocessSyncLocker() {
+ if (isLocked())
+ unlock();
+ }
+
+ /// \brief Acquire the lock (blocks if something else has acquired a
+ /// lock on the same task name)
+ ///
+ /// \return Returns true if the lock was acquired, false otherwise.
+ bool lock() {
+ return (sync_.lock());
+ }
+
+ /// \brief Try to acquire a lock (doesn't block)
+ ///
+ /// \return Returns true if a new lock could be acquired, false
+ /// otherwise.
+ bool tryLock() {
+ return (sync_.tryLock());
+ }
+
+ /// \brief Check if the lock is taken
+ ///
+ /// \return Returns true if a lock is currently acquired, false
+ /// otherwise.
+ bool isLocked() const {
+ return (sync_.is_locked_);
+ }
+
+ /// \brief Release the lock
+ ///
+ /// \return Returns true if the lock was released, false otherwise.
+ bool unlock() {
+ return (sync_.unlock());
+ }
+
+protected:
+ InterprocessSync& sync_; ///< Ref to underlying sync object
+};
+
+} // namespace interprocess
+} // namespace log
+} // namespace isc
+
+#endif // INTERPROCESS_SYNC_H
diff --git a/src/lib/log/interprocess/interprocess_sync_file.cc b/src/lib/log/interprocess/interprocess_sync_file.cc
new file mode 100644
index 0000000..7f8fcb4
--- /dev/null
+++ b/src/lib/log/interprocess/interprocess_sync_file.cc
@@ -0,0 +1,134 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <log/interprocess/interprocess_sync_file.h>
+
+#include <string>
+#include <cerrno>
+#include <cstring>
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+namespace isc {
+namespace log {
+namespace interprocess {
+
+InterprocessSyncFile::~InterprocessSyncFile() {
+ if (fd_ != -1) {
+ // This will also release any applied locks.
+ close(fd_);
+ // The lockfile will continue to exist, and we must not delete
+ // it.
+ }
+}
+
+bool
+InterprocessSyncFile::do_lock(int cmd, short l_type) {
+ // Open lock file only when necessary (i.e., here). This is so that
+ // if a default InterprocessSync object is replaced with another
+ // implementation, it doesn't attempt any opens.
+ if (fd_ == -1) {
+ std::string lockfile_path = LOCKFILE_DIR;
+
+ const char* const env = getenv("B10_FROM_BUILD");
+ if (env != NULL) {
+ lockfile_path = env;
+ }
+
+ const char* const env2 = getenv("B10_FROM_BUILD_LOCALSTATEDIR");
+ if (env2 != NULL) {
+ lockfile_path = env2;
+ }
+
+ const char* const env3 = getenv("B10_LOCKFILE_DIR_FROM_BUILD");
+ if (env3 != NULL) {
+ lockfile_path = env3;
+ }
+
+ lockfile_path += "/" + task_name_ + "_lockfile";
+
+ // Open the lockfile in the constructor so it doesn't do the access
+ // checks every time a message is logged.
+ const mode_t mode = umask(0111);
+ fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR, 0660);
+ umask(mode);
+
+ if (fd_ == -1) {
+ isc_throw(InterprocessSyncFileError,
+ "Unable to use interprocess sync lockfile ("
+ << std::strerror(errno) << "): " << lockfile_path);
+ }
+ }
+
+ struct flock lock;
+
+ memset(&lock, 0, sizeof (lock));
+ lock.l_type = l_type;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 1;
+
+ return (fcntl(fd_, cmd, &lock) == 0);
+}
+
+bool
+InterprocessSyncFile::lock() {
+ if (is_locked_) {
+ return (true);
+ }
+
+ if (do_lock(F_SETLKW, F_WRLCK)) {
+ is_locked_ = true;
+ return (true);
+ }
+
+ return (false);
+}
+
+bool
+InterprocessSyncFile::tryLock() {
+ if (is_locked_) {
+ return (true);
+ }
+
+ if (do_lock(F_SETLK, F_WRLCK)) {
+ is_locked_ = true;
+ return (true);
+ }
+
+ return (false);
+}
+
+bool
+InterprocessSyncFile::unlock() {
+ if (!is_locked_) {
+ return (true);
+ }
+
+ if (do_lock(F_SETLKW, F_UNLCK)) {
+ is_locked_ = false;
+ return (true);
+ }
+
+ return (false);
+}
+
+} // namespace interprocess
+} // namespace log
+} // namespace isc
diff --git a/src/lib/log/interprocess/interprocess_sync_file.h b/src/lib/log/interprocess/interprocess_sync_file.h
new file mode 100644
index 0000000..cb07003
--- /dev/null
+++ b/src/lib/log/interprocess/interprocess_sync_file.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef INTERPROCESS_SYNC_FILE_H
+#define INTERPROCESS_SYNC_FILE_H
+
+#include <log/interprocess/interprocess_sync.h>
+#include <exceptions/exceptions.h>
+
+namespace isc {
+namespace log {
+namespace interprocess {
+
+/// \brief InterprocessSyncFileError
+///
+/// Exception that is thrown if it's not possible to open the
+/// lock file.
+class InterprocessSyncFileError : public Exception {
+public:
+ InterprocessSyncFileError(const char* file, size_t line,
+ const char* what) :
+ isc::Exception(file, line, what) {}
+};
+
+/// \brief File-based Interprocess Sync Class
+///
+/// This class specifies a concrete implementation for a file-based
+/// interprocess synchronization mechanism. Please see the
+/// InterprocessSync class documentation for usage.
+///
+/// An InterprocessSyncFileError exception may be thrown if there is an
+/// issue opening the lock file.
+///
+/// Lock files are created typically in the local state directory
+/// (var). They are typically named like "<task_name>_lockfile".
+/// This implementation opens lock files lazily (only when
+/// necessary). It also leaves the lock files lying around as multiple
+/// processes may have locks on them.
+class InterprocessSyncFile : public InterprocessSync {
+public:
+ /// \brief Constructor
+ ///
+ /// Creates a file-based interprocess synchronization object
+ ///
+ /// \param name Name of the synchronization task. This has to be
+ /// identical among the various processes that need to be
+ /// synchronized for the same task.
+ InterprocessSyncFile(const std::string& task_name) :
+ InterprocessSync(task_name), fd_(-1)
+ {}
+
+ /// \brief Destructor
+ virtual ~InterprocessSyncFile();
+
+protected:
+ /// \brief Acquire the lock (blocks if something else has acquired a
+ /// lock on the same task name)
+ ///
+ /// \return Returns true if the lock was acquired, false otherwise.
+ bool lock();
+
+ /// \brief Try to acquire a lock (doesn't block)
+ ///
+ /// \return Returns true if the lock was acquired, false otherwise.
+ bool tryLock();
+
+ /// \brief Release the lock
+ ///
+ /// \return Returns true if the lock was released, false otherwise.
+ bool unlock();
+
+private:
+ bool do_lock(int cmd, short l_type);
+
+ int fd_; ///< The descriptor for the open file
+};
+
+} // namespace interprocess
+} // namespace log
+} // namespace isc
+
+#endif // INTERPROCESS_SYNC_FILE_H
diff --git a/src/lib/log/interprocess/interprocess_sync_null.cc b/src/lib/log/interprocess/interprocess_sync_null.cc
new file mode 100644
index 0000000..226f722
--- /dev/null
+++ b/src/lib/log/interprocess/interprocess_sync_null.cc
@@ -0,0 +1,44 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <log/interprocess/interprocess_sync_null.h>
+
+namespace isc {
+namespace log {
+namespace interprocess {
+
+InterprocessSyncNull::~InterprocessSyncNull() {
+}
+
+bool
+InterprocessSyncNull::lock() {
+ is_locked_ = true;
+ return (true);
+}
+
+bool
+InterprocessSyncNull::tryLock() {
+ is_locked_ = true;
+ return (true);
+}
+
+bool
+InterprocessSyncNull::unlock() {
+ is_locked_ = false;
+ return (true);
+}
+
+} // namespace interprocess
+} // namespace log
+} // namespace isc
diff --git a/src/lib/log/interprocess/interprocess_sync_null.h b/src/lib/log/interprocess/interprocess_sync_null.h
new file mode 100644
index 0000000..41dab50
--- /dev/null
+++ b/src/lib/log/interprocess/interprocess_sync_null.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef INTERPROCESS_SYNC_NULL_H
+#define INTERPROCESS_SYNC_NULL_H
+
+#include <log/interprocess/interprocess_sync.h>
+
+namespace isc {
+namespace log {
+namespace interprocess {
+
+/// \brief Null Interprocess Sync Class
+///
+/// This class specifies a concrete implementation for a null (no effect)
+/// interprocess synchronization mechanism. Please see the
+/// InterprocessSync class documentation for usage.
+class InterprocessSyncNull : public InterprocessSync {
+public:
+ /// \brief Constructor
+ ///
+ /// Creates a null interprocess synchronization object
+ ///
+ /// \param name Name of the synchronization task. This has to be
+ /// identical among the various processes that need to be
+ /// synchronized for the same task.
+ InterprocessSyncNull(const std::string& task_name) :
+ InterprocessSync(task_name)
+ {}
+
+ /// \brief Destructor
+ virtual ~InterprocessSyncNull();
+
+protected:
+ /// \brief Acquire the lock (never blocks)
+ ///
+ /// \return Always returns true
+ bool lock();
+
+ /// \brief Try to acquire a lock (doesn't block)
+ ///
+ /// \return Always returns true
+ bool tryLock();
+
+ /// \brief Release the lock
+ ///
+ /// \return Always returns true
+ bool unlock();
+};
+
+} // namespace interprocess
+} // namespace log
+} // namespace isc
+
+#endif // INTERPROCESS_SYNC_NULL_H
diff --git a/src/lib/log/interprocess/tests/Makefile.am b/src/lib/log/interprocess/tests/Makefile.am
new file mode 100644
index 0000000..3013f99
--- /dev/null
+++ b/src/lib/log/interprocess/tests/Makefile.am
@@ -0,0 +1,37 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+# XXX: we'll pollute the top builddir for creating a temporary test file
+# used to bind a UNIX domain socket so we can minimize the risk of exceeding
+# the limit of file name path size.
+AM_CPPFLAGS += -DTEST_DATA_TOPBUILDDIR=\"$(abs_top_builddir)\"
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+ $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = run_unittests.cc
+run_unittests_SOURCES += interprocess_sync_file_unittest.cc
+run_unittests_SOURCES += interprocess_sync_null_unittest.cc
+
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+run_unittests_LDADD = ../libb10-log_interprocess.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
+run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
+run_unittests_LDADD += $(GTEST_LDADD)
+endif
+
+noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc b/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc
new file mode 100644
index 0000000..4df365e
--- /dev/null
+++ b/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc
@@ -0,0 +1,151 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <log/interprocess/interprocess_sync_file.h>
+
+#include <util/unittests/check_valgrind.h>
+#include <util/unittests/interprocess_util.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+using namespace std;
+using namespace isc::log::interprocess;
+using isc::util::unittests::parentReadState;
+
+namespace {
+TEST(InterprocessSyncFileTest, TestLock) {
+ InterprocessSyncFile sync("test");
+ InterprocessSyncLocker locker(sync);
+
+ EXPECT_FALSE(locker.isLocked());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.isLocked());
+
+ if (!isc::util::unittests::runningOnValgrind()) {
+
+ int fds[2];
+
+ // Here, we check that a lock has been taken by forking and
+ // checking from the child that a lock exists. This has to be
+ // done from a separate process as we test by trying to lock the
+ // range again on the lock file. The lock attempt would pass if
+ // done from the same process for the granted range. The lock
+ // attempt must fail to pass our check.
+
+ EXPECT_EQ(0, pipe(fds));
+
+ if (fork() == 0) {
+ unsigned char locked = 0;
+ // Child writes to pipe
+ close(fds[0]);
+
+ InterprocessSyncFile sync2("test");
+ InterprocessSyncLocker locker2(sync2);
+
+ if (!locker2.tryLock()) {
+ EXPECT_FALSE(locker2.isLocked());
+ locked = 1;
+ } else {
+ EXPECT_TRUE(locker2.isLocked());
+ }
+
+ ssize_t bytes_written = write(fds[1], &locked, sizeof(locked));
+ EXPECT_EQ(sizeof(locked), bytes_written);
+
+ close(fds[1]);
+ exit(0);
+ } else {
+ // Parent reads from pipe
+ close(fds[1]);
+
+ const unsigned char locked = parentReadState(fds[0]);
+
+ close(fds[0]);
+
+ EXPECT_EQ(1, locked);
+ }
+ }
+
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_FALSE(locker.isLocked());
+
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
+}
+
+TEST(InterprocessSyncFileTest, TestMultipleFilesDirect) {
+ InterprocessSyncFile sync("test1");
+ InterprocessSyncLocker locker(sync);
+
+ EXPECT_TRUE(locker.lock());
+
+ InterprocessSyncFile sync2("test2");
+ InterprocessSyncLocker locker2(sync2);
+ EXPECT_TRUE(locker2.lock());
+ EXPECT_TRUE(locker2.unlock());
+
+ EXPECT_TRUE(locker.unlock());
+
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test1_lockfile"));
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test2_lockfile"));
+}
+
+TEST(InterprocessSyncFileTest, TestMultipleFilesForked) {
+ InterprocessSyncFile sync("test1");
+ InterprocessSyncLocker locker(sync);
+
+ EXPECT_TRUE(locker.lock());
+
+ if (!isc::util::unittests::runningOnValgrind()) {
+
+ int fds[2];
+
+ EXPECT_EQ(0, pipe(fds));
+
+ if (fork() == 0) {
+ unsigned char locked = 0xff;
+ // Child writes to pipe
+ close(fds[0]);
+
+ InterprocessSyncFile sync2("test2");
+ InterprocessSyncLocker locker2(sync2);
+
+ if (locker2.tryLock()) {
+ locked = 0;
+ }
+
+ ssize_t bytes_written = write(fds[1], &locked, sizeof(locked));
+ EXPECT_EQ(sizeof(locked), bytes_written);
+
+ close(fds[1]);
+ exit(0);
+ } else {
+ // Parent reads from pipe
+ close(fds[1]);
+
+ const unsigned char locked = parentReadState(fds[0]);
+
+ close(fds[0]);
+
+ EXPECT_EQ(0, locked);
+ }
+
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test2_lockfile"));
+ }
+
+ EXPECT_TRUE(locker.unlock());
+
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test1_lockfile"));
+}
+
+} // unnamed namespace
diff --git a/src/lib/log/interprocess/tests/interprocess_sync_null_unittest.cc b/src/lib/log/interprocess/tests/interprocess_sync_null_unittest.cc
new file mode 100644
index 0000000..cc9795c
--- /dev/null
+++ b/src/lib/log/interprocess/tests/interprocess_sync_null_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <log/interprocess/interprocess_sync_null.h>
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc::log::interprocess;
+
+namespace {
+
+TEST(InterprocessSyncNullTest, TestNull) {
+ InterprocessSyncNull sync("test1");
+ InterprocessSyncLocker locker(sync);
+
+ // Check if the is_locked_ flag is set correctly during lock().
+ EXPECT_FALSE(locker.isLocked());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.isLocked());
+
+ // lock() must always return true (this is called 4 times, just an
+ // arbitrary number)
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.lock());
+
+ // Check if the is_locked_ flag is set correctly during unlock().
+ EXPECT_TRUE(locker.isLocked());
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_FALSE(locker.isLocked());
+
+ // unlock() must always return true (this is called 4 times, just an
+ // arbitrary number)
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.unlock());
+
+ // Check if the is_locked_ flag is set correctly during tryLock().
+ EXPECT_FALSE(locker.isLocked());
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.isLocked());
+
+ // tryLock() must always return true (this is called 4 times, just an
+ // arbitrary number)
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.tryLock());
+
+ // Random order (should all return true)
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.tryLock());
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_TRUE(locker.unlock());
+}
+
+}
diff --git a/src/lib/log/interprocess/tests/run_unittests.cc b/src/lib/log/interprocess/tests/run_unittests.cc
new file mode 100644
index 0000000..03fb322
--- /dev/null
+++ b/src/lib/log/interprocess/tests/run_unittests.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <gtest/gtest.h>
+#include <util/unittests/run_all.h>
+#include <stdlib.h>
+
+int
+main(int argc, char* argv[]) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ setenv("B10_LOCKFILE_DIR_FROM_BUILD", TEST_DATA_TOPBUILDDIR, 1);
+ return (isc::util::unittests::run_all());
+}
diff --git a/src/lib/log/logger.cc b/src/lib/log/logger.cc
index fef5627..a04267c 100644
--- a/src/lib/log/logger.cc
+++ b/src/lib/log/logger.cc
@@ -182,7 +182,7 @@ Logger::fatal(const isc::log::MessageID& ident) {
// Replace the interprocess synchronization object
void
-Logger::setInterprocessSync(isc::util::InterprocessSync* sync) {
+Logger::setInterprocessSync(isc::log::interprocess::InterprocessSync* sync) {
getLoggerPtr()->setInterprocessSync(sync);
}
diff --git a/src/lib/log/logger.h b/src/lib/log/logger.h
index e3ba163..de2b304 100644
--- a/src/lib/log/logger.h
+++ b/src/lib/log/logger.h
@@ -25,10 +25,13 @@
#include <log/message_types.h>
#include <log/log_formatter.h>
-#include <util/interprocess_sync.h>
-
namespace isc {
namespace log {
+namespace interprocess {
+// Forward declaration to hide implementation details from normal
+// applications.
+class InterprocessSync;
+}
/// \page LoggingApi Logging API
/// \section LoggingApiOverview Overview
@@ -254,11 +257,16 @@ public:
/// If this method is called with NULL as the argument, it throws a
/// BadInterprocessSync exception.
///
+ /// \note This method is intended to be used only within this log library
+ /// and its tests. Normal application shouldn't use it (in fact,
+ /// normal application shouldn't even be able to instantiate
+ /// InterprocessSync objects).
+ ///
/// \param sync The logger uses this synchronization object for
/// 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);
+ void setInterprocessSync(isc::log::interprocess::InterprocessSync* sync);
/// \brief Equality
///
diff --git a/src/lib/log/logger_impl.cc b/src/lib/log/logger_impl.cc
index 9363738..96f021d 100644
--- a/src/lib/log/logger_impl.cc
+++ b/src/lib/log/logger_impl.cc
@@ -32,16 +32,15 @@
#include <log/logger_manager.h>
#include <log/message_dictionary.h>
#include <log/message_types.h>
+#include <log/interprocess/interprocess_sync_file.h>
#include <util/strutil.h>
-#include <util/interprocess_sync_file.h>
// Note: as log4cplus and the BIND 10 logger have many concepts in common, and
// thus many similar names, to disambiguate types we don't "use" the log4cplus
// namespace: instead, all log4cplus types are explicitly qualified.
using namespace std;
-using namespace isc::util;
namespace isc {
namespace log {
@@ -54,7 +53,7 @@ namespace log {
LoggerImpl::LoggerImpl(const string& name) :
name_(expandLoggerName(name)),
logger_(log4cplus::Logger::getInstance(name_)),
- sync_(new InterprocessSyncFile("logger"))
+ sync_(new interprocess::InterprocessSyncFile("logger"))
{
}
@@ -112,7 +111,8 @@ LoggerImpl::lookupMessage(const MessageID& ident) {
// Replace the interprocess synchronization object
void
-LoggerImpl::setInterprocessSync(isc::util::InterprocessSync* sync) {
+LoggerImpl::setInterprocessSync(isc::log::interprocess::InterprocessSync* sync)
+{
if (sync == NULL) {
isc_throw(BadInterprocessSync,
"NULL was passed to setInterprocessSync()");
@@ -130,7 +130,7 @@ LoggerImpl::outputRaw(const Severity& severity, const string& message) {
// Use an interprocess sync locker for mutual exclusion from other
// processes to avoid log messages getting interspersed.
- InterprocessSyncLocker locker(*sync_);
+ interprocess::InterprocessSyncLocker locker(*sync_);
if (!locker.lock()) {
LOG4CPLUS_ERROR(logger_, "Unable to lock logger lockfile");
diff --git a/src/lib/log/logger_impl.h b/src/lib/log/logger_impl.h
index 7280d5c..d8dea26 100644
--- a/src/lib/log/logger_impl.h
+++ b/src/lib/log/logger_impl.h
@@ -31,8 +31,7 @@
// BIND-10 logger files
#include <log/logger_level_impl.h>
#include <log/message_types.h>
-
-#include <util/interprocess_sync.h>
+#include <log/interprocess/interprocess_sync.h>
namespace isc {
namespace log {
@@ -178,7 +177,7 @@ public:
/// 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);
+ void setInterprocessSync(isc::log::interprocess::InterprocessSync* sync);
/// \brief Equality
///
@@ -193,7 +192,7 @@ public:
private:
std::string name_; ///< Full name of this logger
log4cplus::Logger logger_; ///< Underlying log4cplus logger
- isc::util::InterprocessSync* sync_;
+ isc::log::interprocess::InterprocessSync* sync_;
};
} // namespace log
diff --git a/src/lib/log/logger_manager.cc b/src/lib/log/logger_manager.cc
index 0857441..047c7dc 100644
--- a/src/lib/log/logger_manager.cc
+++ b/src/lib/log/logger_manager.cc
@@ -28,7 +28,7 @@
#include <log/message_initializer.h>
#include <log/message_reader.h>
#include <log/message_types.h>
-#include "util/interprocess_sync_null.h"
+#include <log/interprocess/interprocess_sync_null.h>
using namespace std;
@@ -157,7 +157,8 @@ LoggerManager::readLocalMessageFile(const char* file) {
// be used by standalone programs which may not have write access to
// the local state directory (to create lock files). So we switch to
// using a null interprocess sync object here.
- logger.setInterprocessSync(new isc::util::InterprocessSyncNull("logger"));
+ logger.setInterprocessSync(
+ new isc::log::interprocess::InterprocessSyncNull("logger"));
try {
diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am
index 306d5f9..36582e6 100644
--- a/src/lib/log/tests/Makefile.am
+++ b/src/lib/log/tests/Makefile.am
@@ -25,7 +25,6 @@ logger_example_CPPFLAGS = $(AM_CPPFLAGS)
logger_example_LDFLAGS = $(AM_LDFLAGS)
logger_example_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
logger_example_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
-logger_example_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
logger_example_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
logger_example_LDADD += $(AM_LDADD) $(LOG4CPLUS_LIBS)
@@ -35,7 +34,6 @@ init_logger_test_CPPFLAGS = $(AM_CPPFLAGS)
init_logger_test_LDFLAGS = $(AM_LDFLAGS)
init_logger_test_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
init_logger_test_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
-init_logger_test_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
init_logger_test_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
init_logger_test_LDADD += $(AM_LDADD) $(LOG4CPLUS_LIBS)
@@ -45,10 +43,11 @@ buffer_logger_test_CPPFLAGS = $(AM_CPPFLAGS)
buffer_logger_test_LDFLAGS = $(AM_LDFLAGS)
buffer_logger_test_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
buffer_logger_test_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
-buffer_logger_test_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
buffer_logger_test_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
buffer_logger_test_LDADD += $(AM_LDADD) $(LOG4CPLUS_LIBS)
+# This test directly uses libb10-threads, and on some systems it seems to
+# require explicit LDADD (even if libb10-log has indirect dependencies)
noinst_PROGRAMS += logger_lock_test
logger_lock_test_SOURCES = logger_lock_test.cc
nodist_logger_lock_test_SOURCES = log_test_messages.cc log_test_messages.h
@@ -75,7 +74,6 @@ AM_CPPFLAGS += $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
AM_LDFLAGS += $(GTEST_LDFLAGS)
AM_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
-AM_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
AM_LDADD += $(top_builddir)/src/lib/log/libb10-log.la
AM_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
AM_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
diff --git a/src/lib/log/tests/buffer_logger_test.cc b/src/lib/log/tests/buffer_logger_test.cc
index 8d1b3cf..d703e04 100644
--- a/src/lib/log/tests/buffer_logger_test.cc
+++ b/src/lib/log/tests/buffer_logger_test.cc
@@ -16,7 +16,7 @@
#include <log/logger_support.h>
#include <log/logger_manager.h>
#include <log/log_messages.h>
-#include <util/interprocess_sync_null.h>
+#include <log/interprocess/interprocess_sync_null.h>
using namespace isc::log;
@@ -58,7 +58,8 @@ main(int argc, char** argv) {
initLogger("buffertest", isc::log::INFO, 0, NULL, true);
Logger logger("log");
// No need for file interprocess locking in this test
- logger.setInterprocessSync(new isc::util::InterprocessSyncNull("logger"));
+ logger.setInterprocessSync(
+ new isc::log::interprocess::InterprocessSyncNull("logger"));
LOG_INFO(logger, LOG_BAD_SEVERITY).arg("info");
LOG_DEBUG(logger, 50, LOG_BAD_DESTINATION).arg("debug-50");
LOG_INFO(logger, LOG_BAD_SEVERITY).arg("info");
diff --git a/src/lib/log/tests/logger_example.cc b/src/lib/log/tests/logger_example.cc
index 4b20429..daadb7c 100644
--- a/src/lib/log/tests/logger_example.cc
+++ b/src/lib/log/tests/logger_example.cc
@@ -41,11 +41,11 @@
// Include a set of message definitions.
#include <log/log_messages.h>
-#include "util/interprocess_sync_null.h"
+#include <log/interprocess/interprocess_sync_null.h>
using namespace isc::log;
using namespace std;
-
+using isc::log::interprocess::InterprocessSyncNull;
// Print usage information
@@ -286,11 +286,11 @@ int main(int argc, char** argv) {
// have write access to a local state directory to create
// lockfiles).
isc::log::Logger logger_ex(ROOT_NAME);
- logger_ex.setInterprocessSync(new isc::util::InterprocessSyncNull("logger"));
+ logger_ex.setInterprocessSync(new InterprocessSyncNull("logger"));
isc::log::Logger logger_alpha("alpha");
- logger_alpha.setInterprocessSync(new isc::util::InterprocessSyncNull("logger"));
+ logger_alpha.setInterprocessSync(new InterprocessSyncNull("logger"));
isc::log::Logger logger_beta("beta");
- logger_beta.setInterprocessSync(new isc::util::InterprocessSyncNull("logger"));
+ logger_beta.setInterprocessSync(new InterprocessSyncNull("logger"));
LOG_FATAL(logger_ex, LOG_WRITE_ERROR).arg("test1").arg("42");
LOG_ERROR(logger_ex, LOG_READING_LOCAL_FILE).arg("dummy/file");
diff --git a/src/lib/log/tests/logger_lock_test.cc b/src/lib/log/tests/logger_lock_test.cc
index 7fed5c7..9b9ee17 100644
--- a/src/lib/log/tests/logger_lock_test.cc
+++ b/src/lib/log/tests/logger_lock_test.cc
@@ -16,15 +16,17 @@
#include <log/logger_support.h>
#include <log/logger_manager.h>
#include <log/log_messages.h>
-#include "util/interprocess_sync.h"
+#include <log/interprocess/interprocess_sync.h>
#include "log_test_messages.h"
+
+#include <util/threads/sync.h>
#include <iostream>
using namespace std;
using namespace isc::log;
using isc::util::thread::Mutex;
-class MockLoggingSync : public isc::util::InterprocessSync {
+class MockLoggingSync : public isc::log::interprocess::InterprocessSync {
public:
/// \brief Constructor
MockLoggingSync(const std::string& component_name) :
diff --git a/src/lib/log/tests/logger_unittest.cc b/src/lib/log/tests/logger_unittest.cc
index 7b62d79..77a9d2a 100644
--- a/src/lib/log/tests/logger_unittest.cc
+++ b/src/lib/log/tests/logger_unittest.cc
@@ -20,10 +20,9 @@
#include <log/logger_manager.h>
#include <log/logger_name.h>
#include <log/log_messages.h>
+#include <log/interprocess/interprocess_sync_file.h>
#include "log/tests/log_test_messages.h"
-#include <util/interprocess_sync_file.h>
-
#include <iostream>
#include <string>
@@ -391,7 +390,7 @@ TEST_F(LoggerTest, setInterprocessSync) {
EXPECT_THROW(logger.setInterprocessSync(NULL), BadInterprocessSync);
}
-class MockSync : public isc::util::InterprocessSync {
+class MockSync : public isc::log::interprocess::InterprocessSync {
public:
/// \brief Constructor
MockSync(const std::string& component_name) :
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index 32a9341..ff5ef40 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -4,7 +4,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/exceptions -I$(top_builddir)/src/lib/exceptions
AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -DLOCKFILE_DIR=\"${localstatedir}/${PACKAGE_NAME}\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
# If we use the shared-memory support, corresponding Boost library may
# cause build failures especially if it's strict about warnings. We've
@@ -25,9 +24,6 @@ libb10_util_la_SOURCES += locks.h lru_list.h
libb10_util_la_SOURCES += strutil.h strutil.cc
libb10_util_la_SOURCES += buffer.h io_utilities.h
libb10_util_la_SOURCES += time_utilities.h time_utilities.cc
-libb10_util_la_SOURCES += interprocess_sync.h
-libb10_util_la_SOURCES += interprocess_sync_file.h interprocess_sync_file.cc
-libb10_util_la_SOURCES += interprocess_sync_null.h interprocess_sync_null.cc
libb10_util_la_SOURCES += memory_segment.h
libb10_util_la_SOURCES += memory_segment_local.h memory_segment_local.cc
if USE_SHARED_MEMORY
diff --git a/src/lib/util/interprocess_sync.h b/src/lib/util/interprocess_sync.h
deleted file mode 100644
index f55f0ac..0000000
--- a/src/lib/util/interprocess_sync.h
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef INTERPROCESS_SYNC_H
-#define INTERPROCESS_SYNC_H
-
-#include <string>
-
-namespace isc {
-namespace util {
-
-class InterprocessSyncLocker; // forward declaration
-
-/// \brief Interprocess Sync Class
-///
-/// This class specifies an interface for mutual exclusion among
-/// co-operating processes. This is an abstract class and a real
-/// implementation such as InterprocessSyncFile should be used
-/// in code. Usage is as follows:
-///
-/// 1. Client instantiates a sync object of an implementation (such as
-/// InterprocessSyncFile).
-/// 2. Client then creates an automatic (stack) object of
-/// InterprocessSyncLocker around the sync object. Such an object
-/// destroys itself and releases any acquired lock when it goes out of extent.
-/// 3. Client calls lock() method on the InterprocessSyncLocker.
-/// 4. Client performs task that needs mutual exclusion.
-/// 5. Client frees lock with unlock(), or simply returns from the basic
-/// block which forms the scope for the InterprocessSyncLocker.
-///
-/// NOTE: All implementations of InterprocessSync should keep the
-/// is_locked_ member variable updated whenever their
-/// lock()/tryLock()/unlock() implementations are called.
-class InterprocessSync {
- // InterprocessSyncLocker is the only code outside this class that
- // should be allowed to call the lock(), tryLock() and unlock()
- // methods.
- friend class InterprocessSyncLocker;
-
-public:
- /// \brief Constructor
- ///
- /// Creates an interprocess synchronization object
- ///
- /// \param task_name Name of the synchronization task. This has to be
- /// identical among the various processes that need to be
- /// synchronized for the same task.
- InterprocessSync(const std::string& task_name) :
- task_name_(task_name), is_locked_(false)
- {}
-
- /// \brief Destructor
- virtual ~InterprocessSync() {}
-
-protected:
- /// \brief Acquire the lock (blocks if something else has acquired a
- /// lock on the same task name)
- ///
- /// \return Returns true if the lock was acquired, false otherwise.
- virtual bool lock() = 0;
-
- /// \brief Try to acquire a lock (doesn't block)
- ///
- /// \return Returns true if the lock was acquired, false otherwise.
- virtual bool tryLock() = 0;
-
- /// \brief Release the lock
- ///
- /// \return Returns true if the lock was released, false otherwise.
- virtual bool unlock() = 0;
-
- const std::string task_name_; ///< The task name
- bool is_locked_; ///< Is the lock taken?
-};
-
-/// \brief Interprocess Sync Locker Class
-///
-/// This class is used for making automatic stack objects to manage
-/// locks that are released automatically when the block is exited
-/// (RAII). It is meant to be used along with InterprocessSync objects. See
-/// the description of InterprocessSync.
-class InterprocessSyncLocker {
-public:
- /// \brief Constructor
- ///
- /// Creates a lock manager around a interprocess synchronization object
- ///
- /// \param sync The sync object which has to be locked/unlocked by
- /// this locker object.
- InterprocessSyncLocker(InterprocessSync& sync) :
- sync_(sync)
- {}
-
- /// \brief Destructor
- ~InterprocessSyncLocker() {
- if (isLocked())
- unlock();
- }
-
- /// \brief Acquire the lock (blocks if something else has acquired a
- /// lock on the same task name)
- ///
- /// \return Returns true if the lock was acquired, false otherwise.
- bool lock() {
- return (sync_.lock());
- }
-
- /// \brief Try to acquire a lock (doesn't block)
- ///
- /// \return Returns true if a new lock could be acquired, false
- /// otherwise.
- bool tryLock() {
- return (sync_.tryLock());
- }
-
- /// \brief Check if the lock is taken
- ///
- /// \return Returns true if a lock is currently acquired, false
- /// otherwise.
- bool isLocked() const {
- return (sync_.is_locked_);
- }
-
- /// \brief Release the lock
- ///
- /// \return Returns true if the lock was released, false otherwise.
- bool unlock() {
- return (sync_.unlock());
- }
-
-protected:
- InterprocessSync& sync_; ///< Ref to underlying sync object
-};
-
-} // namespace util
-} // namespace isc
-
-#endif // INTERPROCESS_SYNC_H
diff --git a/src/lib/util/interprocess_sync_file.cc b/src/lib/util/interprocess_sync_file.cc
deleted file mode 100644
index 25af55c..0000000
--- a/src/lib/util/interprocess_sync_file.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include "interprocess_sync_file.h"
-
-#include <string>
-#include <cerrno>
-#include <cstring>
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-namespace isc {
-namespace util {
-
-InterprocessSyncFile::~InterprocessSyncFile() {
- if (fd_ != -1) {
- // This will also release any applied locks.
- close(fd_);
- // The lockfile will continue to exist, and we must not delete
- // it.
- }
-}
-
-bool
-InterprocessSyncFile::do_lock(int cmd, short l_type) {
- // Open lock file only when necessary (i.e., here). This is so that
- // if a default InterprocessSync object is replaced with another
- // implementation, it doesn't attempt any opens.
- if (fd_ == -1) {
- std::string lockfile_path = LOCKFILE_DIR;
-
- const char* const env = getenv("B10_FROM_BUILD");
- if (env != NULL) {
- lockfile_path = env;
- }
-
- const char* const env2 = getenv("B10_FROM_BUILD_LOCALSTATEDIR");
- if (env2 != NULL) {
- lockfile_path = env2;
- }
-
- const char* const env3 = getenv("B10_LOCKFILE_DIR_FROM_BUILD");
- if (env3 != NULL) {
- lockfile_path = env3;
- }
-
- lockfile_path += "/" + task_name_ + "_lockfile";
-
- // Open the lockfile in the constructor so it doesn't do the access
- // checks every time a message is logged.
- const mode_t mode = umask(0111);
- fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR, 0660);
- umask(mode);
-
- if (fd_ == -1) {
- isc_throw(InterprocessSyncFileError,
- "Unable to use interprocess sync lockfile ("
- << std::strerror(errno) << "): " << lockfile_path);
- }
- }
-
- struct flock lock;
-
- memset(&lock, 0, sizeof (lock));
- lock.l_type = l_type;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 1;
-
- return (fcntl(fd_, cmd, &lock) == 0);
-}
-
-bool
-InterprocessSyncFile::lock() {
- if (is_locked_) {
- return (true);
- }
-
- if (do_lock(F_SETLKW, F_WRLCK)) {
- is_locked_ = true;
- return (true);
- }
-
- return (false);
-}
-
-bool
-InterprocessSyncFile::tryLock() {
- if (is_locked_) {
- return (true);
- }
-
- if (do_lock(F_SETLK, F_WRLCK)) {
- is_locked_ = true;
- return (true);
- }
-
- return (false);
-}
-
-bool
-InterprocessSyncFile::unlock() {
- if (!is_locked_) {
- return (true);
- }
-
- if (do_lock(F_SETLKW, F_UNLCK)) {
- is_locked_ = false;
- return (true);
- }
-
- return (false);
-}
-
-} // namespace util
-} // namespace isc
diff --git a/src/lib/util/interprocess_sync_file.h b/src/lib/util/interprocess_sync_file.h
deleted file mode 100644
index 153b391..0000000
--- a/src/lib/util/interprocess_sync_file.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef INTERPROCESS_SYNC_FILE_H
-#define INTERPROCESS_SYNC_FILE_H
-
-#include <util/interprocess_sync.h>
-#include <exceptions/exceptions.h>
-
-namespace isc {
-namespace util {
-
-/// \brief InterprocessSyncFileError
-///
-/// Exception that is thrown if it's not possible to open the
-/// lock file.
-class InterprocessSyncFileError : public Exception {
-public:
- InterprocessSyncFileError(const char* file, size_t line,
- const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// \brief File-based Interprocess Sync Class
-///
-/// This class specifies a concrete implementation for a file-based
-/// interprocess synchronization mechanism. Please see the
-/// InterprocessSync class documentation for usage.
-///
-/// An InterprocessSyncFileError exception may be thrown if there is an
-/// issue opening the lock file.
-///
-/// Lock files are created typically in the local state directory
-/// (var). They are typically named like "<task_name>_lockfile".
-/// This implementation opens lock files lazily (only when
-/// necessary). It also leaves the lock files lying around as multiple
-/// processes may have locks on them.
-class InterprocessSyncFile : public InterprocessSync {
-public:
- /// \brief Constructor
- ///
- /// Creates a file-based interprocess synchronization object
- ///
- /// \param name Name of the synchronization task. This has to be
- /// identical among the various processes that need to be
- /// synchronized for the same task.
- InterprocessSyncFile(const std::string& task_name) :
- InterprocessSync(task_name), fd_(-1)
- {}
-
- /// \brief Destructor
- virtual ~InterprocessSyncFile();
-
-protected:
- /// \brief Acquire the lock (blocks if something else has acquired a
- /// lock on the same task name)
- ///
- /// \return Returns true if the lock was acquired, false otherwise.
- bool lock();
-
- /// \brief Try to acquire a lock (doesn't block)
- ///
- /// \return Returns true if the lock was acquired, false otherwise.
- bool tryLock();
-
- /// \brief Release the lock
- ///
- /// \return Returns true if the lock was released, false otherwise.
- bool unlock();
-
-private:
- bool do_lock(int cmd, short l_type);
-
- int fd_; ///< The descriptor for the open file
-};
-
-} // namespace util
-} // namespace isc
-
-#endif // INTERPROCESS_SYNC_FILE_H
diff --git a/src/lib/util/interprocess_sync_null.cc b/src/lib/util/interprocess_sync_null.cc
deleted file mode 100644
index 5355d57..0000000
--- a/src/lib/util/interprocess_sync_null.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include "interprocess_sync_null.h"
-
-namespace isc {
-namespace util {
-
-InterprocessSyncNull::~InterprocessSyncNull() {
-}
-
-bool
-InterprocessSyncNull::lock() {
- is_locked_ = true;
- return (true);
-}
-
-bool
-InterprocessSyncNull::tryLock() {
- is_locked_ = true;
- return (true);
-}
-
-bool
-InterprocessSyncNull::unlock() {
- is_locked_ = false;
- return (true);
-}
-
-} // namespace util
-} // namespace isc
diff --git a/src/lib/util/interprocess_sync_null.h b/src/lib/util/interprocess_sync_null.h
deleted file mode 100644
index be77514..0000000
--- a/src/lib/util/interprocess_sync_null.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef INTERPROCESS_SYNC_NULL_H
-#define INTERPROCESS_SYNC_NULL_H
-
-#include <util/interprocess_sync.h>
-
-namespace isc {
-namespace util {
-
-/// \brief Null Interprocess Sync Class
-///
-/// This class specifies a concrete implementation for a null (no effect)
-/// interprocess synchronization mechanism. Please see the
-/// InterprocessSync class documentation for usage.
-class InterprocessSyncNull : public InterprocessSync {
-public:
- /// \brief Constructor
- ///
- /// Creates a null interprocess synchronization object
- ///
- /// \param name Name of the synchronization task. This has to be
- /// identical among the various processes that need to be
- /// synchronized for the same task.
- InterprocessSyncNull(const std::string& task_name) :
- InterprocessSync(task_name)
- {}
-
- /// \brief Destructor
- virtual ~InterprocessSyncNull();
-
-protected:
- /// \brief Acquire the lock (never blocks)
- ///
- /// \return Always returns true
- bool lock();
-
- /// \brief Try to acquire a lock (doesn't block)
- ///
- /// \return Always returns true
- bool tryLock();
-
- /// \brief Release the lock
- ///
- /// \return Always returns true
- bool unlock();
-};
-
-} // namespace util
-} // namespace isc
-
-#endif // INTERPROCESS_SYNC_NULL_H
diff --git a/src/lib/util/tests/Makefile.am b/src/lib/util/tests/Makefile.am
index 3ee16f9..ab85fa2 100644
--- a/src/lib/util/tests/Makefile.am
+++ b/src/lib/util/tests/Makefile.am
@@ -31,8 +31,6 @@ run_unittests_SOURCES += filename_unittest.cc
run_unittests_SOURCES += hex_unittest.cc
run_unittests_SOURCES += io_utilities_unittest.cc
run_unittests_SOURCES += lru_list_unittest.cc
-run_unittests_SOURCES += interprocess_sync_file_unittest.cc
-run_unittests_SOURCES += interprocess_sync_null_unittest.cc
run_unittests_SOURCES += memory_segment_local_unittest.cc
if USE_SHARED_MEMORY
run_unittests_SOURCES += memory_segment_mapped_unittest.cc
@@ -46,7 +44,6 @@ run_unittests_SOURCES += socketsession_unittest.cc
run_unittests_SOURCES += strutil_unittest.cc
run_unittests_SOURCES += time_utilities_unittest.cc
run_unittests_SOURCES += range_utilities_unittest.cc
-run_unittests_SOURCES += interprocess_util.h interprocess_util.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
diff --git a/src/lib/util/tests/interprocess_sync_file_unittest.cc b/src/lib/util/tests/interprocess_sync_file_unittest.cc
deleted file mode 100644
index 38d9026..0000000
--- a/src/lib/util/tests/interprocess_sync_file_unittest.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <util/interprocess_sync_file.h>
-
-#include <util/unittests/check_valgrind.h>
-#include <util/tests/interprocess_util.h>
-#include <gtest/gtest.h>
-#include <unistd.h>
-
-using namespace std;
-using isc::util::test::parentReadState;
-
-namespace isc {
-namespace util {
-
-namespace {
-TEST(InterprocessSyncFileTest, TestLock) {
- InterprocessSyncFile sync("test");
- InterprocessSyncLocker locker(sync);
-
- EXPECT_FALSE(locker.isLocked());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.isLocked());
-
- if (!isc::util::unittests::runningOnValgrind()) {
-
- int fds[2];
-
- // Here, we check that a lock has been taken by forking and
- // checking from the child that a lock exists. This has to be
- // done from a separate process as we test by trying to lock the
- // range again on the lock file. The lock attempt would pass if
- // done from the same process for the granted range. The lock
- // attempt must fail to pass our check.
-
- EXPECT_EQ(0, pipe(fds));
-
- if (fork() == 0) {
- unsigned char locked = 0;
- // Child writes to pipe
- close(fds[0]);
-
- InterprocessSyncFile sync2("test");
- InterprocessSyncLocker locker2(sync2);
-
- if (!locker2.tryLock()) {
- EXPECT_FALSE(locker2.isLocked());
- locked = 1;
- } else {
- EXPECT_TRUE(locker2.isLocked());
- }
-
- ssize_t bytes_written = write(fds[1], &locked, sizeof(locked));
- EXPECT_EQ(sizeof(locked), bytes_written);
-
- close(fds[1]);
- exit(0);
- } else {
- // Parent reads from pipe
- close(fds[1]);
-
- const unsigned char locked = parentReadState(fds[0]);
-
- close(fds[0]);
-
- EXPECT_EQ(1, locked);
- }
- }
-
- EXPECT_TRUE(locker.unlock());
- EXPECT_FALSE(locker.isLocked());
-
- EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
-}
-
-TEST(InterprocessSyncFileTest, TestMultipleFilesDirect) {
- InterprocessSyncFile sync("test1");
- InterprocessSyncLocker locker(sync);
-
- EXPECT_TRUE(locker.lock());
-
- InterprocessSyncFile sync2("test2");
- InterprocessSyncLocker locker2(sync2);
- EXPECT_TRUE(locker2.lock());
- EXPECT_TRUE(locker2.unlock());
-
- EXPECT_TRUE(locker.unlock());
-
- EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test1_lockfile"));
- EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test2_lockfile"));
-}
-
-TEST(InterprocessSyncFileTest, TestMultipleFilesForked) {
- InterprocessSyncFile sync("test1");
- InterprocessSyncLocker locker(sync);
-
- EXPECT_TRUE(locker.lock());
-
- if (!isc::util::unittests::runningOnValgrind()) {
-
- int fds[2];
-
- EXPECT_EQ(0, pipe(fds));
-
- if (fork() == 0) {
- unsigned char locked = 0xff;
- // Child writes to pipe
- close(fds[0]);
-
- InterprocessSyncFile sync2("test2");
- InterprocessSyncLocker locker2(sync2);
-
- if (locker2.tryLock()) {
- locked = 0;
- }
-
- ssize_t bytes_written = write(fds[1], &locked, sizeof(locked));
- EXPECT_EQ(sizeof(locked), bytes_written);
-
- close(fds[1]);
- exit(0);
- } else {
- // Parent reads from pipe
- close(fds[1]);
-
- const unsigned char locked = parentReadState(fds[0]);
-
- close(fds[0]);
-
- EXPECT_EQ(0, locked);
- }
-
- EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test2_lockfile"));
- }
-
- EXPECT_TRUE(locker.unlock());
-
- EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test1_lockfile"));
-}
-
-} // anonymous namespace
-} // namespace util
-} // namespace isc
diff --git a/src/lib/util/tests/interprocess_sync_null_unittest.cc b/src/lib/util/tests/interprocess_sync_null_unittest.cc
deleted file mode 100644
index 70e2b07..0000000
--- a/src/lib/util/tests/interprocess_sync_null_unittest.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include "util/interprocess_sync_null.h"
-#include <gtest/gtest.h>
-
-using namespace std;
-
-namespace isc {
-namespace util {
-
-TEST(InterprocessSyncNullTest, TestNull) {
- InterprocessSyncNull sync("test1");
- InterprocessSyncLocker locker(sync);
-
- // Check if the is_locked_ flag is set correctly during lock().
- EXPECT_FALSE(locker.isLocked());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.isLocked());
-
- // lock() must always return true (this is called 4 times, just an
- // arbitrary number)
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.lock());
-
- // Check if the is_locked_ flag is set correctly during unlock().
- EXPECT_TRUE(locker.isLocked());
- EXPECT_TRUE(locker.unlock());
- EXPECT_FALSE(locker.isLocked());
-
- // unlock() must always return true (this is called 4 times, just an
- // arbitrary number)
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.unlock());
-
- // Check if the is_locked_ flag is set correctly during tryLock().
- EXPECT_FALSE(locker.isLocked());
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.isLocked());
-
- // tryLock() must always return true (this is called 4 times, just an
- // arbitrary number)
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.tryLock());
-
- // Random order (should all return true)
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.lock());
- EXPECT_TRUE(locker.tryLock());
- EXPECT_TRUE(locker.unlock());
- EXPECT_TRUE(locker.unlock());
-}
-
-} // namespace util
-} // namespace isc
diff --git a/src/lib/util/tests/interprocess_util.cc b/src/lib/util/tests/interprocess_util.cc
deleted file mode 100644
index dfb04b7..0000000
--- a/src/lib/util/tests/interprocess_util.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <gtest/gtest.h>
-
-#include <sys/select.h>
-#include <cstddef>
-
-namespace isc {
-namespace util {
-namespace test {
-
-unsigned char
-parentReadState(int fd) {
- unsigned char result = 0xff;
-
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
-
- struct timeval tv = {5, 0};
-
- const int nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
- EXPECT_EQ(1, nfds);
-
- if (nfds == 1) {
- // Read status
- const ssize_t bytes_read = read(fd, &result, sizeof(result));
- EXPECT_EQ(sizeof(result), bytes_read);
- }
-
- return (result);
-}
-
-}
-}
-}
diff --git a/src/lib/util/tests/interprocess_util.h b/src/lib/util/tests/interprocess_util.h
deleted file mode 100644
index 286f9cf..0000000
--- a/src/lib/util/tests/interprocess_util.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-namespace isc {
-namespace util {
-namespace test {
-/// \brief A helper utility for a simple synchronization with another process.
-///
-/// It waits for incoming data on a given file descriptor up to 5 seconds
-/// (arbitrary choice), read one byte data, and return it to the caller.
-/// On any failure it returns 0xff (255), so the sender process should use
-/// a different value to pass.
-unsigned char parentReadState(int fd);
-}
-}
-}
-
-// Local Variables:
-// mode: c++
-// End:
diff --git a/src/lib/util/tests/memory_segment_mapped_unittest.cc b/src/lib/util/tests/memory_segment_mapped_unittest.cc
index dc8dffc..475d3e5 100644
--- a/src/lib/util/tests/memory_segment_mapped_unittest.cc
+++ b/src/lib/util/tests/memory_segment_mapped_unittest.cc
@@ -14,7 +14,7 @@
#include <util/tests/memory_segment_common_unittest.h>
#include <util/unittests/check_valgrind.h>
-#include <util/tests/interprocess_util.h>
+#include <util/unittests/interprocess_util.h>
#include <util/memory_segment_mapped.h>
#include <exceptions/exceptions.h>
@@ -42,7 +42,7 @@
using namespace isc::util;
using boost::scoped_ptr;
-using isc::util::test::parentReadState;
+using isc::util::unittests::parentReadState;
namespace {
// Shortcut to keep code shorter
diff --git a/src/lib/util/tests/run_unittests.cc b/src/lib/util/tests/run_unittests.cc
index 8789a9c..41761ca 100644
--- a/src/lib/util/tests/run_unittests.cc
+++ b/src/lib/util/tests/run_unittests.cc
@@ -20,6 +20,5 @@ int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
- setenv("B10_LOCKFILE_DIR_FROM_BUILD", TEST_DATA_TOPBUILDDIR, 1);
return (isc::util::unittests::run_all());
}
diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am
index 55e0372..657c2aa 100644
--- a/src/lib/util/unittests/Makefile.am
+++ b/src/lib/util/unittests/Makefile.am
@@ -11,6 +11,7 @@ libutil_unittests_la_SOURCES += check_valgrind.h check_valgrind.cc
libutil_unittests_la_SOURCES += run_all.h run_all.cc
libutil_unittests_la_SOURCES += textdata.h
libutil_unittests_la_SOURCES += wiredata.h wiredata.cc
+libutil_unittests_la_SOURCES += interprocess_util.h interprocess_util.cc
endif
# For now, this isn't needed for libutil_unittests
diff --git a/src/lib/util/unittests/interprocess_util.cc b/src/lib/util/unittests/interprocess_util.cc
new file mode 100644
index 0000000..ce858d4
--- /dev/null
+++ b/src/lib/util/unittests/interprocess_util.cc
@@ -0,0 +1,48 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <gtest/gtest.h>
+
+#include <sys/select.h>
+#include <cstddef>
+
+namespace isc {
+namespace util {
+namespace unittests {
+
+unsigned char
+parentReadState(int fd) {
+ unsigned char result = 0xff;
+
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+
+ struct timeval tv = {5, 0};
+
+ const int nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
+ EXPECT_EQ(1, nfds);
+
+ if (nfds == 1) {
+ // Read status
+ const ssize_t bytes_read = read(fd, &result, sizeof(result));
+ EXPECT_EQ(sizeof(result), bytes_read);
+ }
+
+ return (result);
+}
+
+}
+}
+}
diff --git a/src/lib/util/unittests/interprocess_util.h b/src/lib/util/unittests/interprocess_util.h
new file mode 100644
index 0000000..f25ad3e
--- /dev/null
+++ b/src/lib/util/unittests/interprocess_util.h
@@ -0,0 +1,31 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+namespace isc {
+namespace util {
+namespace unittests {
+/// \brief A helper utility for a simple synchronization with another process.
+///
+/// It waits for incoming data on a given file descriptor up to 5 seconds
+/// (arbitrary choice), read one byte data, and return it to the caller.
+/// On any failure it returns 0xff (255), so the sender process should use
+/// a different value to pass.
+unsigned char parentReadState(int fd);
+}
+}
+}
+
+// Local Variables:
+// mode: c++
+// End:
More information about the bind10-changes
mailing list