Merge "Rotate logs only when there are actual operations"
This commit is contained in:
@@ -74,6 +74,8 @@ maybe_restart_adbd() {
|
|||||||
|
|
||||||
int
|
int
|
||||||
apply_from_adb(RecoveryUI* ui_, bool* wipe_cache, const char* install_file) {
|
apply_from_adb(RecoveryUI* ui_, bool* wipe_cache, const char* install_file) {
|
||||||
|
modified_flash = true;
|
||||||
|
|
||||||
ui = ui_;
|
ui = ui_;
|
||||||
|
|
||||||
stop_adbd();
|
stop_adbd();
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ extern "C" {
|
|||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define EXPAND(x) STRINGIFY(x)
|
#define EXPAND(x) STRINGIFY(x)
|
||||||
|
|
||||||
|
extern bool modified_flash;
|
||||||
typedef struct fstab_rec Volume;
|
typedef struct fstab_rec Volume;
|
||||||
|
|
||||||
// fopen a file, mounting volumes and making parent dirs as necessary.
|
// fopen a file, mounting volumes and making parent dirs as necessary.
|
||||||
|
|||||||
@@ -256,6 +256,8 @@ int
|
|||||||
install_package(const char* path, bool* wipe_cache, const char* install_file,
|
install_package(const char* path, bool* wipe_cache, const char* install_file,
|
||||||
bool needs_mount)
|
bool needs_mount)
|
||||||
{
|
{
|
||||||
|
modified_flash = true;
|
||||||
|
|
||||||
FILE* install_log = fopen_path(install_file, "w");
|
FILE* install_log = fopen_path(install_file, "w");
|
||||||
if (install_log) {
|
if (install_log) {
|
||||||
fputs(path, install_log);
|
fputs(path, install_log);
|
||||||
|
|||||||
+28
-9
@@ -92,6 +92,7 @@ char* locale = NULL;
|
|||||||
char recovery_version[PROPERTY_VALUE_MAX+1];
|
char recovery_version[PROPERTY_VALUE_MAX+1];
|
||||||
char* stage = NULL;
|
char* stage = NULL;
|
||||||
char* reason = NULL;
|
char* reason = NULL;
|
||||||
|
bool modified_flash = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The recovery tool communicates with the main system through /cache files.
|
* The recovery tool communicates with the main system through /cache files.
|
||||||
@@ -337,13 +338,18 @@ copy_log_file(const char* source, const char* destination, int append) {
|
|||||||
|
|
||||||
// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max
|
// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max
|
||||||
// Overwrites any existing last_log.$max.
|
// Overwrites any existing last_log.$max.
|
||||||
static void
|
static void rotate_last_logs(int max) {
|
||||||
rotate_last_logs(int max) {
|
// Logs should only be rotated once.
|
||||||
|
static bool rotated = false;
|
||||||
|
if (rotated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rotated = true;
|
||||||
|
ensure_path_mounted(LAST_LOG_FILE);
|
||||||
|
|
||||||
char oldfn[256];
|
char oldfn[256];
|
||||||
char newfn[256];
|
char newfn[256];
|
||||||
|
for (int i = max-1; i >= 0; --i) {
|
||||||
int i;
|
|
||||||
for (i = max-1; i >= 0; --i) {
|
|
||||||
snprintf(oldfn, sizeof(oldfn), (i==0) ? LAST_LOG_FILE : (LAST_LOG_FILE ".%d"), i);
|
snprintf(oldfn, sizeof(oldfn), (i==0) ? LAST_LOG_FILE : (LAST_LOG_FILE ".%d"), i);
|
||||||
snprintf(newfn, sizeof(newfn), LAST_LOG_FILE ".%d", i+1);
|
snprintf(newfn, sizeof(newfn), LAST_LOG_FILE ".%d", i+1);
|
||||||
// ignore errors
|
// ignore errors
|
||||||
@@ -351,8 +357,17 @@ rotate_last_logs(int max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void copy_logs() {
|
||||||
copy_logs() {
|
// We only rotate and record the log of the current session if there are
|
||||||
|
// actual attempts to modify the flash, such as wipes, installs from BCB
|
||||||
|
// or menu selections. This is to avoid unnecessary rotation (and
|
||||||
|
// possible deletion) of log files, if it does not do anything loggable.
|
||||||
|
if (!modified_flash) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rotate_last_logs(KEEP_LOG_COUNT);
|
||||||
|
|
||||||
// Copy logs to cache so the system can find out what happened.
|
// Copy logs to cache so the system can find out what happened.
|
||||||
copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);
|
copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);
|
||||||
copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);
|
copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);
|
||||||
@@ -692,6 +707,8 @@ static bool wipe_data(int should_confirm, Device* device) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modified_flash = true;
|
||||||
|
|
||||||
ui->Print("\n-- Wiping data...\n");
|
ui->Print("\n-- Wiping data...\n");
|
||||||
if (device->WipeData() == 0 && erase_volume("/data") == 0 && erase_volume("/cache") == 0) {
|
if (device->WipeData() == 0 && erase_volume("/data") == 0 && erase_volume("/cache") == 0) {
|
||||||
ui->Print("Data wipe complete.\n");
|
ui->Print("Data wipe complete.\n");
|
||||||
@@ -708,6 +725,8 @@ static bool wipe_cache(bool should_confirm, Device* device) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modified_flash = true;
|
||||||
|
|
||||||
ui->Print("\n-- Wiping cache...\n");
|
ui->Print("\n-- Wiping cache...\n");
|
||||||
if (erase_volume("/cache") == 0) {
|
if (erase_volume("/cache") == 0) {
|
||||||
ui->Print("Cache wipe complete.\n");
|
ui->Print("Cache wipe complete.\n");
|
||||||
@@ -816,6 +835,8 @@ static void choose_recovery_file(Device* device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int apply_from_sdcard(Device* device, bool* wipe_cache) {
|
static int apply_from_sdcard(Device* device, bool* wipe_cache) {
|
||||||
|
modified_flash = true;
|
||||||
|
|
||||||
if (ensure_path_mounted(SDCARD_ROOT) != 0) {
|
if (ensure_path_mounted(SDCARD_ROOT) != 0) {
|
||||||
ui->Print("\n-- Couldn't mount %s.\n", SDCARD_ROOT);
|
ui->Print("\n-- Couldn't mount %s.\n", SDCARD_ROOT);
|
||||||
return INSTALL_ERROR;
|
return INSTALL_ERROR;
|
||||||
@@ -990,8 +1011,6 @@ main(int argc, char **argv) {
|
|||||||
printf("Starting recovery (pid %d) on %s", getpid(), ctime(&start));
|
printf("Starting recovery (pid %d) on %s", getpid(), ctime(&start));
|
||||||
|
|
||||||
load_volume_table();
|
load_volume_table();
|
||||||
ensure_path_mounted(LAST_LOG_FILE);
|
|
||||||
rotate_last_logs(KEEP_LOG_COUNT);
|
|
||||||
get_args(&argc, &argv);
|
get_args(&argc, &argv);
|
||||||
|
|
||||||
const char *send_intent = NULL;
|
const char *send_intent = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user