From 4ae6c835cb69332e982babcfca1a4e5657ec8bbd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 3 Aug 2011 14:50:51 -0700 Subject: Add some hacks to get stdin piping working more correctly in windows The way pipes work in windows is not the same as unix, though I'm not entirely clear on the differences. This patch changes the windows pipe method to return non-inheritable fds, and the windows rust_run_program method to duplicate them before spawning the new process. This allows make-check-pretty to work on windows. --- src/rt/rust_run_program.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/rt') diff --git a/src/rt/rust_run_program.cpp b/src/rt/rust_run_program.cpp index c89aaf6bcbd..69f3cf7e146 100644 --- a/src/rt/rust_run_program.cpp +++ b/src/rt/rust_run_program.cpp @@ -12,9 +12,20 @@ rust_run_program(void* task, const char* argv[], ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES; - si.hStdInput = (HANDLE)_get_osfhandle(in_fd ? in_fd : 0); - si.hStdOutput = (HANDLE)_get_osfhandle(out_fd ? out_fd : 1); - si.hStdError = (HANDLE)_get_osfhandle(err_fd ? err_fd : 2); + + HANDLE curproc = GetCurrentProcess(); + HANDLE origStdin = (HANDLE)_get_osfhandle(in_fd ? in_fd : 0); + if (!DuplicateHandle(curproc, origStdin, + curproc, &si.hStdInput, 0, 1, DUPLICATE_SAME_ACCESS)) + return -1; + HANDLE origStdout = (HANDLE)_get_osfhandle(out_fd ? out_fd : 1); + if (!DuplicateHandle(curproc, origStdout, + curproc, &si.hStdOutput, 0, 1, DUPLICATE_SAME_ACCESS)) + return -1; + HANDLE origStderr = (HANDLE)_get_osfhandle(err_fd ? err_fd : 2); + if (!DuplicateHandle(curproc, origStderr, + curproc, &si.hStdError, 0, 1, DUPLICATE_SAME_ACCESS)) + return -1; size_t cmd_len = 0; for (const char** arg = argv; *arg; arg++) { @@ -32,6 +43,10 @@ rust_run_program(void* task, const char* argv[], PROCESS_INFORMATION pi; BOOL created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); + + CloseHandle(si.hStdInput); + CloseHandle(si.hStdOutput); + CloseHandle(si.hStdError); free(cmd); if (!created) return -1; -- cgit 1.4.1-3-g733a5