Commit aa528462 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] Merge branch 'trac2899-2'

parents e561cb2e 3471a0a3
......@@ -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
......
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
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
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.
......@@ -18,7 +18,8 @@
#include <string>
namespace isc {
namespace util {
namespace log {
namespace interprocess {
class InterprocessSyncLocker; // forward declaration
......@@ -143,7 +144,8 @@ protected:
InterprocessSync& sync_; ///< Ref to underlying sync object
};
} // namespace util
} // namespace interprocess
} // namespace log
} // namespace isc
#endif // INTERPROCESS_SYNC_H
......@@ -12,7 +12,7 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include "interprocess_sync_file.h"
#include <log/interprocess/interprocess_sync_file.h>
#include <string>
#include <cerrno>
......@@ -26,7 +26,8 @@
#include <sys/stat.h>
namespace isc {
namespace util {
namespace log {
namespace interprocess {
InterprocessSyncFile::~InterprocessSyncFile() {
if (fd_ != -1) {
......@@ -128,5 +129,6 @@ InterprocessSyncFile::unlock() {
return (false);
}
} // namespace util
} // namespace interprocess
} // namespace log
} // namespace isc
......@@ -15,11 +15,12 @@
#ifndef INTERPROCESS_SYNC_FILE_H
#define INTERPROCESS_SYNC_FILE_H
#include <util/interprocess_sync.h>
#include <log/interprocess/interprocess_sync.h>
#include <exceptions/exceptions.h>
namespace isc {
namespace util {
namespace log {
namespace interprocess {
/// \brief InterprocessSyncFileError
///
......@@ -85,7 +86,8 @@ private:
int fd_; ///< The descriptor for the open file
};
} // namespace util
} // namespace interprocess
} // namespace log
} // namespace isc
#endif // INTERPROCESS_SYNC_FILE_H
......@@ -12,10 +12,11 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include "interprocess_sync_null.h"
#include <log/interprocess/interprocess_sync_null.h>
namespace isc {
namespace util {
namespace log {
namespace interprocess {
InterprocessSyncNull::~InterprocessSyncNull() {
}
......@@ -38,5 +39,6 @@ InterprocessSyncNull::unlock() {
return (true);
}
} // namespace util
} // namespace interprocess
} // namespace log
} // namespace isc
......@@ -15,10 +15,11 @@
#ifndef INTERPROCESS_SYNC_NULL_H
#define INTERPROCESS_SYNC_NULL_H
#include <util/interprocess_sync.h>
#include <log/interprocess/interprocess_sync.h>
namespace isc {
namespace util {
namespace log {
namespace interprocess {
/// \brief Null Interprocess Sync Class
///
......@@ -58,7 +59,8 @@ protected:
bool unlock();
};
} // namespace util
} // namespace interprocess
} // namespace log
} // namespace isc
#endif // INTERPROCESS_SYNC_NULL_H
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)
......@@ -12,18 +12,16 @@
// 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 <log/interprocess/interprocess_sync_file.h>
#include <util/unittests/check_valgrind.h>
#include <util/tests/interprocess_util.h>
#include <util/unittests/interprocess_util.h>
#include <gtest/gtest.h>
#include <unistd.h>
using namespace std;
using isc::util::test::parentReadState;
namespace isc {
namespace util {
using namespace isc::log::interprocess;
using isc::util::unittests::parentReadState;
namespace {
TEST(InterprocessSyncFileTest, TestLock) {
......@@ -150,6 +148,4 @@ TEST(InterprocessSyncFileTest, TestMultipleFilesForked) {
EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test1_lockfile"));
}
} // anonymous namespace
} // namespace util
} // namespace isc
} // unnamed namespace
......@@ -12,13 +12,13 @@
// 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 <log/interprocess/interprocess_sync_null.h>
#include <gtest/gtest.h>
using namespace std;
using namespace isc::log::interprocess;
namespace isc {
namespace util {
namespace {
TEST(InterprocessSyncNullTest, TestNull) {
InterprocessSyncNull sync("test1");
......@@ -72,5 +72,4 @@ TEST(InterprocessSyncNullTest, TestNull) {
EXPECT_TRUE(locker.unlock());
}
} // namespace util
} // namespace isc
}
// 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());
}
......@@ -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);
}
......
......@@ -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
///
......
......@@ -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");
......
......@@ -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
......
......@@ -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 {
......
......@@ -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
......
......@@ -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");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment