diff options
Diffstat (limited to 'recovery-persist.cpp')
-rw-r--r-- | recovery-persist.cpp | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/recovery-persist.cpp b/recovery-persist.cpp index b0ec141cb..d706ccac8 100644 --- a/recovery-persist.cpp +++ b/recovery-persist.cpp @@ -30,7 +30,6 @@ // --force-persist ignore /cache mount, always rotate in the contents. // -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -40,17 +39,16 @@ #include <android-base/file.h> #include <android-base/logging.h> - #include <private/android_logger.h> /* private pmsg functions */ +#include "rotate_logs.h" + static const char *LAST_LOG_FILE = "/data/misc/recovery/last_log"; static const char *LAST_PMSG_FILE = "/sys/fs/pstore/pmsg-ramoops-0"; static const char *LAST_KMSG_FILE = "/data/misc/recovery/last_kmsg"; static const char *LAST_CONSOLE_FILE = "/sys/fs/pstore/console-ramoops-0"; static const char *ALT_LAST_CONSOLE_FILE = "/sys/fs/pstore/console-ramoops"; -static const int KEEP_LOG_COUNT = 10; - // close a file, log an error if the error indicator is set static void check_and_fclose(FILE *fp, const char *name) { fflush(fp); @@ -80,39 +78,6 @@ static void copy_file(const char* source, const char* destination) { static bool rotated = false; -// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max. -// Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max. -// Overwrite any existing last_log.$max and last_kmsg.$max. -static void rotate_logs(int max) { - // Logs should only be rotated once. - - if (rotated) { - return; - } - rotated = true; - - for (int i = max-1; i >= 0; --i) { - std::string old_log(LAST_LOG_FILE); - if (i > 0) { - old_log += "." + std::to_string(i); - } - std::string new_log(LAST_LOG_FILE); - new_log += "." + std::to_string(i+1); - - // Ignore errors if old_log doesn't exist. - rename(old_log.c_str(), new_log.c_str()); - - std::string old_kmsg(LAST_KMSG_FILE); - if (i > 0) { - old_kmsg += "." + std::to_string(i); - } - std::string new_kmsg(LAST_KMSG_FILE); - new_kmsg += "." + std::to_string(i+1); - - rename(old_kmsg.c_str(), new_kmsg.c_str()); - } -} - ssize_t logsave( log_id_t /* logId */, char /* prio */, @@ -138,7 +103,8 @@ ssize_t logsave( // already-rotated files? Algorithm thus far is KISS: one file, // one rotation allowed. - rotate_logs(KEEP_LOG_COUNT); + rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE); + rotated = true; return android::base::WriteStringToFile(buffer, destination.c_str()); } |