blob: 5253c1caaf756f63999fcc60d69c54c8d3fc2593 [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
Patrick Venture1d5cccb2018-11-13 13:08:03 -080023 /* 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+$")))
Patrick Venture4dc584d2018-09-27 15:00:46 -070029 {
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