summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorScott Graham <scottmg@chromium.org>2012-05-09 19:30:58 (GMT)
committerScott Graham <scottmg@chromium.org>2012-05-09 19:30:58 (GMT)
commitf4542046be2d7523518b382f0a2fda3be8e7a49f (patch)
tree19fc686abacda699e6a96bd8f0f2a95f6058b358 /src
parentff16370b605c3f668444484eaea2c10a0b62b72f (diff)
downloadNinja-f4542046be2d7523518b382f0a2fda3be8e7a49f.zip
Ninja-f4542046be2d7523518b382f0a2fda3be8e7a49f.tar.gz
Ninja-f4542046be2d7523518b382f0a2fda3be8e7a49f.tar.bz2
pass subprocesses handle to nul device rather than null handle
Diffstat (limited to 'src')
-rw-r--r--src/subprocess-win32.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc
index 7842114..3484e5f 100644
--- a/src/subprocess-win32.cc
+++ b/src/subprocess-win32.cc
@@ -1,4 +1,4 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
+// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -80,15 +80,24 @@ HANDLE Subprocess::SetupPipe(HANDLE ioport) {
bool Subprocess::Start(SubprocessSet* set, const string& command) {
HANDLE child_pipe = SetupPipe(set->ioport_);
+ SECURITY_ATTRIBUTES security_attributes;
+ memset(&security_attributes, 0, sizeof(SECURITY_ATTRIBUTES));
+ security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
+ security_attributes.bInheritHandle = TRUE;
+ // Must be inheritable so subprocesses can dup to children.
+ HANDLE nul = CreateFile("NUL", GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ &security_attributes, OPEN_EXISTING, 0, NULL);
+ if (nul == INVALID_HANDLE_VALUE)
+ Fatal("couldn't open nul");
+
STARTUPINFOA startup_info;
memset(&startup_info, 0, sizeof(startup_info));
startup_info.cb = sizeof(STARTUPINFO);
startup_info.dwFlags = STARTF_USESTDHANDLES;
+ startup_info.hStdInput = nul;
startup_info.hStdOutput = child_pipe;
- // TODO: what does this hook up stdin to?
- startup_info.hStdInput = NULL;
- // TODO: is it ok to reuse pipe like this?
- startup_info.hStdError = child_pipe;
+ startup_info.hStdError = child_pipe;
PROCESS_INFORMATION process_info;
memset(&process_info, 0, sizeof(process_info));
@@ -104,6 +113,7 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
if (child_pipe)
CloseHandle(child_pipe);
CloseHandle(pipe_);
+ CloseHandle(nul);
pipe_ = NULL;
// child_ is already NULL;
buf_ = "CreateProcess failed: The system cannot find the file specified.\n";
@@ -116,6 +126,7 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
// Close pipe channel only used by the child.
if (child_pipe)
CloseHandle(child_pipe);
+ CloseHandle(nul);
CloseHandle(process_info.hThread);
child_ = process_info.hProcess;