summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormseaborn@chromium.org <mseaborn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 12:24:24 +0000
committermseaborn@chromium.org <mseaborn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 12:24:24 +0000
commit6b28ab9e9a4e3564cffeb88f4d22eda7e7dc425b (patch)
tree23369257f4d5335c8b325f1539052280d7b15ee7
parente995e79979c0bbea4f2d5e4e89bc5db66b95660f (diff)
downloadchromium_src-6b28ab9e9a4e3564cffeb88f4d22eda7e7dc425b.zip
chromium_src-6b28ab9e9a4e3564cffeb88f4d22eda7e7dc425b.tar.gz
chromium_src-6b28ab9e9a4e3564cffeb88f4d22eda7e7dc425b.tar.bz2
Make RouteStdioToConsole() redirect FDs 1 and 2 as well as FILE* pointers
After this change, --enable-logging allows NaCl untrusted code to output to stdout/stderr when Chrome is running under the Windows console, which makes debugging easier. The change is needed because NaCl uses _write() on file descriptors 1 and 2 in this case rather than fwrite() on FILE* stdout and stderr. stdout/stderr already worked for NaCl untrusted code on Linux and Mac. BUG=171836 TEST=manually run hello_world.nexe under Chrome on a Windows console Review URL: https://chromiumcodereview.appspot.com/12095018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179613 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/process_util_win.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 4355b15..2a47f13 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -160,10 +160,19 @@ void RouteStdioToConsole() {
// log-lines in output.
enum { kOutputBufferSize = 64 * 1024 };
- if (freopen("CONOUT$", "w", stdout))
+ if (freopen("CONOUT$", "w", stdout)) {
setvbuf(stdout, NULL, _IOLBF, kOutputBufferSize);
- if (freopen("CONOUT$", "w", stderr))
+ // Overwrite FD 1 for the benefit of any code that uses this FD
+ // directly. This is safe because the CRT allocates FDs 0, 1 and
+ // 2 at startup even if they don't have valid underlying Windows
+ // handles. This means we won't be overwriting an FD created by
+ // _open() after startup.
+ _dup2(_fileno(stdout), 1);
+ }
+ if (freopen("CONOUT$", "w", stderr)) {
setvbuf(stderr, NULL, _IOLBF, kOutputBufferSize);
+ _dup2(_fileno(stderr), 2);
+ }
// Fix all cout, wcout, cin, wcin, cerr, wcerr, clog and wclog.
std::ios::sync_with_stdio();