aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-07-21 18:22:31 -0500
committerandroid-build-merger2017-07-21 18:22:31 -0500
commit4fb2825dc29823aef37febff819561630a4a8fba (patch)
treef0dce70f1cde986c1eed77f53db19207fb027c39 /recovery.cpp
parent80acaab52f019c2db0d05865ef63fd533d0a668b (diff)
parent9187f1cc51cc04155754d0ed34a5fc875acb9af4 (diff)
downloadplatform-bootable-recovery-4fb2825dc29823aef37febff819561630a4a8fba.tar.gz
platform-bootable-recovery-4fb2825dc29823aef37febff819561630a4a8fba.tar.xz
platform-bootable-recovery-4fb2825dc29823aef37febff819561630a4a8fba.zip
Merge "Avoid crashing recovery with unwritable /cache."
am: 9187f1cc51 Change-Id: Ie5708c2f703aefbfcad85ad0d2d24ae36b725c78
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp48
1 files changed, 23 insertions, 25 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 50115885..11c12f6f 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -478,40 +478,38 @@ static void copy_logs() {
478 sync(); 478 sync();
479} 479}
480 480
481// clear the recovery command and prepare to boot a (hopefully working) system, 481// Clear the recovery command and prepare to boot a (hopefully working) system,
482// copy our log file to cache as well (for the system to read). This function is 482// copy our log file to cache as well (for the system to read). This function is
483// idempotent: call it as many times as you like. 483// idempotent: call it as many times as you like.
484static void finish_recovery() { 484static void finish_recovery() {
485 // Save the locale to cache, so if recovery is next started up 485 // Save the locale to cache, so if recovery is next started up without a '--locale' argument
486 // without a --locale argument (eg, directly from the bootloader) 486 // (e.g., directly from the bootloader) it will use the last-known locale.
487 // it will use the last-known locale. 487 if (!locale.empty() && has_cache) {
488 if (!locale.empty() && has_cache) { 488 LOG(INFO) << "Saving locale \"" << locale << "\"";
489 LOG(INFO) << "Saving locale \"" << locale << "\""; 489 if (ensure_path_mounted(LOCALE_FILE) != 0) {
490 490 LOG(ERROR) << "Failed to mount " << LOCALE_FILE;
491 FILE* fp = fopen_path(LOCALE_FILE, "we"); 491 } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) {
492 if (!android::base::WriteStringToFd(locale, fileno(fp))) { 492 PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
493 PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
494 }
495 check_and_fclose(fp, LOCALE_FILE);
496 } 493 }
494 }
497 495
498 copy_logs(); 496 copy_logs();
499 497
500 // Reset to normal system boot so recovery won't cycle indefinitely. 498 // Reset to normal system boot so recovery won't cycle indefinitely.
501 std::string err; 499 std::string err;
502 if (!clear_bootloader_message(&err)) { 500 if (!clear_bootloader_message(&err)) {
503 LOG(ERROR) << "Failed to clear BCB message: " << err; 501 LOG(ERROR) << "Failed to clear BCB message: " << err;
504 } 502 }
505 503
506 // Remove the command file, so recovery won't repeat indefinitely. 504 // Remove the command file, so recovery won't repeat indefinitely.
507 if (has_cache) { 505 if (has_cache) {
508 if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { 506 if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) {
509 LOG(WARNING) << "Can't unlink " << COMMAND_FILE; 507 LOG(WARNING) << "Can't unlink " << COMMAND_FILE;
510 }
511 ensure_path_unmounted(CACHE_ROOT);
512 } 508 }
509 ensure_path_unmounted(CACHE_ROOT);
510 }
513 511
514 sync(); // For good measure. 512 sync(); // For good measure.
515} 513}
516 514
517struct saved_log_file { 515struct saved_log_file {