summaryrefslogtreecommitdiffstats
path: root/src/lib/datasrc
diff options
context:
space:
mode:
authorJelte Jansen <jelte@isc.org>2011-11-23 20:15:51 +0100
committerJelte Jansen <jelte@isc.org>2011-11-23 20:15:51 +0100
commit3e1a6afcabbef24f9501d8f4e3ed27d824db4309 (patch)
treea4a373fd75102723bbca052666d6fc92b671ac03 /src/lib/datasrc
parent[master] ChangeLog for Trac 1330 (diff)
downloadkea-3e1a6afcabbef24f9501d8f4e3ed27d824db4309.tar.xz
kea-3e1a6afcabbef24f9501d8f4e3ed27d824db4309.zip
[trac1290] medium-term solution to the ld_path hack
DataSourceClient intializer now calls a helper function that modifies the datasource type, so that dlopen() always gets an absolute path Also updated the lettuce test so that when bindctl fails when sending a command, its output is printed
Diffstat (limited to 'src/lib/datasrc')
-rw-r--r--src/lib/datasrc/datasrc_config.h.in15
-rw-r--r--src/lib/datasrc/factory.cc42
-rw-r--r--src/lib/datasrc/factory.h7
-rw-r--r--src/lib/datasrc/tests/Makefile.am17
4 files changed, 79 insertions, 2 deletions
diff --git a/src/lib/datasrc/datasrc_config.h.in b/src/lib/datasrc/datasrc_config.h.in
new file mode 100644
index 0000000000..c1bc0f4069
--- /dev/null
+++ b/src/lib/datasrc/datasrc_config.h.in
@@ -0,0 +1,15 @@
+// Copyright (C) 2011 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.
+
+#define MODULE_PATH "@prefix@/lib/"
diff --git a/src/lib/datasrc/factory.cc b/src/lib/datasrc/factory.cc
index 1818c70e19..b8f53535dc 100644
--- a/src/lib/datasrc/factory.cc
+++ b/src/lib/datasrc/factory.cc
@@ -19,6 +19,8 @@
#include "sqlite3_accessor.h"
#include "memory_datasrc.h"
+#include "datasrc_config.h"
+
#include <datasrc/logger.h>
#include <dlfcn.h>
@@ -26,6 +28,44 @@
using namespace isc::data;
using namespace isc::datasrc;
+namespace {
+// This helper function takes the 'type' string as passed to
+// the DataSourceClient container below, and, unless it
+// already specifies a specific loadable .so file, will
+// convert the short-name to the full file.
+// I.e. it will add '_ds.so' (if necessary), and prepend
+// it with an absolute path (if necessary).
+// Returns the resulting string to use with LibraryContainer.
+const std::string getDataSourceLibFile(std::string type) {
+ std::string lib_file = type;
+ if (type.length() == 0) {
+ isc_throw(DataSourceError,
+ "DataSourceClient container called with empty type value");
+ }
+
+ // Type can be either a short name, in which case we need to
+ // append "_ds.so", or it can be a direct .so module.
+ const int ext_pos = lib_file.rfind(".so");
+ if (ext_pos == std::string::npos ||
+ ext_pos + 3 != lib_file.length()) {
+ lib_file.append("_ds.so");
+ }
+ // And if it is not an absolute path, prepend it with our
+ // module path
+ if (type[0] != '/') {
+ // When running from the build tree, we do NOT want
+ // to load the installed module
+ if (getenv("B10_FROM_BUILD")) {
+ lib_file = std::string(getenv("B10_FROM_BUILD")) +
+ "/src/lib/datasrc/.libs/" + lib_file;
+ } else {
+ lib_file = MODULE_PATH + lib_file;
+ }
+ }
+ return lib_file;
+}
+} // end anonymous namespace
+
namespace isc {
namespace datasrc {
@@ -61,7 +101,7 @@ LibraryContainer::getSym(const char* name) {
DataSourceClientContainer::DataSourceClientContainer(const std::string& type,
ConstElementPtr config)
-: ds_lib_(type + "_ds.so")
+: ds_lib_(getDataSourceLibFile(type))
{
// We are casting from a data to a function pointer here
// Some compilers (rightfully) complain about that, but
diff --git a/src/lib/datasrc/factory.h b/src/lib/datasrc/factory.h
index 0284067dd3..761a1fe2ff 100644
--- a/src/lib/datasrc/factory.h
+++ b/src/lib/datasrc/factory.h
@@ -115,6 +115,13 @@ private:
/// easy recognition and to reduce potential mistakes.
/// For example, the sqlite3 implementation has the type 'sqlite3', and the
/// derived filename 'sqlite3_ds.so'
+/// The value of type can be a specific loadable module; if it already ends
+/// with '.so', the loader will not add '_ds.so'.
+/// It may also be an absolute path; if it starts with '/', nothing is
+/// prepended. If it does not, the loadable module will be taken from the
+/// installation library directory.
+/// \note When 'B10_FROM_BUILD' is set in the environment, the build
+/// directory is used instead of the install directory.
///
/// There are of course some demands to an implementation, not all of which
/// can be verified compile-time. It must provide a creator and destructor
diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am
index 70f29994e0..fb6d43f04e 100644
--- a/src/lib/datasrc/tests/Makefile.am
+++ b/src/lib/datasrc/tests/Makefile.am
@@ -60,7 +60,7 @@ if !USE_STATIC_LINK
# troubles with static link such as "missing" symbols in the static object
# for the module. As a workaround we disable this particualr test
# in this case.
-run_unittests_SOURCES += factory_unittest.cc
+#run_unittests_SOURCES += factory_unittest.cc
endif
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
@@ -110,3 +110,18 @@ EXTRA_DIST += testdata/test.sqlite3
EXTRA_DIST += testdata/test.sqlite3.nodiffs
EXTRA_DIST += testdata/rwtest.sqlite3
EXTRA_DIST += testdata/diffs.sqlite3
+
+# For the factory unit tests, we need to specify that we want
+# the libraries from the build tree, and not from the installation
+# directory. Therefore we build it into a separate binary,
+# and call that from check-local with B10_FROM_BUILD set.
+# Also, we only want to do this when static building is not used.
+noinst_PROGRAMS+=run_unittests_factory
+run_unittests_factory_SOURCES = $(common_sources)
+run_unittests_factory_SOURCES += factory_unittest.cc
+run_unittests_factory_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_factory_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+run_unittests_factory_LDADD = $(common_ldadd)
+check-local:
+ B10_FROM_BUILD=${abs_top_builddir} ./run_unittests_factory
+