From 2ac86de15a33877b301500c211b49990ec76e8e8 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 20 Feb 2020 13:21:51 -0800 Subject: [PATCH] logd: don't coalesce identical log messages in the security buffer This buffer isn't human readable and the parsers aren't set up to handle the 'chatty' message for identical log messages. Further, it is a low volume buffer so there's not much in terms of memory saving if this were enabled. Bug: 137093665 Test: security unit tests Change-Id: I03fce518d3308a6d9240bd29e83ff3237203fe3b --- logd/LogBuffer.cpp | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 834b20b6b..1cf20617f 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -207,31 +207,37 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, // exact entry with time specified in ms or us precision. if ((realtime.tv_nsec % 1000) == 0) ++realtime.tv_nsec; - LogBufferElement* elem = - new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len); - if (log_id != LOG_ID_SECURITY) { - int prio = ANDROID_LOG_INFO; - const char* tag = nullptr; - size_t tag_len = 0; - if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) { - tag = tagToName(elem->getTag()); - if (tag) { - tag_len = strlen(tag); - } - } else { - prio = *msg; - tag = msg + 1; - tag_len = strnlen(tag, len - 1); - } - if (!__android_log_is_loggable_len(prio, tag, tag_len, - ANDROID_LOG_VERBOSE)) { - // Log traffic received to total - wrlock(); - stats.addTotal(elem); - unlock(); - delete elem; - return -EACCES; + LogBufferElement* elem = new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len); + + // b/137093665: don't coalesce security messages. + if (log_id == LOG_ID_SECURITY) { + wrlock(); + log(elem); + unlock(); + + return len; + } + + int prio = ANDROID_LOG_INFO; + const char* tag = nullptr; + size_t tag_len = 0; + if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) { + tag = tagToName(elem->getTag()); + if (tag) { + tag_len = strlen(tag); } + } else { + prio = *msg; + tag = msg + 1; + tag_len = strnlen(tag, len - 1); + } + if (!__android_log_is_loggable_len(prio, tag, tag_len, ANDROID_LOG_VERBOSE)) { + // Log traffic received to total + wrlock(); + stats.addTotal(elem); + unlock(); + delete elem; + return -EACCES; } wrlock();