about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-08-03 14:50:51 -0700
committerBrian Anderson <banderson@mozilla.com>2011-08-03 15:09:00 -0700
commit4ae6c835cb69332e982babcfca1a4e5657ec8bbd (patch)
tree3c0a0618f8ff22673529bb412bdf72194d1407f0 /src/rt
parente33de59e47c5076a89eadeb38f4934f58a3618a6 (diff)
downloadrust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.tar.gz
rust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.zip
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.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_run_program.cpp21
1 files changed, 18 insertions, 3 deletions
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;