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
This commit is contained in:
David Anderson 2021-11-05 19:26:56 -07:00
parent e179157dc5
commit 52de78e97b

View file

@ -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);
}
}