|
@@ -177,21 +177,43 @@ start_p3dcert() {
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
// Populate the new process' environment.
|
|
// Populate the new process' environment.
|
|
|
|
|
+
|
|
|
|
|
+#ifdef _WIN32
|
|
|
|
|
+ // These are the enviroment variables we forward from the current
|
|
|
|
|
+ // environment, if they are set.
|
|
|
|
|
+ const wchar_t *keep[] = {
|
|
|
|
|
+ L"TMP", L"TEMP", L"HOME", L"USER",
|
|
|
|
|
+ L"SYSTEMROOT", L"USERPROFILE", L"COMSPEC",
|
|
|
|
|
+ NULL
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ wstring env_w;
|
|
|
|
|
+
|
|
|
|
|
+ for (int ki = 0; keep[ki] != NULL; ++ki) {
|
|
|
|
|
+ wchar_t *value = _wgetenv(keep[ki]);
|
|
|
|
|
+ if (value != NULL) {
|
|
|
|
|
+ env_w += keep[ki];
|
|
|
|
|
+ env_w += L"=";
|
|
|
|
|
+ env_w += value;
|
|
|
|
|
+ env_w += (wchar_t)'\0';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wstring_to_string(_env, env_w);
|
|
|
|
|
+
|
|
|
|
|
+#else // _WIN32
|
|
|
|
|
+
|
|
|
_env = string();
|
|
_env = string();
|
|
|
|
|
|
|
|
// These are the enviroment variables we forward from the current
|
|
// These are the enviroment variables we forward from the current
|
|
|
// environment, if they are set.
|
|
// environment, if they are set.
|
|
|
const char *keep[] = {
|
|
const char *keep[] = {
|
|
|
"TMP", "TEMP", "HOME", "USER",
|
|
"TMP", "TEMP", "HOME", "USER",
|
|
|
-#ifdef _WIN32
|
|
|
|
|
- "SYSTEMROOT", "USERPROFILE", "COMSPEC",
|
|
|
|
|
-#endif
|
|
|
|
|
#ifdef HAVE_X11
|
|
#ifdef HAVE_X11
|
|
|
"DISPLAY", "XAUTHORITY",
|
|
"DISPLAY", "XAUTHORITY",
|
|
|
#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) {
|
|
@@ -201,6 +223,7 @@ start_p3dcert() {
|
|
|
_env += '\0';
|
|
_env += '\0';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+#endif // _WIN32
|
|
|
|
|
|
|
|
// Define some new environment variables.
|
|
// Define some new environment variables.
|
|
|
_env += "PATH=";
|
|
_env += "PATH=";
|
|
@@ -219,6 +242,9 @@ start_p3dcert() {
|
|
|
_env += root_dir;
|
|
_env += root_dir;
|
|
|
_env += '\0';
|
|
_env += '\0';
|
|
|
|
|
|
|
|
|
|
+ nout << "Setting environment:\n";
|
|
|
|
|
+ write_env();
|
|
|
|
|
+
|
|
|
nout << "Attempting to start p3dcert from " << _p3dcert_exe << "\n";
|
|
nout << "Attempting to start p3dcert from " << _p3dcert_exe << "\n";
|
|
|
|
|
|
|
|
bool started_p3dcert = false;
|
|
bool started_p3dcert = false;
|
|
@@ -268,6 +294,27 @@ join_wait_thread() {
|
|
|
_started_wait_thread = false;
|
|
_started_wait_thread = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: P3DAuthSession::write_env
|
|
|
|
|
+// Access: Private
|
|
|
|
|
+// Description: Writes _env, which is formatted as a string
|
|
|
|
|
+// containing zero-byte-terminated environment
|
|
|
|
|
+// defintions, to the nout stream, one definition per
|
|
|
|
|
+// line.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+void P3DAuthSession::
|
|
|
|
|
+write_env() const {
|
|
|
|
|
+ size_t p = 0;
|
|
|
|
|
+ size_t zero = _env.find('\0', p);
|
|
|
|
|
+ while (zero != string::npos) {
|
|
|
|
|
+ nout << " ";
|
|
|
|
|
+ nout.write(_env.data() + p, zero - p);
|
|
|
|
|
+ nout << "\n";
|
|
|
|
|
+ p = zero + 1;
|
|
|
|
|
+ zero = _env.find('\0', p);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: P3DAuthSession::wt_thread_run
|
|
// Function: P3DAuthSession::wt_thread_run
|
|
|
// Access: Private
|
|
// Access: Private
|
|
@@ -332,7 +379,7 @@ win_create_process() {
|
|
|
// Make sure we see an error dialog if there is a missing DLL.
|
|
// Make sure we see an error dialog if there is a missing DLL.
|
|
|
SetErrorMode(0);
|
|
SetErrorMode(0);
|
|
|
|
|
|
|
|
- STARTUPINFOW startup_info;
|
|
|
|
|
|
|
+ STARTUPINFO startup_info;
|
|
|
ZeroMemory(&startup_info, sizeof(startup_info));
|
|
ZeroMemory(&startup_info, sizeof(startup_info));
|
|
|
startup_info.cb = sizeof(startup_info);
|
|
startup_info.cb = sizeof(startup_info);
|
|
|
|
|
|
|
@@ -340,34 +387,32 @@ win_create_process() {
|
|
|
startup_info.wShowWindow = SW_SHOW;
|
|
startup_info.wShowWindow = SW_SHOW;
|
|
|
startup_info.dwFlags |= STARTF_USESHOWWINDOW;
|
|
startup_info.dwFlags |= STARTF_USESHOWWINDOW;
|
|
|
|
|
|
|
|
- const wchar_t *start_dir_cstr;
|
|
|
|
|
- wstring start_dir_w;
|
|
|
|
|
- string_to_wstring(start_dir_w, _start_dir);
|
|
|
|
|
- start_dir_cstr = start_dir_w.c_str();
|
|
|
|
|
|
|
+ const char *start_dir_cstr = _start_dir.c_str();
|
|
|
|
|
|
|
|
// Construct the command-line string, containing the quoted
|
|
// Construct the command-line string, containing the quoted
|
|
|
// command-line arguments.
|
|
// command-line arguments.
|
|
|
ostringstream stream;
|
|
ostringstream stream;
|
|
|
stream << "\"" << _p3dcert_exe << "\" \""
|
|
stream << "\"" << _p3dcert_exe << "\" \""
|
|
|
- << _cert_filename->get_filename() << "\" \""
|
|
|
|
|
- << _cert_dir << "\"";
|
|
|
|
|
|
|
+ << _cert_filename->get_filename() << "\" \"" << _cert_dir << "\"";
|
|
|
|
|
|
|
|
// I'm not sure why CreateProcess wants a non-const char pointer for
|
|
// I'm not sure why CreateProcess wants a non-const char pointer for
|
|
|
// its command-line string, but I'm not taking chances. It gets a
|
|
// its command-line string, but I'm not taking chances. It gets a
|
|
|
// non-const char array that it can modify.
|
|
// non-const char array that it can modify.
|
|
|
- wstring command_line_str;
|
|
|
|
|
- string_to_wstring(command_line_str, stream.str());
|
|
|
|
|
- wchar_t *command_line = new wchar_t[command_line_str.size() + 1];
|
|
|
|
|
- memcpy(command_line, command_line_str.c_str(), sizeof(wchar_t) * command_line_str.size() + 1);
|
|
|
|
|
|
|
+ string command_line_str = stream.str();
|
|
|
|
|
+ char *command_line = new char[command_line_str.size() + 1];
|
|
|
|
|
+ memcpy(command_line, command_line_str.c_str(), command_line_str.size() + 1);
|
|
|
|
|
|
|
|
- wstring p3dcert_exe_w;
|
|
|
|
|
- string_to_wstring(p3dcert_exe_w, _p3dcert_exe);
|
|
|
|
|
|
|
+ nout << "Command line: " << command_line_str << "\n";
|
|
|
|
|
|
|
|
|
|
+ // Something about p3dCert_wx tends to become crashy when we call it
|
|
|
|
|
+ // from CreateProcessW(). Something about the way wx parses the
|
|
|
|
|
+ // command-line parameters? Well, whatever, we don't really need
|
|
|
|
|
+ // the Unicode form anyway.
|
|
|
PROCESS_INFORMATION process_info;
|
|
PROCESS_INFORMATION process_info;
|
|
|
- BOOL result = CreateProcessW
|
|
|
|
|
- (p3dcert_exe_w.c_str(), command_line, NULL, NULL, TRUE, 0,
|
|
|
|
|
- (void *)_env.c_str(), start_dir_cstr,
|
|
|
|
|
- &startup_info, &process_info);
|
|
|
|
|
|
|
+ BOOL result = CreateProcess
|
|
|
|
|
+ (_p3dcert_exe.c_str(), command_line, NULL, NULL, TRUE,
|
|
|
|
|
+ 0, (void *)_env.c_str(),
|
|
|
|
|
+ start_dir_cstr, &startup_info, &process_info);
|
|
|
bool started_program = (result != 0);
|
|
bool started_program = (result != 0);
|
|
|
|
|
|
|
|
delete[] command_line;
|
|
delete[] command_line;
|