Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: base/test/launcher/test_launcher.cc

Issue 2670213004: Only allow the desired child proc to inherit its output file. (Closed)
Patch Set: comment tweak Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/launcher/test_launcher.cc
diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc
index 2f22d32d50a4dba63b902aa4006e94a22db08071..1c945d3606d1bd6e76674ebced4660a35927d5fe 100644
--- a/base/test/launcher/test_launcher.cc
+++ b/base/test/launcher/test_launcher.cc
@@ -309,7 +309,26 @@ int LaunchChildTestProcessWithOptions(
// in the set.
AutoLock lock(g_live_processes_lock.Get());
+#if defined(OS_WIN)
+ // Allow the handle used to capture stdio and stdout to be inherited by the
+ // child. Note that this is done under g_live_processes_lock to ensure that
+ // only the desired child receives the handle.
+ if (new_options.stdout_handle) {
+ ::SetHandleInformation(new_options.stdout_handle, HANDLE_FLAG_INHERIT,
+ HANDLE_FLAG_INHERIT);
+ }
+#endif
+
process = LaunchProcess(command_line, new_options);
+
+#if defined(OS_WIN)
+ // Revoke inheritance so that the handle isn't leaked into other children.
+ // Note that this is done under g_live_processes_lock to ensure that only
+ // the desired child receives the handle.
+ if (new_options.stdout_handle)
+ ::SetHandleInformation(new_options.stdout_handle, HANDLE_FLAG_INHERIT, 0);
+#endif
+
if (!process.IsValid())
return -1;
@@ -382,19 +401,9 @@ void DoLaunchChildTestProcess(
win::ScopedHandle handle;
if (redirect_stdio) {
- // Make the file handle inheritable by the child.
- SECURITY_ATTRIBUTES sa_attr;
- sa_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa_attr.lpSecurityDescriptor = NULL;
- sa_attr.bInheritHandle = TRUE;
-
- handle.Set(CreateFile(output_file.value().c_str(),
- GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_DELETE,
- &sa_attr,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_TEMPORARY,
- NULL));
+ handle.Set(CreateFile(output_file.value().c_str(), GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr,
+ OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL));
CHECK(handle.IsValid());
options.inherit_handles = true;
options.stdin_handle = INVALID_HANDLE_VALUE;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698