Skip to content

Commit

Permalink
Added check that plumed is not loaded in the global namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed Mar 1, 2024
1 parent caea68c commit c69c199
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cltools/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <cstdio>
#include <random>
#include <algorithm>
#if defined(__PLUMED_HAS_DLOPEN)
#include <dlfcn.h>
#endif

namespace PLMD {
namespace cltools {
Expand Down Expand Up @@ -213,6 +216,21 @@ int Benchmark::main(FILE* in, FILE*out,Communicator& pc) {

plumed_assert(allplumed.size()>0 && allpaths.size()>0);

#if defined(__PLUMED_HAS_DLOPEN)
if(std::any_of(allpaths.begin(),allpaths.end(),[](auto value) {return value != "this";})) {
#if defined(__PLUMED_HAS_RTLD_DEFAULT)
void* handle=RTLD_DEFAULT;
#else
handle=dlopen(NULL,RTLD_LOCAL);
#endif
if(dlsym(handle,"plumed_plumedmain_create") || dlsym(handle,"plumedmain_create")) {
plumed_error()<<"It looks like libplumed is loaded in the global namespace, you cannot load a different version of the kernel\n"
<<"Please make sure you use the plumed-runtime executable and that the env var PLUMED_LOAD_NAMESPACE is not set to GLOBAL";
}
if(handle) dlclose(handle);
}
#endif

if(allplumed.size()>1 && allpaths.size()>1 && allplumed.size() != allpaths.size()) {
plumed_error() << "--kernel and --plumed should have either one element or the same number of elements";
}
Expand Down

0 comments on commit c69c199

Please sign in to comment.