summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--base/process_util_win.cc4
-rw-r--r--chrome/app/chrome_dll_main.cc22
-rw-r--r--sandbox/src/target_process.cc5
3 files changed, 30 insertions, 1 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index c5d7790..8738b9a 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -196,8 +196,10 @@ bool LaunchAppImpl(const std::wstring& cmdline,
ProcessHandle* process_handle) {
STARTUPINFO startup_info = {0};
startup_info.cb = sizeof(startup_info);
- startup_info.dwFlags = STARTF_USESHOWWINDOW;
+ startup_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW;
+ startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+ startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
PROCESS_INFORMATION process_info;
if (!CreateProcess(NULL,
const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
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
}
diff --git a/sandbox/src/target_process.cc b/sandbox/src/target_process.cc
index a9848c5..f0a40bd 100644
--- a/sandbox/src/target_process.cc
+++ b/sandbox/src/target_process.cc
@@ -136,6 +136,11 @@ DWORD TargetProcess::Create(const wchar_t* exe_path,
startup_info.lpDesktop = desktop_name.get();
}
+ // Hook up stdout/stderr.
+ startup_info.dwFlags = STARTF_USESTDHANDLES;
+ startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+ startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+
PROCESS_INFORMATION process_info = {0};
if (!::CreateProcessAsUserW(lockdown_token_,