diff --git a/src/posix.cpp b/src/posix.cpp index fa9140e2dd..e0c341a70e 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -152,7 +152,7 @@ pathOfExecutable(System* s, const char** retBuf, unsigned* size) #endif } -const bool Verbose = false; +const bool Verbose = true; const unsigned Waiting = 1 << 0; const unsigned Notified = 1 << 1; @@ -483,9 +483,10 @@ class MySystem: public System { class Library: public System::Library { public: Library(System* s, void* p, const char* name, unsigned nameLength, - bool mapName): + bool mapName, bool isMain): s(s), p(p), + mainExecutable(isMain), name_(name), nameLength(nameLength), mapName_(mapName), @@ -517,7 +518,7 @@ class MySystem: public System { fprintf(stderr, "close %p\n", p); } - dlclose(p); + if (!mainExecutable) dlclose(p); if (next_) { next_->disposeAll(); @@ -532,6 +533,7 @@ class MySystem: public System { System* s; void* p; + bool mainExecutable; const char* name_; unsigned nameLength; bool mapName_; @@ -683,6 +685,7 @@ class MySystem: public System { { void* p; bool alreadyAllocated = false; + bool isMain = false; unsigned nameLength = (name ? strlen(name) : 0); if (mapName) { unsigned size = nameLength + 3 + sizeof(SO_SUFFIX); @@ -693,6 +696,7 @@ class MySystem: public System { if (!name) { pathOfExecutable(this, &name, &nameLength); alreadyAllocated = true; + isMain = true; } p = dlopen(name, RTLD_LAZY); } @@ -714,7 +718,7 @@ class MySystem: public System { } *lib = new (allocate(this, sizeof(Library))) - Library(this, p, n, nameLength, mapName); + Library(this, p, n, nameLength, mapName, isMain); return 0; } else {