Merge "Avoid crashing recovery with unwritable /cache."

This commit is contained in:
Treehugger Robot 2017-07-21 23:14:08 +00:00 committed by Gerrit Code Review
commit 9187f1cc51

View file

@ -477,21 +477,19 @@ static void copy_logs() {
sync(); sync();
} }
// clear the recovery command and prepare to boot a (hopefully working) system, // 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). This function is // copy our log file to cache as well (for the system to read). This function is
// idempotent: call it as many times as you like. // idempotent: call it as many times as you like.
static void finish_recovery() { static void finish_recovery() {
// Save the locale to cache, so if recovery is next started up // Save the locale to cache, so if recovery is next started up without a '--locale' argument
// without a --locale argument (eg, directly from the bootloader) // (e.g., directly from the bootloader) it will use the last-known locale.
// it will use the last-known locale.
if (!locale.empty() && has_cache) { if (!locale.empty() && has_cache) {
LOG(INFO) << "Saving locale \"" << locale << "\""; LOG(INFO) << "Saving locale \"" << locale << "\"";
if (ensure_path_mounted(LOCALE_FILE) != 0) {
FILE* fp = fopen_path(LOCALE_FILE, "we"); LOG(ERROR) << "Failed to mount " << LOCALE_FILE;
if (!android::base::WriteStringToFd(locale, fileno(fp))) { } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) {
PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE; PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
} }
check_and_fclose(fp, LOCALE_FILE);
} }
copy_logs(); copy_logs();