diff --git a/ipc/chromium/src/base/debug_util.cc b/ipc/chromium/src/base/debug_util.cc index 2db3aa782cd..410b7b42263 100644 --- a/ipc/chromium/src/base/debug_util.cc +++ b/ipc/chromium/src/base/debug_util.cc @@ -6,6 +6,16 @@ #include "base/platform_thread.h" +#include + +#ifdef OS_WIN +#include +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + bool DebugUtil::WaitForDebugger(int wait_seconds, bool silent) { for (int i = 0; i < wait_seconds * 10; ++i) { if (BeingDebugged()) { @@ -24,3 +34,39 @@ const void *const *StackTrace::Addresses(size_t* count) { return &trace_[0]; return NULL; } + +namespace mozilla { + +EnvironmentLog::EnvironmentLog(const char* varname) + : fd_(NULL) +{ + const char *e = getenv(varname); + if (e && *e) { + if (!strcmp(e, "-")) { + fd_ = fdopen(dup(STDOUT_FILENO), "a"); + } + else { + fd_ = fopen(e, "a"); + } + } +} + +EnvironmentLog::~EnvironmentLog() +{ + if (fd_) + fclose(fd_); +} + +void +EnvironmentLog::print(const char* format, ...) +{ + va_list a; + va_start(a, format); + if (fd_) { + vfprintf(fd_, format, a); + fflush(fd_); + } + va_end(a); +} + +} // namespace mozilla diff --git a/ipc/chromium/src/base/debug_util.h b/ipc/chromium/src/base/debug_util.h index 3ca199cb186..d2e18654274 100644 --- a/ipc/chromium/src/base/debug_util.h +++ b/ipc/chromium/src/base/debug_util.h @@ -67,4 +67,22 @@ class DebugUtil { #endif // defined(OS_MACOSX) }; +namespace mozilla { + +class EnvironmentLog +{ +public: + EnvironmentLog(const char* varname); + ~EnvironmentLog(); + + void print(const char* format, ...); + +private: + FILE* fd_; + + DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog); +}; + +} // namespace mozilla + #endif // BASE_DEBUG_UTIL_H_ diff --git a/ipc/chromium/src/base/process_util_linux.cc b/ipc/chromium/src/base/process_util_linux.cc index bc1aa0c37ac..3a567af1279 100644 --- a/ipc/chromium/src/base/process_util_linux.cc +++ b/ipc/chromium/src/base/process_util_linux.cc @@ -12,6 +12,7 @@ #include #include +#include "base/debug_util.h" #include "base/eintr_wrapper.h" #include "base/file_util.h" #include "base/logging.h" @@ -25,6 +26,8 @@ enum ParsingState { KEY_VALUE }; +static mozilla::EnvironmentLog gProcessLog("MOZ_PROCESS_LOG"); + } // namespace namespace base { @@ -55,17 +58,12 @@ bool LaunchApp(const std::vector& argv, execvp(argv_cstr[0], argv_cstr.get()); #if defined(CHROMIUM_MOZILLA_BUILD) // if we get here, we're in serious trouble and should complain loudly - fprintf(stderr, -"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" -"----> FAILED TO exec() CHILD PROCESS <---\n" -"----> path: %s\n" -"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - argv_cstr[0]); + DLOG(ERROR) << "FAILED TO exec() CHILD PROCESS, path: " << argv_cstr[0]; #endif exit(127); } else { - printf("==> process %d launched child process %d\n", - GetCurrentProcId(), pid); + gProcessLog.print("==> process %d launched child process %d\n", + GetCurrentProcId(), pid); if (wait) HANDLE_EINTR(waitpid(pid, 0, 0)); diff --git a/ipc/chromium/src/base/process_util_win.cc b/ipc/chromium/src/base/process_util_win.cc index 4585a036ff5..030fbc9fe6b 100644 --- a/ipc/chromium/src/base/process_util_win.cc +++ b/ipc/chromium/src/base/process_util_win.cc @@ -8,6 +8,7 @@ #include #include +#include "base/debug_util.h" #include "base/histogram.h" #include "base/logging.h" #include "base/scoped_handle_win.h" @@ -21,6 +22,8 @@ const int PAGESIZE_KB = 4; // HeapSetInformation function pointer. typedef BOOL (WINAPI* HeapSetFn)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T); +static mozilla::EnvironmentLog gProcessLog("MOZ_PROCESS_LOG"); + } // namespace namespace base { @@ -162,9 +165,9 @@ bool LaunchApp(const std::wstring& cmdline, &startup_info, &process_info)) return false; - printf("==> process %d launched child process %d\n", - GetCurrentProcId(), - process_info.dwProcessId); + gProcessLog.print("==> process %d launched child process %d\n", + GetCurrentProcId(), + process_info.dwProcessId); // Handles must be closed or they will leak CloseHandle(process_info.hThread);