Skip to content

Commit

Permalink
add some printing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisspyB committed Oct 24, 2024
1 parent 4550f54 commit fbd5544
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/eckit/system/LibraryManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,47 +201,55 @@ class LibraryRegistry {
}

// now we try with the system LD_LIBRARY_PATH environment variable
Log::debug() << "Loading library " << dynamicLibraryName << " from LD_LIBRARY_PATH or system paths"
<< std::endl;
Log::warning() << "Loading library " << dynamicLibraryName << " from LD_LIBRARY_PATH or system paths"
<< "LD_LIBRARY_PATH=" << ::getenv("LD_LIBRARY_PATH")
<< std::endl;
void* plib = ::dlopen(dynamicLibraryName.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (plib) {
Log::debug() << "Loaded library " << path_from_libhandle(dynamicLibraryName, plib) << std::endl;
return plib;
}
Log::warning() << "Failed to load library " << dynamicLibraryName
<< "dlerror: " << ::dlerror()
<< std::endl;

Log::warning() << "Failed to load library " << dynamicLibraryName << std::endl;
return nullptr;
return nullptr; // <-- this is awful, upstream function will throw with the wrong error message as a result
}

Plugin* lookupPlugin(const std::string& name) const {
std::cout << "XXX: lookupPlugin " << name << std::endl;
auto it = plugins_.find(name);
if (it != plugins_.end()) {
std::string libname = it->second;
std::cout << "XXX: lookupPlugin: plugin found: name=" << name << " and libname=" << libname << std::endl;
return dynamic_cast<Plugin*>(&lookup(libname));
}
std::cout << "XXX: lookupPlugin: plugin not found :(" << std::endl;
return nullptr;
}

Plugin& loadPlugin(const std::string& name, const std::string& libname = std::string()) {

std::cout << "XXX: loadPlugin " << name << " " << libname << std::endl;
AutoLock<Mutex> lockme(mutex_);

std::string lib = libname.empty() ? name : libname;

// check if respective library is already loaded
if (!exists(lib)) {
std::cout << "XXX: loadPlugin: lib not yet loaded (loading now) lib= " << lib << std::endl;

// lets load since the associated library isn't registered
void* libhandle = loadDynamicLibrary(lib);

// the plugin should self-register when the library loads
Plugin* plugin = lookupPlugin(name);
Plugin* plugin = lookupPlugin(name);
if (plugin) {
Log::debug() << "Loaded plugin [" << name << "] from library [" << lib << "]" << std::endl;
plugin->handle(libhandle);
initPlugin(plugin);
return *plugin;
}
std::cout << "XXX: plugin is null apparently" << std::endl;
// If the plugin library still doesn't exist after a successful call of dlopen, then
// we have managed to load something other than a (self-registering) eckit Plugin library
std::ostringstream ss;
Expand Down

0 comments on commit fbd5544

Please sign in to comment.