Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 329fe835 authored by Tao Bao's avatar Tao Bao
Browse files

Avoid crashing recovery with unwritable /cache.

When /cache is unwritable, recovery hits a crash loop. Because it
passes nullptr to fileno(3) when writing back the locale file. This
prevents user from recovering a device - it cannot boot far enough to
recovery menu which allows wiping /cache.

Bug: 63927337
Test: Corrupt /cache and boot into recovery on bullhead:
 1. m -j recoveryimage
 2. fastboot erase cache
 3. fastboot boot $OUT/recovery.img
 4. recovery menu shows up.
Change-Id: I1407743f802049eb48add56a36298b665cb86139
(cherry picked from commit ec57903a7ec0bfe3c2f39dd6ee9cfc3de4ed20e6)
parent d774ff24
Loading
Loading
Loading
Loading
+23 −25
Original line number Diff line number Diff line
@@ -478,21 +478,19 @@ static void copy_logs() {
    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
// idempotent: call it as many times as you like.
static void finish_recovery() {
    // Save the locale to cache, so if recovery is next started up
    // without a --locale argument (eg, directly from the bootloader)
    // it will use the last-known locale.
  // Save the locale to cache, so if recovery is next started up without a '--locale' argument
  // (e.g., directly from the bootloader) it will use the last-known locale.
  if (!locale.empty() && has_cache) {
    LOG(INFO) << "Saving locale \"" << locale << "\"";

        FILE* fp = fopen_path(LOCALE_FILE, "we");
        if (!android::base::WriteStringToFd(locale, fileno(fp))) {
    if (ensure_path_mounted(LOCALE_FILE) != 0) {
      LOG(ERROR) << "Failed to mount " << LOCALE_FILE;
    } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) {
      PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
    }
        check_and_fclose(fp, LOCALE_FILE);
  }

  copy_logs();