summaryrefslogtreecommitdiffstats
path: root/debuggerd
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-02-08 02:13:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-02-08 02:13:58 +0000
commit4207df11c5c09969b576324b4eea93a4c4e1ee99 (patch)
treedfeec02899e94ec874c77be2ba254b8816ae4fcf /debuggerd
parent829ae5befa16efbd2ca4e974d702c2eaac3eab02 (diff)
parent68bd59f6d2c63b752aa4f38bcd655c0d52d6597e (diff)
downloadcore-4207df11c5c09969b576324b4eea93a4c4e1ee99.tar.gz
core-4207df11c5c09969b576324b4eea93a4c4e1ee99.tar.bz2
core-4207df11c5c09969b576324b4eea93a4c4e1ee99.zip
Merge "Use stat structure to keep oldest mtime."
Diffstat (limited to 'debuggerd')
-rwxr-xr-xdebuggerd/tombstone.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp
index c6300200c..91d95fc21 100755
--- a/debuggerd/tombstone.cpp
+++ b/debuggerd/tombstone.cpp
@@ -55,11 +55,6 @@
// Must match the path defined in NativeCrashListener.java
#define NCRASH_SOCKET_PATH "/data/system/ndebugsocket"
-#define typecheck(x,y) { \
- typeof(x) __dummy1; \
- typeof(y) __dummy2; \
- (void)(&__dummy1 == &__dummy2); }
-
static bool signal_has_address(int sig) {
switch (sig) {
case SIGILL:
@@ -653,28 +648,19 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a
//
// Returns the path of the tombstone file, allocated using malloc(). Caller must free() it.
static char* find_and_open_tombstone(int* fd) {
-#ifdef __aarch64__
- long mtime = LONG_MAX;
-#else
- unsigned long mtime = ULONG_MAX;
-#endif
- struct stat sb;
-
- // XXX: Our stat.st_mtime isn't time_t. If it changes, as it probably ought
- // to, our logic breaks. This check will generate a warning if that happens.
- typecheck(mtime, sb.st_mtime);
-
- // In a single wolf-like pass, find an available slot and, in case none
+ // 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 oldest = 0;
+ 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)) {
- if (sb.st_mtime < mtime) {
+ if (oldest < 0 || sb.st_mtime < oldest_sb.st_mtime) {
oldest = i;
- mtime = sb.st_mtime;
+ oldest_sb.st_mtime = sb.st_mtime;
}
continue;
}
@@ -689,6 +675,11 @@ static char* find_and_open_tombstone(int* fd) {
return strdup(path);
}
+ if (oldest < 0) {
+ LOG("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, 0600);