From c3706668c67acdd8bcfb3df873991777d8bc1195 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 29 Aug 2017 13:08:32 -0700 Subject: libdebuggerd: cleanup. Move libdebuggerd headers into their own directory for namespacing, move some includes to the top of their implementing files, delete some dead code. Test: mma, treehugger Change-Id: Ie4c44e32e2ab3bc678092899d257fd4ed634aa34 --- debuggerd/libdebuggerd/tombstone.cpp | 69 ++++-------------------------------- 1 file changed, 7 insertions(+), 62 deletions(-) (limited to 'debuggerd/libdebuggerd/tombstone.cpp') diff --git a/debuggerd/libdebuggerd/tombstone.cpp b/debuggerd/libdebuggerd/tombstone.cpp index b809ed4bc..50d19bd1d 100644 --- a/debuggerd/libdebuggerd/tombstone.cpp +++ b/debuggerd/libdebuggerd/tombstone.cpp @@ -16,6 +16,8 @@ #define LOG_TAG "DEBUG" +#include "libdebuggerd/tombstone.h" + #include #include #include @@ -43,22 +45,18 @@ #include #include +// Needed to get DEBUGGER_SIGNAL. #include "debuggerd/handler.h" -#include "backtrace.h" -#include "elf_utils.h" -#include "machine.h" -#include "open_files_list.h" -#include "tombstone.h" +#include "libdebuggerd/backtrace.h" +#include "libdebuggerd/elf_utils.h" +#include "libdebuggerd/machine.h" +#include "libdebuggerd/open_files_list.h" using android::base::StringPrintf; #define STACK_WORDS 16 -#define MAX_TOMBSTONES 10 -#define TOMBSTONE_DIR "/data/tombstones" -#define TOMBSTONE_TEMPLATE (TOMBSTONE_DIR"/tombstone_%02d") - static bool signal_has_si_addr(int si_signo, int si_code) { // Manually sent signals won't have si_addr. if (si_code == SI_USER || si_code == SI_QUEUE || si_code == SI_TKILL) { @@ -764,59 +762,6 @@ static void dump_crash(log_t* log, BacktraceMap* map, BacktraceMap* map_new, } } -// open_tombstone - find an available tombstone slot, if any, of the -// form tombstone_XX where XX is 00 to MAX_TOMBSTONES-1, inclusive. If no -// file is available, we reuse the least-recently-modified file. -int open_tombstone(std::string* out_path) { - // In a single pass, find an available slot and, in case none - // exist, find and record the least-recently-modified file. - char path[128]; - int fd = -1; - int oldest = -1; - struct stat oldest_sb; - for (int i = 0; i < MAX_TOMBSTONES; i++) { - snprintf(path, sizeof(path), TOMBSTONE_TEMPLATE, i); - - struct stat sb; - if (stat(path, &sb) == 0) { - if (oldest < 0 || sb.st_mtime < oldest_sb.st_mtime) { - oldest = i; - oldest_sb.st_mtime = sb.st_mtime; - } - continue; - } - if (errno != ENOENT) continue; - - fd = open(path, O_CREAT | O_EXCL | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0600); - if (fd < 0) continue; // raced ? - - if (out_path) { - *out_path = path; - } - fchown(fd, AID_SYSTEM, AID_SYSTEM); - return fd; - } - - if (oldest < 0) { - ALOGE("debuggerd: failed to find a valid tombstone, default to using tombstone 0.\n"); - oldest = 0; - } - - // we didn't find an available file, so we clobber the oldest one - snprintf(path, sizeof(path), TOMBSTONE_TEMPLATE, oldest); - fd = open(path, O_CREAT | O_TRUNC | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0600); - if (fd < 0) { - ALOGE("debuggerd: failed to open tombstone file '%s': %s\n", path, strerror(errno)); - return -1; - } - - if (out_path) { - *out_path = path; - } - fchown(fd, AID_SYSTEM, AID_SYSTEM); - return fd; -} - void engrave_tombstone(int tombstone_fd, BacktraceMap* map, BacktraceMap* map_new, const OpenFilesList* open_files, pid_t pid, pid_t tid, const std::string& process_name, const std::map& threads, -- cgit v1.2.3