diff options
author | Tom Cherry <tomcherry@google.com> | 2019-01-17 17:18:10 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-01-17 17:18:10 +0000 |
commit | 065854748e84cb4b29baf52948296f7d293ddb02 (patch) | |
tree | bfd1a90330d796c27bd022f01d49e2aa94b12e9e /logd | |
parent | b94c2e52a674d43705045d0662e6a427aee2e873 (diff) | |
parent | c2ea6e7c39c5a03a3b3cdcbfeed3f58bdc059921 (diff) | |
download | core-065854748e84cb4b29baf52948296f7d293ddb02.tar.gz |
Merge "Remove __android_log_event_list and the reader aspect of android_log_event_list"
Diffstat (limited to 'logd')
-rw-r--r-- | logd/LogTags.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/logd/LogTags.cpp b/logd/LogTags.cpp index 1ab9dd1b6..f19e7b09d 100644 --- a/logd/LogTags.cpp +++ b/logd/LogTags.cpp @@ -30,6 +30,7 @@ #include <android-base/file.h> #include <android-base/macros.h> +#include <android-base/scopeguard.h> #include <android-base/stringprintf.h> #include <log/log_event_list.h> #include <log/log_properties.h> @@ -38,6 +39,8 @@ #include "LogTags.h" #include "LogUtils.h" +using android::base::make_scope_guard; + static LogTags* logtags; const char LogTags::system_event_log_tags[] = "/system/etc/event-log-tags"; @@ -316,27 +319,29 @@ void LogTags::ReadPersistEventLogTags() { std::string Format; android_log_list_element elem; { - android_log_event_list ctx(log_msg); - elem = ctx.read(); + auto ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t), + log_msg.entry.len - sizeof(uint32_t)); + auto guard = make_scope_guard([&ctx]() { android_log_destroy(&ctx); }); + elem = android_log_read_next(ctx); if (elem.type != EVENT_TYPE_LIST) { continue; } - elem = ctx.read(); + elem = android_log_read_next(ctx); if (elem.type != EVENT_TYPE_INT) { continue; } Tag = elem.data.int32; - elem = ctx.read(); + elem = android_log_read_next(ctx); if (elem.type != EVENT_TYPE_STRING) { continue; } Name = std::string(elem.data.string, elem.len); - elem = ctx.read(); + elem = android_log_read_next(ctx); if (elem.type != EVENT_TYPE_STRING) { continue; } Format = std::string(elem.data.string, elem.len); - elem = ctx.read(); + elem = android_log_read_next(ctx); } if ((elem.type != EVENT_TYPE_LIST_STOP) || !elem.complete) continue; @@ -524,10 +529,22 @@ void LogTags::WritePmsgEventLogTags(uint32_t tag, uid_t uid) { tag2format_const_iterator iform = tag2format.find(tag); std::string Format = (iform != tag2format.end()) ? iform->second : ""; - __android_log_event_list ctx(TAG_DEF_LOG_TAG); - ctx << tag << Name << Format; - std::string buffer(ctx); - if (buffer.length() <= 0) return; // unlikely + auto ctx = create_android_logger(TAG_DEF_LOG_TAG); + auto guard = make_scope_guard([&ctx]() { android_log_destroy(&ctx); }); + if (android_log_write_int32(ctx, static_cast<int32_t>(tag) < 0) || + android_log_write_string8_len(ctx, Name.c_str(), Name.size()) < 0 || + android_log_write_string8_len(ctx, Format.c_str(), Format.size()) < 0) { + return; + } + + const char* cp = nullptr; + ssize_t len = android_log_write_list_buffer(ctx, &cp); + + if (len <= 0 || cp == nullptr) { + return; + } + + std::string buffer(cp, len); /* * struct { |