You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/05/06 23:17:25 UTC
git commit: Added DynamicLibrary to stout.
Repository: mesos
Updated Branches:
refs/heads/master 5044bc831 -> f76ab279b
Added DynamicLibrary to stout.
Addition of DynamicLibrary class to stout, to enable future plugins
inside of mesos.
Review: https://reviews.apache.org/r/21013
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f76ab279
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f76ab279
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f76ab279
Branch: refs/heads/master
Commit: f76ab279b55bef3e1b9b0982cbd401ac300f2a82
Parents: 5044bc8
Author: Timothy St. Clair <ts...@redhat.com>
Authored: Tue May 6 13:45:56 2014 -0700
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Tue May 6 14:08:25 2014 -0700
----------------------------------------------------------------------
3rdparty/libprocess/3rdparty/Makefile.am | 4 +-
3rdparty/libprocess/3rdparty/stout/Makefile.am | 2 +
.../stout/include/stout/dynamiclibrary.hpp | 91 ++++++++++++++++++++
.../stout/tests/dynamiclibrary_tests.cpp | 39 +++++++++
3rdparty/libprocess/configure.ac | 7 ++
5 files changed, 142 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f76ab279/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index 980146b..4ddb6a5 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -134,6 +134,7 @@ stout_tests_SOURCES = \
$(STOUT)/tests/bytes_tests.cpp \
$(STOUT)/tests/cache_tests.cpp \
$(STOUT)/tests/duration_tests.cpp \
+ $(STOUT)/tests/dynamiclibrary_tests.cpp \
$(STOUT)/tests/error_tests.cpp \
$(STOUT)/tests/flags_tests.cpp \
$(STOUT)/tests/gzip_tests.cpp \
@@ -180,7 +181,8 @@ endif
stout_tests_LDADD = \
libgmock.la \
$(GLOG)/libglog.la \
- $(PROTOBUF)/src/libprotobuf.la
+ $(PROTOBUF)/src/libprotobuf.la \
+ -ldl
# We use a check-local target for now to avoid the parallel test
# runner that ships with newer versions of autotools.
http://git-wip-us.apache.org/repos/asf/mesos/blob/f76ab279/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index aa1d0a5..a9269ad 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -11,6 +11,7 @@ EXTRA_DIST = \
include/stout/cache.hpp \
include/stout/check.hpp \
include/stout/duration.hpp \
+ include/stout/dynamiclibrary.hpp \
include/stout/error.hpp \
include/stout/exit.hpp \
include/stout/fatal.hpp \
@@ -75,6 +76,7 @@ EXTRA_DIST = \
tests/bytes_tests.cpp \
tests/cache_tests.cpp \
tests/duration_tests.cpp \
+ tests/dynamiclibrary_tests.cpp \
tests/error_tests.cpp \
tests/flags_tests.cpp \
tests/gzip_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/f76ab279/3rdparty/libprocess/3rdparty/stout/include/stout/dynamiclibrary.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/dynamiclibrary.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/dynamiclibrary.hpp
new file mode 100644
index 0000000..067be3a
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/dynamiclibrary.hpp
@@ -0,0 +1,91 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_DYNAMICLIBRARY_HPP__
+#define __STOUT_DYNAMICLIBRARY_HPP__
+
+#include <dlfcn.h>
+
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+/**
+ * DynamicLibrary is a very simple wrapper around the programming interface
+ * to the dynamic linking loader.
+ */
+class DynamicLibrary
+{
+public:
+ DynamicLibrary() : handle_(NULL) { }
+
+ virtual ~DynamicLibrary()
+ {
+ if (handle_ != NULL) {
+ close();
+ }
+ }
+
+ Try<Nothing> open(const std::string& path)
+ {
+ // Check if we've already opened a library.
+ if (handle_ != NULL) {
+ return Error("Library already opened");
+ }
+
+ handle_ = dlopen(path.c_str(), RTLD_NOW);
+
+ if (handle_ == NULL) {
+ return Error(
+ "Could not load library '" + path +
+ "': " + dlerror());
+ }
+
+ path_ = path;
+
+ return Nothing();
+ }
+
+ Try<Nothing> close()
+ {
+ if (dlclose(handle_) != 0) {
+ return Error(
+ "Could not close library '" +
+ (path_.isSome() ? path_.get() : "") + "': " + dlerror());
+ }
+
+ handle_ = NULL;
+ path_ = None();
+
+ return Nothing();
+ }
+
+ Try<void*> loadSymbol(const std::string& name)
+ {
+ void* symbol = dlsym(handle_, name.c_str());
+
+ if (symbol == NULL) {
+ return Error(
+ "Error looking up symbol '" + name + "' in '" +
+ (path_.isSome() ? path_.get() : "") + "' : " + dlerror());
+ }
+
+ return symbol;
+ }
+
+private:
+ void* handle_;
+ Option<std::string> path_;
+};
+
+#endif // __STOUT_DYNAMICLIBRARY_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/f76ab279/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
new file mode 100644
index 0000000..4cc781b
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/dynamiclibrary_tests.cpp
@@ -0,0 +1,39 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stout/dynamiclibrary.hpp>
+#include <stout/gtest.hpp>
+#include <stout/some.hpp>
+
+// Test that we can dynamically load the library, that loads libraries.
+TEST(DynamicLibraryTest, LoadKnownSymbol)
+{
+ DynamicLibrary dltest;
+
+#ifdef __linux__
+ Try<Nothing> result = dltest.open("libdl.so");
+#else
+ Try<Nothing> result = dltest.open("libdl.dylib");
+#endif
+
+ EXPECT_SOME(result);
+
+ Try<void*> symbol = dltest.loadSymbol("dlopen");
+
+ EXPECT_SOME(symbol);
+
+ result = dltest.close();
+ EXPECT_SOME(result);
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/f76ab279/3rdparty/libprocess/configure.ac
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/configure.ac b/3rdparty/libprocess/configure.ac
index 0c7cc6d..a32c479 100644
--- a/3rdparty/libprocess/configure.ac
+++ b/3rdparty/libprocess/configure.ac
@@ -256,5 +256,12 @@ if test "x$with_cxx11" = "xyes"; then
CONFIGURE_ARGS="$CONFIGURE_ARGS CXXFLAGS='$CXXFLAGS'"
fi
+AC_CHECK_LIB([dl], [dlopen], [AC_MSG_RESULT([found])],
+ [AC_MSG_ERROR([cannot find libdl
+-------------------------------------------------------------------
+libdl was not found, and is required for compilation.
+-------------------------------------------------------------------
+])])
+
AC_OUTPUT