do not call dlclose on the main executable (to avoid crashes)

This commit is contained in:
Eric Scharff 2008-02-20 09:41:30 -07:00
parent 85abd14137
commit 8f4cb3315a

View File

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