Search plugins in system directories and LD_LIBRARY_PATH

Fixes #133
This commit is contained in:
Dennis Klein 2019-01-31 21:28:08 +01:00 committed by Dennis Klein
parent e2e476ba19
commit c0771c81d6

View File

@ -29,7 +29,7 @@ using boost::optional;
const std::string fair::mq::PluginManager::fgkLibPrefix = "FairMQPlugin_"; const std::string fair::mq::PluginManager::fgkLibPrefix = "FairMQPlugin_";
fair::mq::PluginManager::PluginManager() fair::mq::PluginManager::PluginManager()
: fSearchPaths{{"."}} : fSearchPaths{}
, fPluginFactories() , fPluginFactories()
, fPluginServices() , fPluginServices()
, fPlugins() , fPlugins()
@ -39,7 +39,7 @@ fair::mq::PluginManager::PluginManager()
} }
fair::mq::PluginManager::PluginManager(const vector<string> args) fair::mq::PluginManager::PluginManager(const vector<string> args)
: fSearchPaths{{"."}} : fSearchPaths{}
, fPluginFactories() , fPluginFactories()
, fPluginServices() , fPluginServices()
, fPlugins() , fPlugins()
@ -115,7 +115,8 @@ auto fair::mq::PluginManager::ProgramOptions() -> po::options_description
"* Append(>) or prepend(<) to default search path, e.g.\n" "* Append(>) or prepend(<) to default search path, e.g.\n"
" -S >/lib </home/user/lib\n" " -S >/lib </home/user/lib\n"
"* If you mix the overriding and appending/prepending syntaxes, the overriding paths act as default search path, e.g.\n" "* If you mix the overriding and appending/prepending syntaxes, the overriding paths act as default search path, e.g.\n"
" -S /usr/lib >/lib </home/user/lib /usr/local/lib results in /home/user/lib,/usr/local/lib,/usr/lib/,/lib") " -S /usr/lib >/lib </home/user/lib /usr/local/lib results in /home/user/lib,/usr/local/lib,/usr/lib/,/lib\n"
"If nothing is found, the default dynamic library lookup is performed, see man ld.so(8) for details.")
("plugin,P", po::value<vector<string>>(), "List of plugin names to load in order," ("plugin,P", po::value<vector<string>>(), "List of plugin names to load in order,"
"e.g. if the file is called 'libFairMQPlugin_example.so', just list 'example' or 'd:example' here." "e.g. if the file is called 'libFairMQPlugin_example.so', just list 'example' or 'd:example' here."
"To load a prelinked plugin, list 'p:example' here."); "To load a prelinked plugin, list 'p:example' here.");
@ -170,29 +171,42 @@ auto fair::mq::PluginManager::LoadPluginDynamic(const string& pluginName) -> voi
if (fPluginFactories.find(pluginName) == fPluginFactories.end()) if (fPluginFactories.find(pluginName) == fPluginFactories.end())
{ {
auto success = false; auto success = false;
for(const auto& searchPath : SearchPaths()) for (const auto& searchPath : SearchPaths()) {
{ try {
try LoadSymbols(pluginName,
{ searchPath / ToString(LibPrefix(), pluginName),
LoadSymbols( dll::load_mode::append_decorations);
pluginName,
searchPath / ToString(LibPrefix(), pluginName),
dll::load_mode::append_decorations
);
fPluginOrder.push_back(pluginName); fPluginOrder.push_back(pluginName);
success = true; success = true;
break; break;
} } catch (boost::system::system_error& e) {
catch (boost::system::system_error& e) if (string{e.what()}.find("No such file or directory") == string::npos) {
{ throw PluginLoadError(
if(string{e.what()}.find("No such file or directory") == string::npos) ToString("An error occurred while loading dynamic plugin ",
{ pluginName, ": ", e.what()));
throw PluginLoadError(ToString("An error occurred while loading dynamic plugin ", pluginName, ": ", e.what()));
} }
} }
} }
if(!success) { throw PluginLoadError(ToString("The plugin ", pluginName, " could not be found in the plugin search paths.")); }
if (!success) {
try {
// LoadSymbols(pluginName,
// ToString(LibPrefix(), pluginName),
// dll::load_mode::search_system_folders | dll::load_mode::append_decorations);
// Not sure, why the above does not work. Workaround for now:
LoadSymbols(pluginName,
ToString("lib",
LibPrefix(),
pluginName,
boost::dll::detail::shared_library_impl::suffix().native()),
dll::load_mode::search_system_folders);
fPluginOrder.push_back(pluginName);
} catch (boost::system::system_error& e) {
throw PluginLoadError(
ToString("An error occurred while loading dynamic plugin ",
pluginName, ": ", e.what()));
}
}
} }
} }