My program uses an existing library with limited documentation, over which I have no control. For the purposes of this question it is used as follows:
#include <theirlib.hpp>
using their_lib::Node;
int main ( int argc, char** argv )
{
Node my_node;
// connect to the master communication server
my_node.init();
// ...
}
For reasons best known to itself, init()
takes no parameters, instead trying to find the URI of the communication server (as well as other parameters) from an environment variable. I can see this with ltrace
:
...
15:43:24 libtheirlib.so->getenv("THEIRLIB_MASTER_URI") = nil <0.000173>
...
Now, I can wrap my program with a script and set the environment variables beforehand, but what if I want to be able to change them at runtime? I can use setenv()
but this still strikes me as polluting the environment, and what if I want to connect to multiple master servers at once?
What are my options (if any) to prevent theirlib
from using environment variables to change its behaviour and force it to use a value I can supply in code?