// fopen(3)'s the given file, by mounting volumes and making parent dirs as necessary. Returns the // file pointer, or nullptr on error. static FILE* fopen_path(const std::string& path, constchar* mode, const selabel_handle* sehandle) { if (ensure_path_mounted(path) != 0) {
LOG(ERROR) << "Can't mount " << path; return nullptr;
}
// When writing, try to create the containing directory, if necessary. Use generous permissions, // the system (init.rc) will reset them. if (strchr("wa", mode[0])) {
mkdir_recursively(path, 0777, true, sehandle);
} return fopen(path.c_str(), mode);
}
void check_and_fclose(FILE* fp, const std::string& name) {
fflush(fp); if (fsync(fileno(fp)) == -1) {
PLOG(ERROR) << "Failed to fsync " << name;
} if (ferror(fp)) {
PLOG(ERROR) << "Error in " << name;
}
fclose(fp);
}
// close a file, log an error if the error indicator is set
ssize_t logbasename(log_id_t /* id */, char /* prio */, const char* filename, const char* /* buf */,
size_t len, void* arg) { bool* do_rotate = static_cast<bool*>(arg); if (std::string(LAST_KMSG_FILTER).find(filename) != std::string::npos ||
std::string(LAST_LOG_FILTER).find(filename) != std::string::npos) {
*do_rotate = true;
} return len;
}
void copy_logs(bool save_current_log) { // We only rotate and record the log of the current session if explicitly requested. This usually // happens after wipes, installation from BCB or menu selections. This is to avoid unnecessary // rotation (and possible deletion) of log files, if it does not do anything loggable. if (!save_current_log) { return;
}
// Always write to pmsg, this allows the OTA logs to be caught in `logcat -L`.
copy_log_file_to_pmsg(Paths::Get().temporary_log_file(), LAST_LOG_FILE);
copy_log_file_to_pmsg(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE);
// We can do nothing for now if there's no /cache partition. if (!HasCache()) { return;
}
// Copy logs to cache so the system can find out what happened.
copy_log_file(Paths::Get().temporary_log_file(), LOG_FILE, true);
copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false);
copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false);
save_kernel_log(LAST_KMSG_FILE);
chmod(LOG_FILE, 0600);
chown(LOG_FILE, AID_SYSTEM, AID_SYSTEM);
chmod(LAST_KMSG_FILE, 0600);
chown(LAST_KMSG_FILE, AID_SYSTEM, AID_SYSTEM);
chmod(LAST_LOG_FILE, 0640);
chmod(LAST_INSTALL_FILE, 0644);
chown(LAST_INSTALL_FILE, AID_SYSTEM, AID_SYSTEM);
sync();
}
// Read from kernel log into buffer and write out to file. void save_kernel_log(constchar* destination) { int klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0); if (klog_buf_len <= 0) {
PLOG(ERROR) << "Error getting klog size"; return;
}
std::string buffer(klog_buf_len, 0); int n = klogctl(KLOG_READ_ALL, &buffer[0], klog_buf_len); if (n == -1) {
PLOG(ERROR) << "Error in reading klog"; return;
}
buffer.resize(n);
android::base::WriteStringToFile(buffer, destination);
}
log_files.emplace_back(saved_log_file{ path, sb, data });
}
}
return log_files;
}
bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files) { // Re-create the log dir and write back the log entries. if (ensure_path_mounted(CACHE_LOG_DIR) != 0) {
PLOG(ERROR) << "Failed to mount " << CACHE_LOG_DIR; returnfalse;
}
if (mkdir_recursively(CACHE_LOG_DIR, 0777, false, logging_sehandle) != 0) {
PLOG(ERROR) << "Failed to create " << CACHE_LOG_DIR; returnfalse;
}
for (constauto& log : log_files) { if (!android::base::WriteStringToFile(log.data, log.name, log.sb.st_mode, log.sb.st_uid,
log.sb.st_gid)) {
PLOG(ERROR) << "Failed to write to " << log.name;
}
}
// 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.
reset_tmplog_offset();
copy_logs(true/* save_current_log */);
returntrue;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-07-01)
¤
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.