diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 21:43:21 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 21:43:21 +0000 |
commit | 1a766443445dada8604d47fab980ef3793fc4a73 (patch) | |
tree | 60a29f42f8dd7aa8a7de6dc4cb833609899e2218 /base | |
parent | b63328cdfdb01a53aaa210985ce42ea8821923e4 (diff) | |
download | chromium_src-1a766443445dada8604d47fab980ef3793fc4a73.zip chromium_src-1a766443445dada8604d47fab980ef3793fc4a73.tar.gz chromium_src-1a766443445dada8604d47fab980ef3793fc4a73.tar.bz2 |
Cherrypick of r34036 to make merge at r34474 build.
Merging only changes to base/logging.* (for RAW_LOG()/RAW_CHECK()), and NOT changes to chrome/browser/browser_main.cc.
Original CL description:
Make POSIX SIGTERM/SIGINT/SIGHUP handler async signal safe.
* Don't use LOG/CHECK. Replace with RAW_LOG/DCHECK (newly added to logging.h)
* Don't directly post a task to the UI loop. Write to a magic pipe. Read this from a separate thread which will post to a task to the UI loop.
BUG=http://crbug.com/29240
Review URL: http://codereview.chromium.org/460094
TBR=viettrungluu@chromium.org,mark@chromium.org,willchan@chromium.org
Review URL: http://codereview.chromium.org/501004
git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@34499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/logging.cc | 37 | ||||
-rw-r--r-- | base/logging.h | 11 |
2 files changed, 48 insertions, 0 deletions
diff --git a/base/logging.cc b/base/logging.cc index b59e3fb..b169a22 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -5,9 +5,14 @@ #include "base/logging.h" #if defined(OS_WIN) +#include <io.h> #include <windows.h> typedef HANDLE FileHandle; typedef HANDLE MutexHandle; +// Windows warns on using write(). It prefers _write(). +#define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) +// Windows doesn't define STDERR_FILENO. Define it here. +#define STDERR_FILENO 2 #elif defined(OS_MACOSX) #include <CoreFoundation/CoreFoundation.h> #include <mach/mach.h> @@ -37,6 +42,7 @@ typedef pthread_mutex_t* MutexHandle; #include "base/base_switches.h" #include "base/command_line.h" #include "base/debug_util.h" +#include "base/eintr_wrapper.h" #include "base/lock_impl.h" #if defined(OS_POSIX) #include "base/safe_strerror_posix.h" @@ -667,6 +673,37 @@ void CloseLogFile() { log_file = NULL; } +void RawLog(int level, const char* message) { + if (level >= min_log_level) { + size_t bytes_written = 0; + const size_t message_len = strlen(message); + int rv; + while (bytes_written < message_len) { + rv = HANDLE_EINTR( + write(STDERR_FILENO, message + bytes_written, + message_len - bytes_written)); + if (rv < 0) { + // Give up, nothing we can do now. + break; + } + bytes_written += rv; + } + + if (message_len > 0 && message[message_len - 1] != '\n') { + do { + rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1)); + if (rv < 0) { + // Give up, nothing we can do now. + break; + } + } while (rv != 1); + } + } + + if (level == LOG_FATAL) + DebugUtil::BreakDebugger(); +} + } // namespace logging std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { diff --git a/base/logging.h b/base/logging.h index de8de71..b4878ea 100644 --- a/base/logging.h +++ b/base/logging.h @@ -765,6 +765,17 @@ class ErrnoLogMessage { // after this call. void CloseLogFile(); +// Async signal safe logging mechanism. +void RawLog(int level, const char* message); + +#define RAW_LOG(level, message) logging::RawLog(logging::LOG_ ## level, message) + +#define RAW_CHECK(condition) \ + do { \ + if (!(condition)) \ + logging::RawLog(logging::LOG_FATAL, "Check failed: " #condition "\n"); \ + } while (0) + } // namespace logging // These functions are provided as a convenience for logging, which is where we |