diff options
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | utils.cpp | 37 | ||||
-rw-r--r-- | utils.hpp | 15 |
4 files changed, 64 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index 9373ea2..9027e47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,12 +13,17 @@ libblobcmds_la_SOURCES = main.cpp \ manager.cpp \ process.cpp \ crc.cpp \ + utils.cpp \ $(HANDLERS) libblobcmds_la_LDFLAGS = $(SYSTEMD_LIBS) \ + $(LIBADD_DLOPEN) \ + $(PHOSPHOR_LOGGING_LIBS) \ + -lstdc++fs \ -version-info 0:0:0 -shared -libblobcmds_la_CXXFLAGS = $(SYSTEMD_CFLAGS) +libblobcmds_la_CXXFLAGS = $(SYSTEMD_CFLAGS) \ + $(PHOSPHOR_LOGGING_CFLAGS) nobase_include_HEADERS = \ blobs-ipmid/blobs.hpp \ diff --git a/configure.ac b/configure.ac index 97d54d6..21fcde9 100644 --- a/configure.ac +++ b/configure.ac @@ -16,13 +16,16 @@ AC_PROG_MAKE_SET AX_CXX_COMPILE_STDCXX_17([noext]) AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS]) +# Checks for library functions. +LT_INIT([dlopen]) # Required for systemd linking +LT_LIB_DLLOAD + # Checks for libraries. +PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, [AC_MSG_ERROR([Could not find phosphor-logging...openbmc/phosphor-logging package required])]) AC_CHECK_HEADER([host-ipmid], [AC_MSG_ERROR(["phosphor-host-ipmid required and not found."])]) +AC_CHECK_HEADER(experimental/filesystem, ,[AC_MSG_ERROR([Could not find experimental/filesystem...libstdc++fs developement package required])]) AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])]) -# Checks for library functions. -LT_INIT # Required for systemd linking - # Check/set gtest specific functions. PKG_CHECK_MODULES([GTEST], [gtest], [], [AC_MSG_NOTICE([gtest not found, tests will not build])]) PKG_CHECK_MODULES([GMOCK], [gmock], [], [AC_MSG_NOTICE([gmock not found, tests will not build])]) diff --git a/utils.cpp b/utils.cpp new file mode 100644 index 0000000..1daa3c9 --- /dev/null +++ b/utils.cpp @@ -0,0 +1,37 @@ +#include "utils.hpp" + +#include <dlfcn.h> + +#include <experimental/filesystem> +#include <phosphor-logging/log.hpp> +#include <regex> + +namespace blobs +{ + +namespace fs = std::experimental::filesystem; +using namespace phosphor::logging; + +void loadLibraries(const std::string& path) +{ + void* libHandle = NULL; + + for (const auto& p : fs::recursive_directory_iterator(path)) + { + auto ps = p.path().string(); + + if (!std::regex_match(ps, std::regex(".+\\.so$"))) + { + continue; + } + + libHandle = dlopen(ps.c_str(), RTLD_NOW); + if (!libHandle) + { + log<level::ERR>("ERROR opening", entry("HANDLER=%s", ps.c_str()), + entry("ERROR=%s", dlerror())); + } + } +} + +} // namespace blobs diff --git a/utils.hpp b/utils.hpp new file mode 100644 index 0000000..9b75a40 --- /dev/null +++ b/utils.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include <string> + +namespace blobs +{ + +/** + * @brief Given a path, find libraries (*.so only) and load them. + * + * @param[in] paths - list of fully qualified paths to libraries to load. + */ +void loadLibraries(const std::string& path); + +} // namespace blobs |