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/lib/win32_os.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index 65ee769fb5c..c502ebbfcb7 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -38,6 +38,7 @@ mod libc_constants { fn O_TRUNC() -> int { ret 512; } fn O_TEXT() -> int { ret 16384; } fn O_BINARY() -> int { ret 32768; } + fn O_NOINHERIT() -> int { ret 0x0080; } fn S_IRUSR() -> uint { ret 256u; // really _S_IREAD in win32 @@ -60,9 +61,18 @@ fn target_os() -> str { ret "win32"; } fn dylib_filename(base: str) -> str { ret base + ".dll"; } fn pipe() -> {in: int, out: int} { + // Windows pipes work subtly differently than unix pipes, and their + // inheritance has to be handled in a different way that I don't fully + // understand. Here we explicitly make the pipe non-inheritable, + // which means to pass it to a subprocess they need to be duplicated + // first, as in rust_run_program. let fds = {mutable in: 0, mutable out: 0}; - assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u, - libc_constants::O_BINARY()) == 0); + let res = os::libc::_pipe(ptr::addr_of(fds.in), 1024u, + libc_constants::O_BINARY() + | libc_constants::O_NOINHERIT()); + assert res == 0; + assert fds.in != -1 && fds.in != 0; + assert fds.out != -1 && fds.in != 0; ret {in: fds.in, out: fds.out}; } -- cgit 1.4.1-3-g733a5