logd: wait for timeout via CLOCK_MONOTONIC
There are well known issues with CLOCK_REALTIME jumping drastically.
Test: --wrap works successfully
Change-Id: I5676274783ac9aa9374d2b9254e0109d883cc5a8
diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp
index 9db8c00..d52d459 100644
--- a/logd/LogReader.cpp
+++ b/logd/LogReader.cpp
@@ -89,8 +89,7 @@
static const char _timeout[] = " timeout=";
cp = strstr(buffer, _timeout);
if (cp) {
- timeout = atol(cp + sizeof(_timeout) - 1) * NS_PER_SEC +
- log_time(CLOCK_REALTIME).nsec();
+ timeout = atol(cp + sizeof(_timeout) - 1) * NS_PER_SEC + log_time(CLOCK_MONOTONIC).nsec();
}
unsigned int logMask = -1;
diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp
index 208d67f..1723139 100644
--- a/logd/LogTimes.cpp
+++ b/logd/LogTimes.cpp
@@ -27,9 +27,9 @@
pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER;
-LogTimeEntry::LogTimeEntry(LogReader& reader, SocketClient* client,
- bool nonBlock, unsigned long tail, log_mask_t logMask,
- pid_t pid, log_time start, uint64_t timeout)
+LogTimeEntry::LogTimeEntry(LogReader& reader, SocketClient* client, bool nonBlock,
+ unsigned long tail, log_mask_t logMask, pid_t pid, log_time start,
+ uint64_t timeout)
: leadingDropped(false),
mReader(reader),
mLogMask(logMask),
@@ -39,8 +39,7 @@
mIndex(0),
mClient(client),
mStart(start),
- mNonBlock(nonBlock),
- mEnd(log_time(android_log_clockid())) {
+ mNonBlock(nonBlock) {
mTimeout.tv_sec = timeout / NS_PER_SEC;
mTimeout.tv_nsec = timeout % NS_PER_SEC;
memset(mLastTid, 0, sizeof(mLastTid));
@@ -85,8 +84,8 @@
while (!me->mRelease) {
if (me->mTimeout.tv_sec || me->mTimeout.tv_nsec) {
- if (pthread_cond_timedwait(&me->threadTriggeredCondition,
- ×Lock, &me->mTimeout) == ETIMEDOUT) {
+ if (pthread_cond_clockwait(&me->threadTriggeredCondition, ×Lock, CLOCK_MONOTONIC,
+ &me->mTimeout) == ETIMEDOUT) {
me->mTimeout.tv_sec = 0;
me->mTimeout.tv_nsec = 0;
}
diff --git a/logd/LogTimes.h b/logd/LogTimes.h
index 9f6f203..49b2d9d 100644
--- a/logd/LogTimes.h
+++ b/logd/LogTimes.h
@@ -56,9 +56,8 @@
SocketClient* mClient;
log_time mStart;
- struct timespec mTimeout;
+ struct timespec mTimeout; // CLOCK_MONOTONIC based timeout used for log wrapping.
const bool mNonBlock;
- const log_time mEnd; // only relevant if mNonBlock
// Protect List manipulations
static void wrlock(void) {