From f8e546e6090002cde90c21c83b8cdef311e50816 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 30 Nov 2015 11:36:09 -0800 Subject: [PATCH] liblog: Support for ANDROID_LOG_WRAP mode flag on reader If ANDROID_LOG_WRAP is specified, add timeout=3600 to the reader request. logd will comply by going to sleep with the socket open. If the start time is about to wrap or get pruned in the specified log buffers, then wakeup and dump the logs; or wakeup on timeout, whichever comes first. Bug: 25929746 Change-Id: I531b4317a20abcf3ba87d78c68fa2f268a4488ab --- include/log/logger.h | 2 ++ liblog/README | 4 ++++ liblog/log_read.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/include/log/logger.h b/include/log/logger.h index ff70529fb7..b3928a7135 100644 --- a/include/log/logger.h +++ b/include/log/logger.h @@ -163,6 +163,8 @@ int android_logger_set_prune_list(struct logger_list *logger_list, #define ANDROID_LOG_RDWR O_RDWR #define ANDROID_LOG_ACCMODE O_ACCMODE #define ANDROID_LOG_NONBLOCK O_NONBLOCK +#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */ +#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */ #define ANDROID_LOG_PSTORE 0x80000000 struct logger_list *android_logger_list_alloc(int mode, diff --git a/liblog/README b/liblog/README index f29ac045b3..df1e68c653 100644 --- a/liblog/README +++ b/liblog/README @@ -116,6 +116,10 @@ DESCRIPTION code, otherwise the android_logger_list_read call will block for new entries. + The ANDROID_LOG_WRAP mode flag to the android_logger_list_alloc_time + signals logd to quiesce the reader until the buffer is about to prune + at the start time then proceed to dumping content. + The ANDROID_LOG_PSTORE mode flag to the android_logger_open is used to switch from the active logs to the persistent logs from before the last reboot. diff --git a/liblog/log_read.c b/liblog/log_read.c index cfc8a7aca9..fb8675779b 100644 --- a/liblog/log_read.c +++ b/liblog/log_read.c @@ -797,6 +797,14 @@ int android_logger_list_read(struct logger_list *logger_list, } if (logger_list->start.tv_sec || logger_list->start.tv_nsec) { + if (logger_list->mode & ANDROID_LOG_WRAP) { + // ToDo: alternate API to allow timeout to be adjusted. + ret = snprintf(cp, remaining, " timeout=%u", + ANDROID_LOG_WRAP_DEFAULT_TIMEOUT); + ret = min(ret, remaining); + remaining -= ret; + cp += ret; + } ret = snprintf(cp, remaining, " start=%" PRIu32 ".%09" PRIu32, logger_list->start.tv_sec, logger_list->start.tv_nsec); -- GitLab