summaryrefslogtreecommitdiffstats
path: root/otautil
diff options
context:
space:
mode:
Diffstat (limited to 'otautil')
-rw-r--r--otautil/include/otautil/logging.h2
-rw-r--r--otautil/include/otautil/roots.h3
-rw-r--r--otautil/logging.cpp17
-rw-r--r--otautil/roots.cpp8
4 files changed, 20 insertions, 10 deletions
diff --git a/otautil/include/otautil/logging.h b/otautil/include/otautil/logging.h
index 608349785..4462eca6e 100644
--- a/otautil/include/otautil/logging.h
+++ b/otautil/include/otautil/logging.h
@@ -53,7 +53,7 @@ void rotate_logs(const char* last_log_file, const char* last_kmsg_file);
void check_and_fclose(FILE* fp, const std::string& name);
void copy_log_file_to_pmsg(const std::string& source, const std::string& destination);
-void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle);
+void copy_logs(bool save_current_log);
void reset_tmplog_offset();
void save_kernel_log(const char* destination);
diff --git a/otautil/include/otautil/roots.h b/otautil/include/otautil/roots.h
index 2ab3f4549..92ee756f0 100644
--- a/otautil/include/otautil/roots.h
+++ b/otautil/include/otautil/roots.h
@@ -53,3 +53,6 @@ int format_volume(const std::string& volume, const std::string& directory);
// Ensure that all and only the volumes that packages expect to find
// mounted (/tmp and /cache) are mounted. Returns 0 on success.
int setup_install_mounts();
+
+// Returns true if there is /cache in the volumes.
+bool HasCache();
diff --git a/otautil/logging.cpp b/otautil/logging.cpp
index 484f1150f..3db0e8ac2 100644
--- a/otautil/logging.cpp
+++ b/otautil/logging.cpp
@@ -178,9 +178,8 @@ void reset_tmplog_offset() {
tmplog_offset = 0;
}
-static void copy_log_file(const std::string& source, const std::string& destination, bool append,
- const selabel_handle* sehandle) {
- FILE* dest_fp = fopen_path(destination, append ? "ae" : "we", sehandle);
+static void copy_log_file(const std::string& source, const std::string& destination, bool append) {
+ FILE* dest_fp = fopen_path(destination, append ? "ae" : "we", logging_sehandle);
if (dest_fp == nullptr) {
PLOG(ERROR) << "Can't open " << destination;
} else {
@@ -203,7 +202,7 @@ static void copy_log_file(const std::string& source, const std::string& destinat
}
}
-void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle) {
+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.
@@ -216,7 +215,7 @@ void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* seha
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 (!has_cache) {
+ if (!HasCache()) {
return;
}
@@ -225,9 +224,9 @@ void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* seha
rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE);
// Copy logs to cache so the system can find out what happened.
- copy_log_file(Paths::Get().temporary_log_file(), LOG_FILE, true, sehandle);
- copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false, sehandle);
- copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false, sehandle);
+ 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);
@@ -319,7 +318,7 @@ bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files) {
// Reset the pointer so we copy from the beginning of the temp
// log.
reset_tmplog_offset();
- copy_logs(true /* save_current_log */, true /* has_cache */, logging_sehandle);
+ copy_logs(true /* save_current_log */);
return true;
}
diff --git a/otautil/roots.cpp b/otautil/roots.cpp
index a778e05ff..431551785 100644
--- a/otautil/roots.cpp
+++ b/otautil/roots.cpp
@@ -51,6 +51,8 @@ using android::fs_mgr::ReadDefaultFstab;
static Fstab fstab;
+constexpr const char* CACHE_ROOT = "/cache";
+
void load_volume_table() {
if (!ReadDefaultFstab(&fstab)) {
LOG(ERROR) << "Failed to read default fstab";
@@ -275,3 +277,9 @@ int setup_install_mounts() {
}
return 0;
}
+
+bool HasCache() {
+ CHECK(!fstab.empty());
+ static bool has_cache = volume_for_mount_point(CACHE_ROOT) != nullptr;
+ return has_cache;
+}