From 4b104db121f8d85efd21487b983b1ddda052d1aa Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Thu, 8 Dec 2022 16:43:42 +0100 Subject: [PATCH] dlog_logger: extract a static var to a struct Change-Id: Ib9b254d2a679833659c558572cc6516030a6548c Signed-off-by: Michal Bloch --- src/logger/reader_logger.c | 11 ++++------- src/logger/reader_logger.h | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/logger/reader_logger.c b/src/logger/reader_logger.c index b5ebc8c..e11f8f5 100644 --- a/src/logger/reader_logger.c +++ b/src/logger/reader_logger.c @@ -20,11 +20,7 @@ static int service_reader_logger(struct reader_common *_reader, struct now_t tim { struct reader_logger *const reader = (struct reader_logger *) _reader; assert(reader); - - struct dlogutil_entry_with_msg entry; - static char buffer[sizeof entry + 1]; - buffer[sizeof buffer - 1] = '\0'; - struct android_logger_entry *const ale = (struct android_logger_entry *) buffer; + struct android_logger_entry *const ale = (struct android_logger_entry *) reader->read_buffer; /* The devices for the Android Logger only return one log per read(). * So using an 'if' here would be wasteful and, more importantly, too slow in the case where other logs come in. @@ -35,7 +31,7 @@ static int service_reader_logger(struct reader_common *_reader, struct now_t tim * starvation under heavy load. */ int max_loop_iterations = g_backend.logger_device_throttling[reader->buf_id]; while (max_loop_iterations--) { - int r = TEMP_FAILURE_RETRY(read(reader->common.fd_entity_source.fd, buffer, sizeof buffer - 1)); + int r = TEMP_FAILURE_RETRY(read(reader->common.fd_entity_source.fd, reader->read_buffer, sizeof reader->read_buffer - 1)); if (r == 0) break; else if (r == -1) { @@ -67,8 +63,9 @@ static int service_reader_logger(struct reader_common *_reader, struct now_t tim continue; } } + reader->read_buffer[r] = '\0'; - buffer[r] = '\0'; + struct dlogutil_entry_with_msg entry; parse_androidlogger_message(ale, &entry.header, r); add_recv_timestamp(&entry.header, time); diff --git a/src/logger/reader_logger.h b/src/logger/reader_logger.h index eb1e682..14933b9 100644 --- a/src/logger/reader_logger.h +++ b/src/logger/reader_logger.h @@ -8,6 +8,10 @@ struct reader_logger { struct reader_common common; log_id_t buf_id; int skip_count; + + /* This should probably be sizeof raw Android Logger entry + * as opposed to the processed dlogutil entry (with msg). */ + char read_buffer[sizeof (struct dlogutil_entry_with_msg) + sizeof '\0']; }; int reader_logger_init(struct reader_logger **reader, log_id_t buf_id, struct logger *server, bool skip); -- 2.7.4