From c2ea6e7c39c5a03a3b3cdcbfeed3f58bdc059921 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 16 Jan 2019 13:57:31 -0800 Subject: [PATCH] Remove __android_log_event_list and the reader aspect of android_log_event_list One user of each, dubious API, remove it while we work on a new one. Test: build Change-Id: If422246226addaf873dc2af32553fad3a5182089 --- liblog/include/log/log_event_list.h | 13 --------- liblog/include/private/android_logger.h | 31 --------------------- libstats/include/stats_event_list.h | 7 ----- logd/LogTags.cpp | 37 ++++++++++++++++++------- 4 files changed, 27 insertions(+), 61 deletions(-) diff --git a/liblog/include/log/log_event_list.h b/liblog/include/log/log_event_list.h index b37650424..636d417e8 100644 --- a/liblog/include/log/log_event_list.h +++ b/liblog/include/log/log_event_list.h @@ -109,8 +109,6 @@ int android_log_destroy(android_log_context* ctx); /* android_log_list C++ helpers */ extern "C++" { class android_log_event_list { - friend class __android_log_event_list; - private: android_log_context ctx; int ret; @@ -122,10 +120,6 @@ class android_log_event_list { explicit android_log_event_list(int tag) : ret(0) { ctx = create_android_logger(static_cast(tag)); } - explicit android_log_event_list(log_msg& log_msg) : ret(0) { - ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t), - log_msg.entry.len - sizeof(uint32_t)); - } ~android_log_event_list() { android_log_destroy(&ctx); } @@ -283,13 +277,6 @@ class android_log_event_list { if (retval < 0) ret = retval; return ret >= 0; } - - android_log_list_element read() { - return android_log_read_next(ctx); - } - android_log_list_element peek() { - return android_log_peek_next(ctx); - } }; } #endif diff --git a/liblog/include/private/android_logger.h b/liblog/include/private/android_logger.h index 830f6516b..5e04148b7 100644 --- a/liblog/include/private/android_logger.h +++ b/liblog/include/private/android_logger.h @@ -150,37 +150,6 @@ bool __android_logger_valid_buffer_size(unsigned long value); /* Retrieve the composed event buffer */ int android_log_write_list_buffer(android_log_context ctx, const char** msg); -#ifdef __cplusplus -#ifdef __class_android_log_event_list_defined -#ifndef __class_android_log_event_list_private_defined -#define __class_android_log_event_list_private_defined -/* android_log_context C++ helpers */ -extern "C++" { -class __android_log_event_list : public android_log_event_list { - __android_log_event_list(const android_log_event_list&) = delete; - void operator=(const __android_log_event_list&) = delete; - - public: - explicit __android_log_event_list(int tag) : android_log_event_list(tag) { - } - explicit __android_log_event_list(log_msg& log_msg) - : android_log_event_list(log_msg) { - } - - operator std::string() { - if (ret) return std::string(""); - const char* cp = nullptr; - ssize_t len = android_log_write_list_buffer(ctx, &cp); - if (len < 0) ret = len; - if (!cp || (len <= 0)) return std::string(""); - return std::string(cp, len); - } -}; -} -#endif -#endif -#endif - #if defined(__cplusplus) } #endif diff --git a/libstats/include/stats_event_list.h b/libstats/include/stats_event_list.h index 162d1cfeb..b5bc5af50 100644 --- a/libstats/include/stats_event_list.h +++ b/libstats/include/stats_event_list.h @@ -51,10 +51,6 @@ class stats_event_list { explicit stats_event_list(int tag) : ret(0) { ctx = create_android_logger(static_cast(tag)); } - explicit stats_event_list(log_msg& log_msg) : ret(0) { - ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t), - log_msg.entry.len - sizeof(uint32_t)); - } ~stats_event_list() { android_log_destroy(&ctx); } int close() { @@ -251,9 +247,6 @@ class stats_event_list { } return ret >= 0; } - - android_log_list_element read() { return android_log_read_next(ctx); } - android_log_list_element peek() { return android_log_peek_next(ctx); } }; #endif 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 #include +#include #include #include #include @@ -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(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 {