Index: src/platform/crash/crash_dumper.cc |
diff --git a/src/platform/crash/crash_dumper.cc b/src/platform/crash/crash_dumper.cc |
index 94a82636d4f527bd67bac85e804c5b1f3be5c490..0e0d2c7abec59bf0352a94696887b62b389314a4 100644 |
--- a/src/platform/crash/crash_dumper.cc |
+++ b/src/platform/crash/crash_dumper.cc |
@@ -1,16 +1,18 @@ |
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+// |
+// Simple wrapper and basic configuration of Google breakpad. We try |
+// to avoid using any unnecessary code (like libbase) to make it as |
+// non-intrusive as possible to link in this library. |
#include <errno.h> |
#include <pwd.h> |
+#include <stddef.h> |
#include <sys/stat.h> |
#include <sys/types.h> |
#include <unistd.h> |
-#include "base/file_path.h" |
-#include "base/file_util.h" |
-#include "base/logging.h" |
#include "client/linux/handler/exception_handler.h" |
#include "common/linux/linux_libc_support.h" |
#include "common/linux/linux_syscall_support.h" |
@@ -31,10 +33,17 @@ static const char *s_crash_parent_path; |
static mode_t s_dump_directory_mode; |
static bool s_any_crashes_occurred = false; |
-static scoped_ptr<google_breakpad::ExceptionHandler> s_breakpad_handler; |
+static google_breakpad::ExceptionHandler *s_breakpad_handler; |
static bool s_enabled = false; |
+#define CHECK_CONDITION(_cond, _message) \ |
+ do { if (!(_cond)) { fputs(_message, stderr); abort(); } } while(false) |
+ |
+// This static object will cause anything that links in this object to get |
+// crash handling for the duration of this file's scope. |
+static CrashDumper g_crash_dumper; |
+ |
// Prepare the crash path. Must avoid allocating memory. |
static bool PrepareCrashPath() { |
@@ -78,12 +87,11 @@ static bool GetEffectiveUser(std::string *result) { |
} |
void CrashDumper::Enable() { |
- CHECK(!s_enabled) << "Crash handling already enabled"; |
+ CHECK_CONDITION(!s_enabled, "Crash handling already enabled"); |
std::string name; |
- CHECK(GetEffectiveUser(&name)) |
- << "getpwuid_r failed - " << errno |
- << " - crash reporting cannot be enabled"; |
+ CHECK_CONDITION(GetEffectiveUser(&name), |
+ "getpwuid_r failed, cannot enable crash reporting"); |
if (name == kDefaultUser) { |
// Crashes as "chronos" when the user is not yet logged in will |
@@ -101,15 +109,15 @@ void CrashDumper::Enable() { |
s_dump_directory_mode = 01777; |
} |
- CHECK(PrepareCrashPath()) << "Unable to create path " << s_crash_path; |
+ CHECK_CONDITION(PrepareCrashPath(), "Unable to create crash path"); |
// Begin collecting crashes |
- s_breakpad_handler.reset(new google_breakpad::ExceptionHandler( |
+ s_breakpad_handler = new google_breakpad::ExceptionHandler( |
s_crash_path, |
FilterCallback, |
NULL, // No minidump callback - sending happens asynchronously to writing |
NULL, // No callback context necessary |
- true)); // Install handler now. |
+ true); // Install handler now. |
s_enabled = true; |
} |
@@ -119,8 +127,9 @@ bool CrashDumper::IsEnabled() { |
} |
void CrashDumper::Disable() { |
- CHECK(s_enabled) << "Crash handling was not enabled"; |
- s_breakpad_handler.reset(NULL); |
+ CHECK_CONDITION(s_enabled, "Crash handling was not enabled"); |
+ delete s_breakpad_handler; |
+ s_breakpad_handler = NULL; |
s_crash_path = NULL; |
s_crash_parent_path = NULL; |
s_enabled = false; |