mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
preserve environment
This commit is contained in:
parent
ae7dcc4253
commit
265236f6de
@ -755,26 +755,68 @@ start_p3dpython(P3DInstance *inst) {
|
|||||||
// Populate the new process' environment.
|
// Populate the new process' environment.
|
||||||
_env = string();
|
_env = string();
|
||||||
|
|
||||||
// These are the enviroment variables we forward from the current
|
if (!inst_mgr->get_trusted_environment()) {
|
||||||
// environment, if they are set.
|
// These are the enviroment variables we forward from the current
|
||||||
const char *keep[] = {
|
// environment, if they are set.
|
||||||
"TMP", "TEMP", "HOME", "USER",
|
const char *keep[] = {
|
||||||
|
"TMP", "TEMP", "HOME", "USER",
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
"SYSTEMROOT", "USERPROFILE", "COMSPEC", "PANDA_ROOT",
|
"SYSTEMROOT", "USERPROFILE", "COMSPEC", "PANDA_ROOT",
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
"DISPLAY",
|
"DISPLAY",
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
for (int ki = 0; keep[ki] != NULL; ++ki) {
|
for (int ki = 0; keep[ki] != NULL; ++ki) {
|
||||||
char *value = getenv(keep[ki]);
|
char *value = getenv(keep[ki]);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
_env += keep[ki];
|
_env += keep[ki];
|
||||||
_env += "=";
|
_env += "=";
|
||||||
_env += value;
|
_env += value;
|
||||||
_env += '\0';
|
_env += '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// In a trusted environment, we forward *all* environment
|
||||||
|
// variables, except those defined specifically below.
|
||||||
|
const char *dont_keep[] = {
|
||||||
|
"PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH",
|
||||||
|
"PYTHONPATH", "PYTHONHOME", "PRC_PATH", "PANDA_PRC_PATH",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Windows has a leading underscore in the name, and the word
|
||||||
|
// "environ" is a keyword. (!)
|
||||||
|
extern char **_environ;
|
||||||
|
char **global_environ = _environ;
|
||||||
|
#else
|
||||||
|
// Posix doesn't have an underscore.
|
||||||
|
extern char **environ;
|
||||||
|
char **global_environ = environ;
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
|
char **ep;
|
||||||
|
for (ep = global_environ; *ep != NULL; ++ep) {
|
||||||
|
string env = *ep;
|
||||||
|
size_t equals = env.find('=');
|
||||||
|
if (equals != string::npos) {
|
||||||
|
string var = env.substr(0, equals);
|
||||||
|
const char *varc = var.c_str();
|
||||||
|
bool found = false;
|
||||||
|
for (int i = 0; dont_keep[i] != NULL && !found; ++i) {
|
||||||
|
found = (strcmp(dont_keep[i], varc) == 0);
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
// This variable is OK, keep it.
|
||||||
|
_env += env;
|
||||||
|
_env += '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define some new environment variables.
|
// Define some new environment variables.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user