Skip to content

Commit

Permalink
Merge pull request #1711 from jhett12321/clean-ld-preload
Browse files Browse the repository at this point in the history
Clean NWNX binaries from LD_PRELOAD.
  • Loading branch information
mtijanic committed Dec 4, 2023
2 parents 18a4f80 + 45b5f75 commit 51162c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Core/NWNXCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ NWNXCore::NWNXCore()
: m_ScriptChunkRecursion(0)
{
g_core = this;
CleanupPreload();

// NOTE: We should do the version check here, but the global in the binary hasn't been initialised yet at this point.
// This will be fixed in a future release of NWNX:EE. For now, the version check will happen *too late* - we may
Expand All @@ -145,6 +146,20 @@ NWNXCore::~NWNXCore()
Shutdown();
}

void NWNXCore::CleanupPreload()
{
const auto* preload = std::getenv("LD_PRELOAD");
const std::regex regex("(([^: ]+)?NWNX_[^: ]+)");

std::string newPreload = preload;
while (std::regex_search(newPreload, regex))
{
newPreload = std::regex_replace(newPreload, regex, "");
}

setenv("LD_PRELOAD", newPreload.c_str(), true);
}

std::unique_ptr<Services::ServiceList> NWNXCore::ConstructCoreServices()
{
using namespace NWNXLib::Services;
Expand Down
1 change: 1 addition & 0 deletions Core/NWNXCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NWNXCore
std::unique_ptr<NWNXLib::Services::ServiceList> ConstructCoreServices();
std::unique_ptr<NWNXLib::Services::ProxyServiceList> ConstructProxyServices(const std::string& plugin);

void CleanupPreload();
void ConfigureLogLevel(const std::string& plugin);

void InitialSetupHooks();
Expand Down

0 comments on commit 51162c5

Please sign in to comment.