From 52de78e97b3abeac6397d46263897774f19c9ca8 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 5 Nov 2021 19:26:56 -0700 Subject: [PATCH] Route error logs to the kernel during early boot. This is needed to debug vold mounting errors before adb is up. It also helps diagnose failures on devices that store dmesg persistently. Tested by adding an error log with serial attached. Bug: 205314634 Test: manual test Change-Id: Ia095340c562e3f1f94bc44c5d13ad466a7a35345 --- main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 641d13a..978db66 100644 --- a/main.cpp +++ b/main.cpp @@ -52,8 +52,11 @@ typedef struct vold_configs { static int process_config(VolumeManager* vm, VoldConfigs* configs); static void coldboot(const char* path); static void parse_args(int argc, char** argv); +static void VoldLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity, + const char* tag, const char* file, unsigned int line, const char* message); struct selabel_handle* sehandle; +android::base::LogdLogger logd_logger(android::base::SYSTEM); using android::base::StringPrintf; using android::fs_mgr::ReadDefaultFstab; @@ -61,7 +64,7 @@ using android::fs_mgr::ReadDefaultFstab; int main(int argc, char** argv) { atrace_set_tracing_enabled(false); setenv("ANDROID_LOG_TAGS", "*:d", 1); // Do not submit with verbose logs enabled - android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); + android::base::InitLogging(argv, &VoldLogger); LOG(INFO) << "Vold 3.0 (the awakening) firing up"; @@ -278,3 +281,23 @@ static int process_config(VolumeManager* vm, VoldConfigs* configs) { } return 0; } + +static void VoldLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity, + const char* tag, const char* file, unsigned int line, const char* message) { + logd_logger(log_buffer_id, severity, tag, file, line, message); + + if (severity >= android::base::ERROR) { + static bool is_data_mounted = false; + + // When /data fails to mount, we don't have adb to get logcat. So until /data is + // mounted we log errors to the kernel. This allows us to get failures via serial logs + // and via last dmesg/"fastboot oem dmesg" on devices that support it. + // + // As a very quick-and-dirty test for /data, we check whether /data/misc/vold exists. + if (is_data_mounted || access("/data/misc/vold", F_OK) == 0) { + is_data_mounted = true; + return; + } + android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message); + } +}