summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2018-08-01 21:45:55 -0500
committerGerrit Code Review2018-08-01 21:45:55 -0500
commit2d5c1b56d2732dbc6697ccc4c20f3de909df4402 (patch)
treeb0a6967d0408d1290b8e935fce2a839c884a8e67
parent8f2a34a89b7ff1263217049fe837237b3af16814 (diff)
parentbb20b9e6b85c381199a495a7dfdbbfd57fcb1705 (diff)
downloadplatform-system-core-2d5c1b56d2732dbc6697ccc4c20f3de909df4402.tar.gz
platform-system-core-2d5c1b56d2732dbc6697ccc4c20f3de909df4402.tar.xz
platform-system-core-2d5c1b56d2732dbc6697ccc4c20f3de909df4402.zip
Merge "liblog: Add functions to reset log context"
-rw-r--r--liblog/include/log/log_event_list.h7
-rw-r--r--liblog/include_vndk/log/log_event_list.h7
-rw-r--r--liblog/liblog.map.txt6
-rw-r--r--liblog/log_event_list.c64
4 files changed, 73 insertions, 11 deletions
diff --git a/liblog/include/log/log_event_list.h b/liblog/include/log/log_event_list.h
index bb1ce3485..1b7c37717 100644
--- a/liblog/include/log/log_event_list.h
+++ b/liblog/include/log/log_event_list.h
@@ -108,6 +108,13 @@ android_log_context create_android_log_parser(const char* msg, size_t len);
108android_log_list_element android_log_read_next(android_log_context ctx); 108android_log_list_element android_log_read_next(android_log_context ctx);
109android_log_list_element android_log_peek_next(android_log_context ctx); 109android_log_list_element android_log_peek_next(android_log_context ctx);
110 110
111/* Reset writer context */
112int android_log_reset(android_log_context ctx);
113
114/* Reset reader context */
115int android_log_parser_reset(android_log_context ctx,
116 const char* msg, size_t len);
117
111/* Finished with reader or writer context */ 118/* Finished with reader or writer context */
112int android_log_destroy(android_log_context* ctx); 119int android_log_destroy(android_log_context* ctx);
113 120
diff --git a/liblog/include_vndk/log/log_event_list.h b/liblog/include_vndk/log/log_event_list.h
index cbd309174..9f74534be 100644
--- a/liblog/include_vndk/log/log_event_list.h
+++ b/liblog/include_vndk/log/log_event_list.h
@@ -63,6 +63,13 @@ int android_log_write_float32(android_log_context ctx, float value);
63/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */ 63/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
64int android_log_write_list(android_log_context ctx, log_id_t id); 64int android_log_write_list(android_log_context ctx, log_id_t id);
65 65
66/* Reset writer context */
67int android_log_reset(android_log_context ctx);
68
69/* Reset reader context */
70int android_log_parser_reset(android_log_context ctx,
71 const char* msg, size_t len);
72
66/* Finished with reader or writer context */ 73/* Finished with reader or writer context */
67int android_log_destroy(android_log_context* ctx); 74int android_log_destroy(android_log_context* ctx);
68 75
diff --git a/liblog/liblog.map.txt b/liblog/liblog.map.txt
index 66670fe28..015c9cbf9 100644
--- a/liblog/liblog.map.txt
+++ b/liblog/liblog.map.txt
@@ -53,3 +53,9 @@ LIBLOG_O {
53 __android_log_is_loggable_len; 53 __android_log_is_loggable_len;
54 __android_log_is_debuggable; # vndk 54 __android_log_is_debuggable; # vndk
55}; 55};
56
57LIBLOG_Q {
58 global:
59 android_log_reset; #vndk
60 android_log_parser_reset; #vndk
61};
diff --git a/liblog/log_event_list.c b/liblog/log_event_list.c
index a59cb8738..14002ceb5 100644
--- a/liblog/log_event_list.c
+++ b/liblog/log_event_list.c
@@ -45,14 +45,9 @@ typedef struct {
45 uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD]; 45 uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD];
46} android_log_context_internal; 46} android_log_context_internal;
47 47
48LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) { 48static void init_context(android_log_context_internal* context, uint32_t tag) {
49 size_t needed, i; 49 size_t needed;
50 android_log_context_internal* context;
51 50
52 context = calloc(1, sizeof(android_log_context_internal));
53 if (!context) {
54 return NULL;
55 }
56 context->tag = tag; 51 context->tag = tag;
57 context->read_write_flag = kAndroidLoggerWrite; 52 context->read_write_flag = kAndroidLoggerWrite;
58 needed = sizeof(uint8_t) + sizeof(uint8_t); 53 needed = sizeof(uint8_t) + sizeof(uint8_t);
@@ -63,6 +58,24 @@ LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
63 context->storage[context->pos + 0] = EVENT_TYPE_LIST; 58 context->storage[context->pos + 0] = EVENT_TYPE_LIST;
64 context->list[0] = context->pos + 1; 59 context->list[0] = context->pos + 1;
65 context->pos += needed; 60 context->pos += needed;
61}
62
63static void init_parser_context(android_log_context_internal* context,
64 const char* msg, size_t len) {
65 len = (len <= MAX_EVENT_PAYLOAD) ? len : MAX_EVENT_PAYLOAD;
66 context->len = len;
67 memcpy(context->storage, msg, len);
68 context->read_write_flag = kAndroidLoggerRead;
69}
70
71LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
72 android_log_context_internal* context;
73
74 context = calloc(1, sizeof(android_log_context_internal));
75 if (!context) {
76 return NULL;
77 }
78 init_context(context, tag);
66 79
67 return (android_log_context)context; 80 return (android_log_context)context;
68} 81}
@@ -76,10 +89,7 @@ LIBLOG_ABI_PUBLIC android_log_context create_android_log_parser(const char* msg,
76 if (!context) { 89 if (!context) {
77 return NULL; 90 return NULL;
78 } 91 }
79 len = (len <= MAX_EVENT_PAYLOAD) ? len : MAX_EVENT_PAYLOAD; 92 init_parser_context(context, msg, len);
80 context->len = len;
81 memcpy(context->storage, msg, len);
82 context->read_write_flag = kAndroidLoggerRead;
83 93
84 return (android_log_context)context; 94 return (android_log_context)context;
85} 95}
@@ -97,6 +107,38 @@ LIBLOG_ABI_PUBLIC int android_log_destroy(android_log_context* ctx) {
97 return 0; 107 return 0;
98} 108}
99 109
110LIBLOG_ABI_PUBLIC int android_log_reset(android_log_context ctx) {
111 android_log_context_internal* context;
112 uint32_t tag;
113
114 context = (android_log_context_internal*)ctx;
115 if (!context || (kAndroidLoggerWrite != context->read_write_flag)) {
116 return -EBADF;
117 }
118
119 tag = context->tag;
120 memset(context, 0, sizeof(*context));
121 init_context(context, tag);
122
123 return 0;
124}
125
126LIBLOG_ABI_PUBLIC int android_log_parser_reset(android_log_context ctx,
127 const char* msg, size_t len) {
128 android_log_context_internal* context;
129
130 context = (android_log_context_internal*)ctx;
131 if (!context || (kAndroidLoggerRead != context->read_write_flag)) {
132 return -EBADF;
133 }
134
135 memset(context, 0, sizeof(*context));
136 init_parser_context(context, msg, len);
137
138 return 0;
139}
140
141
100LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) { 142LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) {
101 size_t needed; 143 size_t needed;
102 android_log_context_internal* context; 144 android_log_context_internal* context;