Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: src/platform/crash/user_collector.cc

Issue 1702008: Add crash_reporter functionality (Closed)
Patch Set: add set -e Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/crash/user_collector.h ('k') | src/platform/crash/user_collector_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/crash/user_collector.cc
diff --git a/src/platform/crash/user_collector.cc b/src/platform/crash/user_collector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a83b5c94636b3a115d5e7b7972cd7ac88bc799de
--- /dev/null
+++ b/src/platform/crash/user_collector.cc
@@ -0,0 +1,75 @@
+// 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.
+
+#include <string>
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "crash/user_collector.h"
+#include "metrics_library.h"
+
+// This procfs file is used to cause kernel core file writing to
+// instead pipe the core file into a user space process. See
+// core(5) man page.
+static const char kCorePatternFile[] = "/proc/sys/kernel/core_pattern";
+
+UserCollector::UserCollector()
+ : core_pattern_file_(kCorePatternFile),
+ count_crash_function_(NULL),
+ initialized_(false),
+ is_feedback_allowed_function_(NULL),
+ logger_(NULL) {
+}
+
+void UserCollector::Initialize(
+ UserCollector::CountCrashFunction count_crash_function,
+ const std::string &our_path,
+ UserCollector::IsFeedbackAllowedFunction is_feedback_allowed_function,
+ SystemLogging *logger) {
+ CHECK(count_crash_function != NULL);
+ CHECK(is_feedback_allowed_function != NULL);
+ CHECK(logger != NULL);
+
+ count_crash_function_ = count_crash_function;
+ our_path_ = our_path;
+ is_feedback_allowed_function_ = is_feedback_allowed_function;
+ logger_ = logger;
+ initialized_ = true;
+}
+
+UserCollector::~UserCollector() {
+}
+
+std::string UserCollector::GetPattern(bool enabled) const {
+ if (enabled) {
+ return StringPrintf("|%s --signal=%%s --pid=%%p --exec=%%e",
+ our_path_.c_str());
+ } else {
+ return "core";
+ }
+}
+
+bool UserCollector::SetUpInternal(bool enabled) {
+ CHECK(initialized_);
+ logger_->LogInfo("%s crash handling", enabled ? "Enabling" : "Disabling");
+ std::string pattern = GetPattern(enabled);
+ if (file_util::WriteFile(FilePath(core_pattern_file_),
+ pattern.c_str(),
+ pattern.length()) != pattern.length()) {
+ logger_->LogError("Unable to write %s", core_pattern_file_.c_str());
+ return false;
+ }
+ return true;
+}
+
+void UserCollector::HandleCrash(int signal, int pid, const std::string &exec) {
+ CHECK(initialized_);
+ logger_->LogWarning("Received crash notification for %s[%d] sig %d",
+ exec.c_str(), pid, signal);
+
+ if (is_feedback_allowed_function_()) {
+ count_crash_function_();
+ }
+}
« no previous file with comments | « src/platform/crash/user_collector.h ('k') | src/platform/crash/user_collector_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698