From 3272000382e0013a2e3f7ec86d4b45ec15a2c363 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 2 Jun 2017 13:02:10 -0700 Subject: [PATCH] tombstoned: log where we're writing the tombstone. Make it easy to find out where a specific crash's tombstone was written to by adding a log. Bug: http://b/62268830 Test: crasher Merged-In: I1961dfb19f76a42a8448ebafd4be153b73cb6800 Change-Id: I1961dfb19f76a42a8448ebafd4be153b73cb6800 (cherry picked from commit cb68a0317d1d3f8a32a5fc87e93c1e7fc98a7d24) --- debuggerd/tombstoned/tombstoned.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/debuggerd/tombstoned/tombstoned.cpp b/debuggerd/tombstoned/tombstoned.cpp index 2248a217b..0e5dcef94 100644 --- a/debuggerd/tombstoned/tombstoned.cpp +++ b/debuggerd/tombstoned/tombstoned.cpp @@ -61,6 +61,7 @@ struct Crash { unique_fd crash_fd; pid_t crash_pid; event* crash_event = nullptr; + std::string crash_path; }; static constexpr char kTombstoneDirectory[] = "/data/tombstones/"; @@ -104,32 +105,31 @@ static void find_oldest_tombstone() { next_tombstone = oldest_tombstone; } -static unique_fd get_tombstone_fd() { +static std::pair get_tombstone() { // If kMaxConcurrentDumps is greater than 1, then theoretically the same // filename could be handed out to multiple processes. Unlink and create the // file, instead of using O_TRUNC, to avoid two processes interleaving their // output. unique_fd result; - char buf[PATH_MAX]; - snprintf(buf, sizeof(buf), "tombstone_%02d", next_tombstone); - if (unlinkat(tombstone_directory_fd, buf, 0) != 0 && errno != ENOENT) { - PLOG(FATAL) << "failed to unlink tombstone at " << kTombstoneDirectory << buf; + std::string file_name = StringPrintf("tombstone_%02d", next_tombstone); + if (unlinkat(tombstone_directory_fd, file_name.c_str(), 0) != 0 && errno != ENOENT) { + PLOG(FATAL) << "failed to unlink tombstone at " << kTombstoneDirectory << "/" << file_name; } - result.reset( - openat(tombstone_directory_fd, buf, O_CREAT | O_EXCL | O_WRONLY | O_APPEND | O_CLOEXEC, 0640)); + result.reset(openat(tombstone_directory_fd, file_name.c_str(), + O_CREAT | O_EXCL | O_WRONLY | O_APPEND | O_CLOEXEC, 0640)); if (result == -1) { - PLOG(FATAL) << "failed to create tombstone at " << kTombstoneDirectory << buf; + PLOG(FATAL) << "failed to create tombstone at " << kTombstoneDirectory << "/" << file_name; } next_tombstone = (next_tombstone + 1) % kTombstoneCount; - return result; + return {std::move(result), std::string(kTombstoneDirectory) + "/" + file_name}; } static void perform_request(Crash* crash) { unique_fd output_fd; if (!intercept_manager->GetIntercept(crash->crash_pid, &output_fd)) { - output_fd = get_tombstone_fd(); + std::tie(output_fd, crash->crash_path) = get_tombstone(); } TombstonedCrashPacket response = { @@ -251,6 +251,10 @@ static void crash_completed_cb(evutil_socket_t sockfd, short ev, void* arg) { goto fail; } + if (!crash->crash_path.empty()) { + LOG(ERROR) << "Tombstone written to: " << crash->crash_path; + } + fail: delete crash;