diff options
author | Christopher Ferris <cferris@google.com> | 2014-02-10 12:51:27 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-02-10 12:51:27 +0000 |
commit | 8a54dea42ade5f5c6d1bba6ec590368dab48f308 (patch) | |
tree | 688f9b82e7dae09b7401089270b48c2ebcfc996a /debuggerd | |
parent | 4160507b759bc119c5a7393b4c2c090654c04f47 (diff) | |
parent | 25a619fb30ac04ee534a749ff238900845b64bb6 (diff) | |
download | system_core-8a54dea42ade5f5c6d1bba6ec590368dab48f308.zip system_core-8a54dea42ade5f5c6d1bba6ec590368dab48f308.tar.gz system_core-8a54dea42ade5f5c6d1bba6ec590368dab48f308.tar.bz2 |
am 25a619fb: am 48e81834: am 4207df11: Merge "Use stat structure to keep oldest mtime."
* commit '25a619fb30ac04ee534a749ff238900845b64bb6':
Use stat structure to keep oldest mtime.
Diffstat (limited to 'debuggerd')
-rwxr-xr-x | debuggerd/tombstone.cpp | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index 5e3d729..58e7e5d 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: @@ -647,28 +642,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; } @@ -683,6 +669,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); |