Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12e61caa authored by Steve Fung's avatar Steve Fung
Browse files

crash_reporter: Generate and use own guid

Rather than share the guid with metrics, crash_reporter should
use its own guid that is persistent across reboots but not
across factory resets.

Bug: 24102242
Change-Id: I1bcc1a10aa8e1c09372386fe8e1661a8894b8d70
parent f5974755
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <vector>
#include <vector>


#include <base/files/file_util.h>
#include <base/files/file_util.h>
#include <base/guid.h>
#include <base/logging.h>
#include <base/logging.h>
#include <base/strings/string_split.h>
#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include <base/strings/string_util.h>
@@ -41,6 +42,7 @@ static const char kUserCrashSignal[] =
static const char kKernelCrashDetected[] = "/var/run/kernel-crash-detected";
static const char kKernelCrashDetected[] = "/var/run/kernel-crash-detected";
static const char kUncleanShutdownDetected[] =
static const char kUncleanShutdownDetected[] =
    "/var/run/unclean-shutdown-detected";
    "/var/run/unclean-shutdown-detected";
static const char kGUIDFileName[] = "/data/misc/crash_reporter/guid";


// Enumeration of kinds of crashes to be used in the CrashCounter histogram.
// Enumeration of kinds of crashes to be used in the CrashCounter histogram.
enum CrashKinds {
enum CrashKinds {
@@ -122,6 +124,21 @@ static int Initialize(KernelCollector *kernel_collector,
                      const bool clean_shutdown) {
                      const bool clean_shutdown) {
  CHECK(!clean_shutdown) << "Incompatible options";
  CHECK(!clean_shutdown) << "Incompatible options";


  // Try to read the GUID from kGUIDFileName.  If the file doesn't exist, is
  // blank, or the read fails, generate a new GUID and write it to the file.
  std::string guid;
  base::FilePath filepath(kGUIDFileName);
  if (!base::ReadFileToString(filepath, &guid) || guid.empty()) {
    guid = base::GenerateGUID();
    // If we can't read or write the file, log an error.  However it is not
    // a fatal error, as the crash server will assign a random GUID based
    // on a hash of the IP address if one is not provided in the report.
    if (base::WriteFile(filepath, guid.c_str(), guid.size()) <= 0) {
      LOG(ERROR) << "Could not write guid " << guid << " to file "
                 << filepath.value();
    }
  }

  bool was_kernel_crash = false;
  bool was_kernel_crash = false;
  bool was_unclean_shutdown = false;
  bool was_unclean_shutdown = false;
  kernel_collector->Enable();
  kernel_collector->Enable();
+3 −4
Original line number Original line Diff line number Diff line
@@ -22,9 +22,8 @@ BRILLO_PRODUCT=Brillo
# Base directory that contains any crash reporter state files.
# Base directory that contains any crash reporter state files.
CRASH_STATE_DIR="/data/misc/crash_reporter"
CRASH_STATE_DIR="/data/misc/crash_reporter"


# File whose existence implies crash reports may be sent, and whose
# File containing crash_reporter's anonymized guid.
# contents includes our machine's anonymized guid.
GUID_FILE="${CRASH_STATE_DIR}/guid"
CONSENT_ID="/data/misc/metrics/enabled"


# Crash sender lock in case the sender is already running.
# Crash sender lock in case the sender is already running.
CRASH_SENDER_LOCK="${CRASH_STATE_DIR}/lock/crash_sender"
CRASH_SENDER_LOCK="${CRASH_STATE_DIR}/lock/crash_sender"
@@ -393,7 +392,7 @@ send_crash() {


  # Need to strip dashes ourselves as Chrome preserves it in the file
  # Need to strip dashes ourselves as Chrome preserves it in the file
  # nowadays.  This is also what the Chrome breakpad client does.
  # nowadays.  This is also what the Chrome breakpad client does.
  guid=$(tr -d '-' < "${CONSENT_ID}")
  guid=$(tr -d '-' < "${GUID_FILE}")


  local error_type="$(get_key_value "${meta_path}" "error_type")"
  local error_type="$(get_key_value "${meta_path}" "error_type")"
  [ "${error_type}" = "undefined" ] && error_type=
  [ "${error_type}" = "undefined" ] && error_type=