xref: /openbmc/phosphor-ipmi-blobs/utils.cpp (revision 5100a386)
1 #include "utils.hpp"
2 
3 #include <dlfcn.h>
4 
5 #include <experimental/filesystem>
6 #include <phosphor-logging/log.hpp>
7 #include <regex>
8 
9 namespace blobs
10 {
11 
12 namespace fs = std::experimental::filesystem;
13 using namespace phosphor::logging;
14 
15 void 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
38