// // Strictly to deal with reboot into system after OTA after /data // mounts to pull the last pmsg file data and place it // into /data/misc/recovery/ directory, rotating it in. // // Usage: recovery-persist [--force-persist] // // On systems without /cache mount, all file content representing in the // recovery/ directory stored in /sys/fs/pstore/pmsg-ramoops-0 in logger // format that reside in the LOG_ID_SYSTEM buffer at ANDROID_LOG_INFO // priority or higher is transfered to the /data/misc/recovery/ directory. // The content is matched and rotated in as need be. // // --force-persist ignore /cache mount, always rotate in the contents. //
// close a file, log an error if the error indicator is set staticvoid check_and_fclose(FILE *fp, constchar *name) {
fflush(fp); if (ferror(fp)) {
PLOG(ERROR) << "Error in " << name;
}
fclose(fp);
}
if (!android::base::ReadFully(fd1, buf1.data(), bytes_to_read)) {
LOG(ERROR) << "Failed to read from " << file1; returnfalse;
} if (!android::base::ReadFully(fd2, buf2.data(), bytes_to_read)) {
LOG(ERROR) << "Failed to read from " << file2; returnfalse;
} if (memcmp(buf1.data(), buf2.data(), bytes_to_read) != 0) { returnfalse;
}
} returntrue;
}
void rotate_last_kmsg() { if (rotated) { return;
} if (!file_exists(LAST_CONSOLE_FILE) && !file_exists(ALT_LAST_CONSOLE_FILE)) { return;
} if (!compare_file(LAST_KMSG_FILE, LAST_CONSOLE_FILE) &&
!compare_file(LAST_KMSG_FILE, ALT_LAST_CONSOLE_FILE)) {
rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE);
rotated = true;
}
}
int main(int argc, char **argv) {
/* Is /cache a mount?, we have been delivered where we are not wanted */ /* *Followingcodehalvesthesizeoftheexecutableascomparedto: * *load_volume_table(); *has_cache=volume_for_path(CACHE_ROOT)!=nullptr;
*/ bool has_cache = false; staticconstchar mounts_file[] = "/proc/mounts";
FILE* fp = fopen(mounts_file, "re"); if (!fp) {
PLOG(ERROR) << "failed to open " << mounts_file;
} else { char *line = NULL;
size_t len = 0;
ssize_t read{}; while ((read = getline(&line, &len, fp)) != -1) { if (strstr(line, " /cache ")) {
has_cache = true; break;
}
}
free(line);
fclose(fp);
}
if (has_cache) { // Collects and reports the non-a/b update metrics from last_install; and removes the file // to avoid duplicate report. if (file_exists(LAST_INSTALL_FILE_IN_CACHE) && unlink(LAST_INSTALL_FILE_IN_CACHE) == -1) {
PLOG(ERROR) << "Failed to unlink " << LAST_INSTALL_FILE_IN_CACHE;
}
// TBD: Future location to move content from /cache/recovery to /data/misc/recovery/ // if --force-persist flag, then transfer pmsg data anyways if ((argc <= 1) || !argv[1] || strcmp(argv[1], "--force-persist")) { return0;
}
}
/* Is there something in pmsg? If not, no need to proceed. */ if (!file_exists(LAST_PMSG_FILE)) { return0;
}
// Take last pmsg file contents and send it off to the logsave
__android_log_pmsg_file_read(
LOG_ID_SYSTEM, ANDROID_LOG_INFO, "recovery/", logsave, NULL);
// For those device without /cache, the last_install file has been copied to // /data/misc/recovery from pmsg. Looks for the sideload history only. if (!has_cache) { if (file_exists(LAST_INSTALL_FILE) && unlink(LAST_INSTALL_FILE) == -1) {
PLOG(ERROR) << "Failed to unlink " << LAST_INSTALL_FILE;
}
}
rotate_last_kmsg();
/* Is there a last console log too? */ if (rotated) { if (file_exists(LAST_CONSOLE_FILE)) {
copy_file(LAST_CONSOLE_FILE, LAST_KMSG_FILE);
} elseif (file_exists(ALT_LAST_CONSOLE_FILE)) {
copy_file(ALT_LAST_CONSOLE_FILE, LAST_KMSG_FILE);
}
}
return0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.