xref: /openbmc/phosphor-ipmi-blobs/utils.cpp (revision 1d5cccb5837f210d8156811e87cdb111c2037d80)
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         /* The bitbake recipe symlinks the library lib*.so.? into the folder
24          * only, and not the other names, .so, .so.?.?, .so.?.?.?
25          *
26          * Therefore only care if it's lib*.so.?
27          */
28         if (!std::regex_match(ps, std::regex(".+\\.so\\.\\d+$")))
29         {
30             continue;
31         }
32 
33         libHandle = dlopen(ps.c_str(), RTLD_NOW);
34         if (!libHandle)
35         {
36             log<level::ERR>("ERROR opening", entry("HANDLER=%s", ps.c_str()),
37                             entry("ERROR=%s", dlerror()));
38         }
39     }
40 }
41 
42 } // namespace blobs
43