#include "ATOOLS/Org/Library_Loader.H" #include "ATOOLS/Org/Shell_Tools.H" #include "ATOOLS/Org/Exception.H" #include "ATOOLS/Org/Message.H" #include "ATOOLS/Org/Run_Parameter.H" #include "ATOOLS/Org/CXXFLAGS.H" #include #include #include #include #include #include using namespace ATOOLS; Library_Loader *ATOOLS::s_loader(NULL); Library_Loader::Library_Loader(): m_wait(3600), m_check(false) { m_paths.push_back(rpa->gen.Variable("SHERPA_RUN_PATH")); m_paths.push_back(rpa->gen.Variable("SHERPA_LIBRARY_PATH")); const std::vector &paths(EnvironmentVariable(LD_PATH_NAME)); m_paths.insert(m_paths.end(),paths.begin(),paths.end()); } bool Library_Loader::CreateLockFile(const std::string &lockname) { if (m_check) { msg_Debugging()<<"checking lock file '"<Error()<::iterator lit(m_libs.find(name)); if (lit!=m_libs.end()) m_libs.erase(lit); dlclose(module); } bool Library_Loader::LibraryIsLoaded(const std::string &name) { std::map::iterator lit(m_libs.find(name)); if (lit!=m_libs.end()) return true; return false; } void *Library_Loader::LoadLibrary(const std::string &name) { std::map::iterator lit(m_libs.find(name)); if (lit!=m_libs.end()) return lit->second; msg_Debugging()<<"loading library 'lib"<gen.Variable("HOME")+ "/.sherpa/.liblock")) return NULL; void *module(dlopen(fullpath.c_str(),RTLD_LAZY|RTLD_GLOBAL)); if (!RemoveLockFile(rpa->gen.Variable("HOME")+ "/.sherpa/.liblock")) return NULL; if (!RemoveLockFile(lockname)) return NULL; char *err(dlerror()); if (err!=NULL) THROW(fatal_error, std::string("Error loading library: ") + err); assert(module!=NULL); return module; } void *Library_Loader::GetLibraryFunction(const std::string &libname, const std::string &funcname) { msg_Debugging()<<"executing library function '"<