Merge "logd: remove start filtration from flushTo (part deux)" am: 2623b6c55a

am: b8f2089d91

Change-Id: I3cb14b19aaf7180e5721b5178f17e87823418706
This commit is contained in:
Mark Salyzyn 2017-05-19 17:03:15 +00:00 committed by android-build-merger
commit fa685b1638

View file

@ -79,10 +79,16 @@ void LogBuffer::init() {
if (monotonic) { if (monotonic) {
if (!android::isMonotonic(e->mRealTime)) { if (!android::isMonotonic(e->mRealTime)) {
LogKlog::convertRealToMonotonic(e->mRealTime); LogKlog::convertRealToMonotonic(e->mRealTime);
if ((e->mRealTime.tv_nsec % 1000) == 0) {
e->mRealTime.tv_nsec++;
}
} }
} else { } else {
if (android::isMonotonic(e->mRealTime)) { if (android::isMonotonic(e->mRealTime)) {
LogKlog::convertMonotonicToReal(e->mRealTime); LogKlog::convertMonotonicToReal(e->mRealTime);
if ((e->mRealTime.tv_nsec % 1000) == 0) {
e->mRealTime.tv_nsec++;
}
} }
} }
++it; ++it;
@ -194,6 +200,11 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
return -EINVAL; return -EINVAL;
} }
// Slip the time by 1 nsec if the incoming lands on xxxxxx000 ns.
// This prevents any chance that an outside source can request an
// exact entry with time specified in ms or us precision.
if ((realtime.tv_nsec % 1000) == 0) ++realtime.tv_nsec;
LogBufferElement* elem = LogBufferElement* elem =
new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len); new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len);
if (log_id != LOG_ID_SECURITY) { if (log_id != LOG_ID_SECURITY) {
@ -1109,6 +1120,9 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
LogBufferElement* element = *it; LogBufferElement* element = *it;
if (element->getRealTime() > start) { if (element->getRealTime() > start) {
last = it; last = it;
} else if (element->getRealTime() == start) {
last = ++it;
break;
} else if (!--count || (element->getRealTime() < min)) { } else if (!--count || (element->getRealTime() < min)) {
break; break;
} }
@ -1116,7 +1130,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
it = last; it = last;
} }
log_time max = start; log_time curr = start;
LogBufferElement* lastElement = nullptr; // iterator corruption paranoia LogBufferElement* lastElement = nullptr; // iterator corruption paranoia
static const size_t maxSkip = 4194304; // maximum entries to skip static const size_t maxSkip = 4194304; // maximum entries to skip
@ -1142,10 +1156,6 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
continue; continue;
} }
if (element->getRealTime() <= start) {
continue;
}
// NB: calling out to another object with wrlock() held (safe) // NB: calling out to another object with wrlock() held (safe)
if (filter) { if (filter) {
int ret = (*filter)(element, arg); int ret = (*filter)(element, arg);
@ -1172,10 +1182,10 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
unlock(); unlock();
// range locking in LastLogTimes looks after us // range locking in LastLogTimes looks after us
max = element->flushTo(reader, this, privileged, sameTid); curr = element->flushTo(reader, this, privileged, sameTid);
if (max == element->FLUSH_ERROR) { if (curr == element->FLUSH_ERROR) {
return max; return curr;
} }
skip = maxSkip; skip = maxSkip;
@ -1183,7 +1193,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
} }
unlock(); unlock();
return max; return curr;
} }
std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid,