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

Unified Diff: base/process_util_win.cc

Issue 12038059: Windows: Fix --enable-logging to not disable logging when stderr is a pipe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/process_util_win.cc
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 3ac2ca4de7ba88ef635a755303d56f10392f1344..6cbc887fb5277d9d773fdc6426474d70fa0b49a5 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -122,6 +122,24 @@ void TimerExpiredTask::KillProcess() {
} // namespace
void RouteStdioToConsole() {
+ // Don't change anything if stdout or stderr already point to a
+ // valid stream.
+ //
+ // If we are running under Buildbot or under Cygwin's default
+ // terminal (mintty), stderr and stderr will be pipe handles. In
+ // that case, we don't want to open CONOUT$, because its output
+ // likely does not go anywhere.
+ //
+ // We don't use GetStdHandle() to check stdout/stderr here because
+ // it can return dangling IDs of handles that were never inherited
+ // by this process. These IDs could have been reused by the time
+ // this function is called. The CRT checks the validity of
+ // stdout/stderr on startup (before the handle IDs can be reused).
+ // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was
+ // invalid.
+ if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0)
+ return;
+
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
unsigned int result = GetLastError();
// Was probably already attached.
« 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