diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-07-20 20:46:56 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-07-20 20:46:56 +0000 |
commit | de717d55c7a3f7d8051222f26ef12eb38b3777f2 (patch) | |
tree | c01ca2455dc9bd1dc34dcdd2bf0fbe880dc3f2be | |
parent | 2b82d1160cbbd94c6dadda316b55b717fbca4d60 (diff) | |
parent | 505fb5a068f4bc592196cff8d6be11090b253b22 (diff) | |
download | system_core-de717d55c7a3f7d8051222f26ef12eb38b3777f2.tar.gz system_core-de717d55c7a3f7d8051222f26ef12eb38b3777f2.tar.bz2 system_core-de717d55c7a3f7d8051222f26ef12eb38b3777f2.zip |
Merge \\\\"logd: auditd: suppress multiple identical avc: messages to kmsg\\\\" am: 02ccdc5db9 am: 8e7e71c56a am: 7e0c62d33e
am: 505fb5a068
Change-Id: I593498b94e5e09c25b83f69d9ea57b473e6c2feb
-rw-r--r-- | logd/LogAudit.cpp | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index 24c3f52d9..cc140b0a9 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -102,16 +102,72 @@ int LogAudit::logPrint(const char *fmt, ...) { struct iovec iov[3]; static const char log_info[] = { KMSG_PRIORITY(LOG_INFO) }; static const char log_warning[] = { KMSG_PRIORITY(LOG_WARNING) }; - - iov[0].iov_base = info ? const_cast<char *>(log_info) - : const_cast<char *>(log_warning); - iov[0].iov_len = info ? sizeof(log_info) : sizeof(log_warning); - iov[1].iov_base = str; - iov[1].iov_len = strlen(str); - iov[2].iov_base = const_cast<char *>("\n"); - iov[2].iov_len = 1; - - writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); + static const char newline[] = "\n"; + + // Dedupe messages, checking for identical messages starting with avc: + static unsigned count; + static char *last_str; + static bool last_info; + + if (last_str != NULL) { + static const char avc[] = "): avc: "; + char *avcl = strstr(last_str, avc); + bool skip = false; + + if (avcl) { + char *avcr = strstr(str, avc); + + skip = avcr && !strcmp(avcl + strlen(avc), avcr + strlen(avc)); + if (skip) { + ++count; + free(last_str); + last_str = strdup(str); + last_info = info; + } + } + if (!skip) { + static const char resume[] = " duplicate messages suppressed\n"; + + iov[0].iov_base = last_info ? + const_cast<char *>(log_info) : + const_cast<char *>(log_warning); + iov[0].iov_len = last_info ? + sizeof(log_info) : + sizeof(log_warning); + iov[1].iov_base = last_str; + iov[1].iov_len = strlen(last_str); + if (count > 1) { + iov[2].iov_base = const_cast<char *>(resume); + iov[2].iov_len = strlen(resume); + } else { + iov[2].iov_base = const_cast<char *>(newline); + iov[2].iov_len = strlen(newline); + } + + writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); + free(last_str); + last_str = NULL; + } + } + if (last_str == NULL) { + count = 0; + last_str = strdup(str); + last_info = info; + } + if (count == 0) { + iov[0].iov_base = info ? + const_cast<char *>(log_info) : + const_cast<char *>(log_warning); + iov[0].iov_len = info ? + sizeof(log_info) : + sizeof(log_warning); + iov[1].iov_base = str; + iov[1].iov_len = strlen(str); + iov[2].iov_base = const_cast<char *>(newline); + iov[2].iov_len = strlen(newline); + + writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); + } } pid_t pid = getpid(); |