aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util_windows.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/cpp/blaze_util_windows.cc')
-rw-r--r--src/main/cpp/blaze_util_windows.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index ff8ec2f85b..e18e3db300 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -57,6 +57,7 @@ static_assert(sizeof(wchar_t) == sizeof(WCHAR),
// Add 4 characters for potential UNC prefix and a couple more for safety.
static const size_t kWindowsPathBufferSize = 0x8010;
+using bazel::windows::AutoAttributeList;
using bazel::windows::AutoHandle;
using bazel::windows::CreateJunction;
@@ -551,13 +552,27 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
}
AutoHandle stderr_file(stderr_handle);
+ // Create an attribute list with length of 1
+ AutoAttributeList lpAttributeList(1);
+
+ HANDLE handlesToInherit[2] = {stdout_file, stderr_handle};
+ if (!UpdateProcThreadAttribute(
+ lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
+ handlesToInherit, 2 * sizeof(HANDLE), NULL, NULL)) {
+ pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
+ "ExecuteDaemon(%s): UpdateProcThreadAttribute", exe.c_str());
+ }
+
PROCESS_INFORMATION processInfo = {0};
- STARTUPINFOA startupInfo = {0};
+ STARTUPINFOEXA startupInfoEx = {0};
+
+ startupInfoEx.StartupInfo.cb = sizeof(startupInfoEx);
+ startupInfoEx.StartupInfo.hStdInput = devnull;
+ startupInfoEx.StartupInfo.hStdOutput = stdout_file;
+ startupInfoEx.StartupInfo.hStdError = stderr_handle;
+ startupInfoEx.StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
+ startupInfoEx.lpAttributeList = lpAttributeList;
- startupInfo.hStdInput = devnull;
- startupInfo.hStdError = stdout_file;
- startupInfo.hStdOutput = stderr_handle;
- startupInfo.dwFlags |= STARTF_USESTDHANDLES;
CmdLine cmdline;
CreateCommandLine(&cmdline, exe, args_vector);
@@ -567,10 +582,11 @@ int ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
/* lpProcessAttributes */ NULL,
/* lpThreadAttributes */ NULL,
/* bInheritHandles */ TRUE,
- /* dwCreationFlags */ DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP,
+ /* dwCreationFlags */ DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP |
+ EXTENDED_STARTUPINFO_PRESENT,
/* lpEnvironment */ NULL,
/* lpCurrentDirectory */ NULL,
- /* lpStartupInfo */ &startupInfo,
+ /* lpStartupInfo */ &startupInfoEx.StartupInfo,
/* lpProcessInformation */ &processInfo);
if (!ok) {