summaryrefslogtreecommitdiffstats
path: root/chrome/app
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 22:59:48 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-11 22:59:48 +0000
commit659c19560c41ea3e4e283ebac8b1b6088a82143b (patch)
tree03fc953e87f64e44b65aa1eacb3b0e66f16949ed /chrome/app
parent2de7e004b9e0cede80a1955d99d01a1e484182d9 (diff)
downloadchromium_src-659c19560c41ea3e4e283ebac8b1b6088a82143b.zip
chromium_src-659c19560c41ea3e4e283ebac8b1b6088a82143b.tar.gz
chromium_src-659c19560c41ea3e4e283ebac8b1b6088a82143b.tar.bz2
Make writing to stdout and stderr work in Chrome processes when inherited
handles are available. Don't create a console, just attach to any existing console. R=cpu BUG=none TEST=none Review URL: http://codereview.chromium.org/3574008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app')
-rw-r--r--chrome/app/chrome_dll_main.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index c08e109..7100464e 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -13,8 +13,11 @@
#include <algorithm>
#include <atlbase.h>
#include <atlapp.h>
+#include <fcntl.h>
+#include <io.h>
#include <malloc.h>
#include <new.h>
+#include <process.h>
#elif defined(OS_POSIX)
#include <locale.h>
#include <signal.h>
@@ -319,6 +322,19 @@ void RegisterInvalidParamHandler() {
#endif
}
+#if defined(OS_WIN)
+void SetupStdHandle(DWORD name, int target_fd, FILE* target_fp) {
+ HANDLE handle = GetStdHandle(name);
+ if (handle && handle != INVALID_HANDLE_VALUE) {
+ int fd = _open_osfhandle(reinterpret_cast<intptr_t>(handle), _O_TEXT);
+ if (fd != -1) {
+ _dup2(fd, target_fd);
+ target_fp->_file = target_fd;
+ }
+ }
+}
+#endif
+
void SetupCRT(const CommandLine& parsed_command_line) {
#if defined(OS_WIN)
#ifdef _CRTDBG_MAP_ALLOC
@@ -341,6 +357,12 @@ void SetupCRT(const CommandLine& parsed_command_line) {
HeapSetInformation(crt_heap, HeapCompatibilityInformation,
&enable_lfh, sizeof(enable_lfh));
}
+
+ // Attach to an existing console if one exists, and connect up the CRT
+ // handles for stdout/stderr.
+ AttachConsole(ATTACH_PARENT_PROCESS);
+ SetupStdHandle(STD_OUTPUT_HANDLE, 1, stdout);
+ SetupStdHandle(STD_ERROR_HANDLE, 2, stderr);
#endif
}