blob: 1daa3c971648d3f33be6c6f664b0199d3c86c8d5 [file] [log] [blame]
Patrick Venture4dc584d2018-09-27 15:00:46 -07001#include "utils.hpp"
2
3#include <dlfcn.h>
4
5#include <experimental/filesystem>
6#include <phosphor-logging/log.hpp>
7#include <regex>
8
9namespace blobs
10{
11
12namespace fs = std::experimental::filesystem;
13using namespace phosphor::logging;
14
15void loadLibraries(const std::string& path)
16{
17 void* libHandle = NULL;
18
19 for (const auto& p : fs::recursive_directory_iterator(path))
20 {
21 auto ps = p.path().string();
22
23 if (!std::regex_match(ps, std::regex(".+\\.so$")))
24 {
25 continue;
26 }
27
28 libHandle = dlopen(ps.c_str(), RTLD_NOW);
29 if (!libHandle)
30 {
31 log<level::ERR>("ERROR opening", entry("HANDLER=%s", ps.c_str()),
32 entry("ERROR=%s", dlerror()));
33 }
34 }
35}
36
37} // namespace blobs