summaryrefslogtreecommitdiffstats
path: root/otautil
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-04-16 00:34:19 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-04-16 00:34:19 +0200
commit9fc764f1f0e6c4c581a5236d7558d97a1f90b38e (patch)
treec1ebcae66a7fbf7aaa79a6c1d894f2fa708ac441 /otautil
parentMerge "Import translations. DO NOT MERGE" (diff)
parentMove wipe cache|data to libinstall (diff)
downloadandroid_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar.gz
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar.bz2
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar.lz
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar.xz
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.tar.zst
android_bootable_recovery-9fc764f1f0e6c4c581a5236d7558d97a1f90b38e.zip
Diffstat (limited to '')
-rw-r--r--otautil/Android.bp1
-rw-r--r--otautil/include/otautil/logging.h (renamed from logging.h)5
-rw-r--r--otautil/logging.cpp (renamed from logging.cpp)25
3 files changed, 17 insertions, 14 deletions
diff --git a/otautil/Android.bp b/otautil/Android.bp
index c9ecba788..73398c3aa 100644
--- a/otautil/Android.bp
+++ b/otautil/Android.bp
@@ -40,6 +40,7 @@ cc_library_static {
android: {
srcs: [
"dirutil.cpp",
+ "logging.cpp",
"mounts.cpp",
"parse_install_logs.cpp",
"roots.cpp",
diff --git a/logging.h b/otautil/include/otautil/logging.h
index 3cfbc7af6..c4f13292b 100644
--- a/logging.h
+++ b/otautil/include/otautil/logging.h
@@ -26,6 +26,8 @@
static constexpr int KEEP_LOG_COUNT = 10;
+struct selabel_handle;
+
ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
void* arg);
@@ -41,8 +43,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_log_file(const std::string& source, const std::string& destination, bool append);
-void copy_logs(bool modified_flash, bool has_cache);
+void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle);
void reset_tmplog_offset();
void save_kernel_log(const char* destination);
diff --git a/logging.cpp b/otautil/logging.cpp
index 48f9ec317..7c330ac61 100644
--- a/logging.cpp
+++ b/otautil/logging.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "logging.h"
+#include "otautil/logging.h"
#include <stdio.h>
#include <string.h>
@@ -29,8 +29,8 @@
#include <android-base/stringprintf.h>
#include <private/android_filesystem_config.h> /* for AID_SYSTEM */
#include <private/android_logger.h> /* private pmsg functions */
+#include <selinux/label.h>
-#include "common.h"
#include "otautil/dirutil.h"
#include "otautil/paths.h"
#include "otautil/roots.h"
@@ -45,7 +45,7 @@ static const std::string LAST_LOG_FILTER = "recovery/last_log";
// 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, const char* mode) {
+static FILE* fopen_path(const std::string& path, const char* mode, const selabel_handle* sehandle) {
if (ensure_path_mounted(path) != 0) {
LOG(ERROR) << "Can't mount " << path;
return nullptr;
@@ -165,8 +165,9 @@ void reset_tmplog_offset() {
tmplog_offset = 0;
}
-void copy_log_file(const std::string& source, const std::string& destination, bool append) {
- FILE* dest_fp = fopen_path(destination, append ? "ae" : "we");
+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);
if (dest_fp == nullptr) {
PLOG(ERROR) << "Can't open " << destination;
} else {
@@ -189,11 +190,11 @@ void copy_log_file(const std::string& source, const std::string& destination, bo
}
}
-void copy_logs(bool modified_flash, bool has_cache) {
- // We only rotate and record the log of the current session if there are actual attempts to modify
- // the flash, such as wipes, installs from BCB or menu selections. This is to avoid unnecessary
+void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle) {
+ // 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 (!modified_flash) {
+ if (!save_current_log) {
return;
}
@@ -211,9 +212,9 @@ void copy_logs(bool modified_flash, bool has_cache) {
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);
- copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false);
- copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false);
+ 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);
save_kernel_log(LAST_KMSG_FILE);
chmod(LOG_FILE, 0600);
chown(LOG_FILE, AID_SYSTEM, AID_SYSTEM);