diff options
author | Doug Zongker <dougz@android.com> | 2010-09-29 22:21:30 +0200 |
---|---|---|
committer | Doug Zongker <dougz@android.com> | 2010-09-29 22:40:44 +0200 |
commit | 2c3539e4d8251ad91e0b881253d39583680093e8 (patch) | |
tree | 17003913f4522c09f0155719f16c7929f9c02ca7 | |
parent | handle old-style CACHE: packages (diff) | |
download | android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar.gz android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar.bz2 android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar.lz android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar.xz android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.tar.zst android_bootable_recovery-2c3539e4d8251ad91e0b881253d39583680093e8.zip |
Diffstat (limited to '')
-rw-r--r-- | recovery.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/recovery.c b/recovery.c index 6f9f8e750..452794aff 100644 --- a/recovery.c +++ b/recovery.c @@ -53,6 +53,7 @@ static const struct option OPTIONS[] = { static const char *COMMAND_FILE = "/cache/recovery/command"; static const char *INTENT_FILE = "/cache/recovery/intent"; static const char *LOG_FILE = "/cache/recovery/log"; +static const char *LAST_LOG_FILE = "/cache/recovery/last_log"; static const char *SDCARD_ROOT = "/sdcard"; static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload"; @@ -237,6 +238,34 @@ set_sdcard_update_bootloader_message() { set_bootloader_message(&boot); } +// How much of the temp log we have copied to the copy in cache. +static long tmplog_offset = 0; + +static void +copy_log_file(const char* destination, int append) { + FILE *log = fopen_path(destination, append ? "a" : "w"); + if (log == NULL) { + LOGE("Can't open %s\n", destination); + } else { + FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r"); + if (tmplog == NULL) { + LOGE("Can't open %s\n", TEMPORARY_LOG_FILE); + } else { + if (append) { + fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write + } + char buf[4096]; + while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); + if (append) { + tmplog_offset = ftell(tmplog); + } + check_and_fclose(tmplog, TEMPORARY_LOG_FILE); + } + check_and_fclose(log, destination); + } +} + + // clear the recovery command and prepare to boot a (hopefully working) system, // copy our log file to cache as well (for the system to read), and // record any intent we were asked to communicate back to the system. @@ -255,23 +284,9 @@ finish_recovery(const char *send_intent) { } // Copy logs to cache so the system can find out what happened. - FILE *log = fopen_path(LOG_FILE, "a"); - if (log == NULL) { - LOGE("Can't open %s\n", LOG_FILE); - } else { - FILE *tmplog = fopen(TEMPORARY_LOG_FILE, "r"); - if (tmplog == NULL) { - LOGE("Can't open %s\n", TEMPORARY_LOG_FILE); - } else { - static long tmplog_offset = 0; - fseek(tmplog, tmplog_offset, SEEK_SET); // Since last write - char buf[4096]; - while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log); - tmplog_offset = ftell(tmplog); - check_and_fclose(tmplog, TEMPORARY_LOG_FILE); - } - check_and_fclose(log, LOG_FILE); - } + copy_log_file(LOG_FILE, true); + copy_log_file(LAST_LOG_FILE, false); + chmod(LAST_LOG_FILE, 0640); // Reset to mormal system boot so recovery won't cycle indefinitely. struct bootloader_message boot; @@ -292,6 +307,14 @@ erase_volume(const char *volume) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); ui_print("Formatting %s...\n", volume); + + if (strcmp(volume, "/cache") == 0) { + // Any part of the log we'd copied to cache is now gone. + // Reset the pointer so we copy from the beginning of the temp + // log. + tmplog_offset = 0; + } + return format_volume(volume); } |