Skip to content
Snippets Groups Projects
Commit 13d83395 authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

Prevent duplicate loading of plugins if they are in the path twice.

parent 177363ad
No related branches found
No related tags found
Loading
Pipeline #13550 failed
...@@ -212,6 +212,7 @@ void ZiprPluginManager_t::open_plugins ...@@ -212,6 +212,7 @@ void ZiprPluginManager_t::open_plugins
) )
{ {
const auto ziprPluginDirs=splitVar(getenv("ZIPR_PLUGIN_PATH")); const auto ziprPluginDirs=splitVar(getenv("ZIPR_PLUGIN_PATH"));
auto loadedBasenames = set<string>();
for(const auto dir : ziprPluginDirs) for(const auto dir : ziprPluginDirs)
{ {
...@@ -226,6 +227,15 @@ void ZiprPluginManager_t::open_plugins ...@@ -226,6 +227,15 @@ void ZiprPluginManager_t::open_plugins
while ((dirp = readdir(dp)) != nullptr) while ((dirp = readdir(dp)) != nullptr)
{ {
const auto basename = string(dirp->d_name); const auto basename = string(dirp->d_name);
if(loadedBasenames.find(basename) != loadedBasenames.end())
{
if (m_verbose)
cout<<"Already loaded "<<basename<<". Skipping..."<<endl;
continue;
}
loadedBasenames.insert(basename);
const auto name=dir+'/'+basename; const auto name=dir+'/'+basename;
const auto zpi=string(".zpi"); const auto zpi=string(".zpi");
const auto extension=name.substr(name.size() - zpi.length()); const auto extension=name.substr(name.size() - zpi.length());
...@@ -239,9 +249,21 @@ void ZiprPluginManager_t::open_plugins ...@@ -239,9 +249,21 @@ void ZiprPluginManager_t::open_plugins
cout<<"File ("<<name<<") does not have proper extension, skipping."<<endl; cout<<"File ("<<name<<") does not have proper extension, skipping."<<endl;
continue; // try next file continue; // try next file
} }
// test if this library is already loaded, can happen when
// an entry in ZIPR_PLUGIN_PATH is duplicated.
const auto isLoaded = dlopen(name.c_str(), RTLD_LAZY|RTLD_GLOBAL|RTLD_NOLOAD) != nullptr;
if(isLoaded)
{
if (m_verbose)
cout<<"File ("<<name<<") already loaded."<<endl;
continue;
}
if (m_verbose) if (m_verbose)
cout<<"Attempting load of file ("<<name<<")."<<endl; cout<<"Attempting load of file ("<<name<<")."<<endl;
// actuall load
const auto handle=dlopen(name.c_str(), RTLD_LAZY|RTLD_GLOBAL); const auto handle=dlopen(name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
if(!handle) if(!handle)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment