diff --git a/crash_reporter/crash_reporter.cc b/crash_reporter/crash_reporter.cc index 72eeeda99..7872f7b1d 100644 --- a/crash_reporter/crash_reporter.cc +++ b/crash_reporter/crash_reporter.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ static const char kUserCrashSignal[] = static const char kKernelCrashDetected[] = "/var/run/kernel-crash-detected"; static const char kUncleanShutdownDetected[] = "/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. enum CrashKinds { @@ -122,6 +124,21 @@ static int Initialize(KernelCollector *kernel_collector, const bool clean_shutdown) { 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_unclean_shutdown = false; kernel_collector->Enable(); diff --git a/crash_reporter/crash_sender b/crash_reporter/crash_sender index d0d677204..29a12297f 100755 --- a/crash_reporter/crash_sender +++ b/crash_reporter/crash_sender @@ -22,9 +22,8 @@ BRILLO_PRODUCT=Brillo # Base directory that contains any crash reporter state files. CRASH_STATE_DIR="/data/misc/crash_reporter" -# File whose existence implies crash reports may be sent, and whose -# contents includes our machine's anonymized guid. -CONSENT_ID="/data/misc/metrics/enabled" +# File containing crash_reporter's anonymized guid. +GUID_FILE="${CRASH_STATE_DIR}/guid" # Crash sender lock in case the sender is already running. 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 # 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")" [ "${error_type}" = "undefined" ] && error_type=