blob: f92fe65c8e424412151fc9a72bec9f8f36b302ba [file] [log] [blame]
Mark Salyzyn0175b072014-02-26 09:50:16 -08001/*
2 * Copyright (C) 2012-2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Tom Cherryd5b38382020-05-12 13:16:41 -070016// for manual checking of stale entries during ChattyLogBuffer::erase()
Mark Salyzyn60636fa2016-10-24 16:22:17 -070017//#define DEBUG_CHECK_FOR_STALE_ENTRIES
Mark Salyzyn0175b072014-02-26 09:50:16 -080018
Tom Cherryd5b38382020-05-12 13:16:41 -070019#include "ChattyLogBuffer.h"
20
Mark Salyzyn671e3432014-05-06 07:34:59 -070021#include <ctype.h>
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080022#include <endian.h>
Mark Salyzyn202e1532015-02-09 08:21:05 -080023#include <errno.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080024#include <stdio.h>
25#include <string.h>
Mark Salyzyn8fcfd852016-10-24 08:20:26 -070026#include <sys/cdefs.h>
Mark Salyzyn57a0af92014-05-09 17:44:18 -070027#include <sys/user.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080028#include <time.h>
29#include <unistd.h>
30
Tom Cherryb398a7c2020-05-20 12:09:22 -070031#include <limits>
Mark Salyzyn511338d2015-05-19 09:12:30 -070032#include <unordered_map>
Tom Cherry10d086e2019-08-21 14:16:34 -070033#include <utility>
Mark Salyzyn511338d2015-05-19 09:12:30 -070034
Mark Salyzynf10e2732016-09-27 13:08:23 -070035#include <private/android_logger.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080036
Mark Salyzyna2c02222016-12-13 10:31:29 -080037#include "LogUtils.h"
Mark Salyzyn0175b072014-02-26 09:50:16 -080038
Mark Salyzyn8fcfd852016-10-24 08:20:26 -070039#ifndef __predict_false
40#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
41#endif
42
Tom Cherryd5b38382020-05-12 13:16:41 -070043ChattyLogBuffer::ChattyLogBuffer(LogReaderList* reader_list, LogTags* tags, PruneList* prune,
44 LogStatistics* stats)
Tom Cherry8f613462020-05-12 12:46:43 -070045 : SimpleLogBuffer(reader_list, tags, stats), prune_(prune) {}
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070046
Tom Cherrya26f7df2020-05-19 17:48:42 -070047ChattyLogBuffer::~ChattyLogBuffer() {}
Mark Salyzyna2c02222016-12-13 10:31:29 -080048
Mark Salyzyn501c3732017-03-10 14:31:54 -080049enum match_type { DIFFERENT, SAME, SAME_LIBLOG };
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080050
Tom Cherry9787f9a2020-05-19 19:01:16 -070051static enum match_type Identical(const LogBufferElement& elem, const LogBufferElement& last) {
52 ssize_t lenl = elem.msg_len();
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070053 if (lenl <= 0) return DIFFERENT; // value if this represents a chatty elem
Tom Cherry9787f9a2020-05-19 19:01:16 -070054 ssize_t lenr = last.msg_len();
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070055 if (lenr <= 0) return DIFFERENT; // value if this represents a chatty elem
Tom Cherry9787f9a2020-05-19 19:01:16 -070056 if (elem.uid() != last.uid()) return DIFFERENT;
57 if (elem.pid() != last.pid()) return DIFFERENT;
58 if (elem.tid() != last.tid()) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080059
60 // last is more than a minute old, stop squashing identical messages
Tom Cherry9787f9a2020-05-19 19:01:16 -070061 if (elem.realtime().nsec() > (last.realtime().nsec() + 60 * NS_PER_SEC)) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080062
63 // Identical message
Tom Cherry9787f9a2020-05-19 19:01:16 -070064 const char* msgl = elem.msg();
65 const char* msgr = last.msg();
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080066 if (lenl == lenr) {
67 if (!fastcmp<memcmp>(msgl, msgr, lenl)) return SAME;
68 // liblog tagged messages (content gets summed)
Tom Cherry9787f9a2020-05-19 19:01:16 -070069 if (elem.log_id() == LOG_ID_EVENTS && lenl == sizeof(android_log_event_int_t) &&
Tom Cherryd5b38382020-05-12 13:16:41 -070070 !fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_int_t) - sizeof(int32_t)) &&
Tom Cherry9787f9a2020-05-19 19:01:16 -070071 elem.GetTag() == LIBLOG_LOG_TAG) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080072 return SAME_LIBLOG;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070073 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080074 }
Mark Salyzyna2c02222016-12-13 10:31:29 -080075
76 // audit message (except sequence number) identical?
Tom Cherry3dd3ec32020-06-02 15:39:21 -070077 if (IsBinary(last.log_id()) &&
78 lenl > static_cast<ssize_t>(sizeof(android_log_event_string_t)) &&
Tom Cherryd5b38382020-05-12 13:16:41 -070079 lenr > static_cast<ssize_t>(sizeof(android_log_event_string_t))) {
80 if (fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_string_t) - sizeof(int32_t))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080081 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070082 }
Mark Salyzyna2c02222016-12-13 10:31:29 -080083 msgl += sizeof(android_log_event_string_t);
84 lenl -= sizeof(android_log_event_string_t);
85 msgr += sizeof(android_log_event_string_t);
86 lenr -= sizeof(android_log_event_string_t);
87 }
Mark Salyzyn0484b3b2016-08-11 08:02:06 -070088 static const char avc[] = "): avc: ";
Mark Salyzyn501c3732017-03-10 14:31:54 -080089 const char* avcl = android::strnstr(msgl, lenl, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080090 if (!avcl) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080091 lenl -= avcl - msgl;
Mark Salyzyn501c3732017-03-10 14:31:54 -080092 const char* avcr = android::strnstr(msgr, lenr, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080093 if (!avcr) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -080094 lenr -= avcr - msgr;
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080095 if (lenl != lenr) return DIFFERENT;
Tom Cherryd5b38382020-05-12 13:16:41 -070096 if (fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc), lenl - strlen(avc))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -080097 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -070098 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080099 return SAME;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800100}
101
Tom Cherry8f613462020-05-12 12:46:43 -0700102void ChattyLogBuffer::LogInternal(LogBufferElement&& elem) {
Tom Cherrya26f7df2020-05-19 17:48:42 -0700103 // b/137093665: don't coalesce security messages.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700104 if (elem.log_id() == LOG_ID_SECURITY) {
Tom Cherry8f613462020-05-12 12:46:43 -0700105 SimpleLogBuffer::LogInternal(std::move(elem));
106 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700107 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700108 int log_id = elem.log_id();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700109
Tom Cherrya26f7df2020-05-19 17:48:42 -0700110 // Initialize last_logged_elements_ to a copy of elem if logging the first element for a log_id.
111 if (!last_logged_elements_[log_id]) {
Tom Cherry13224722020-05-19 18:02:00 -0700112 last_logged_elements_[log_id].emplace(elem);
Tom Cherry8f613462020-05-12 12:46:43 -0700113 SimpleLogBuffer::LogInternal(std::move(elem));
114 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700115 }
116
Tom Cherry13224722020-05-19 18:02:00 -0700117 LogBufferElement& current_last = *last_logged_elements_[log_id];
Tom Cherry9787f9a2020-05-19 19:01:16 -0700118 enum match_type match = Identical(elem, current_last);
Tom Cherrya26f7df2020-05-19 17:48:42 -0700119
120 if (match == DIFFERENT) {
121 if (duplicate_elements_[log_id]) {
Tom Cherrya26f7df2020-05-19 17:48:42 -0700122 // If we previously had 3+ identical messages, log the chatty message.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700123 if (duplicate_elements_[log_id]->dropped_count() > 0) {
Tom Cherry8f613462020-05-12 12:46:43 -0700124 SimpleLogBuffer::LogInternal(std::move(*duplicate_elements_[log_id]));
Mark Salyzyna2c02222016-12-13 10:31:29 -0800125 }
Tom Cherry13224722020-05-19 18:02:00 -0700126 duplicate_elements_[log_id].reset();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700127 // Log the saved copy of the last identical message seen.
Tom Cherry8f613462020-05-12 12:46:43 -0700128 SimpleLogBuffer::LogInternal(std::move(current_last));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700129 }
Tom Cherry13224722020-05-19 18:02:00 -0700130 last_logged_elements_[log_id].emplace(elem);
Tom Cherry8f613462020-05-12 12:46:43 -0700131 SimpleLogBuffer::LogInternal(std::move(elem));
132 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700133 }
134
135 // 2 identical message: set duplicate_elements_ appropriately.
136 if (!duplicate_elements_[log_id]) {
Tom Cherry13224722020-05-19 18:02:00 -0700137 duplicate_elements_[log_id].emplace(std::move(current_last));
138 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700139 return;
Tom Cherrya26f7df2020-05-19 17:48:42 -0700140 }
141
142 // 3+ identical LIBLOG event messages: coalesce them into last_logged_elements_.
143 if (match == SAME_LIBLOG) {
144 const android_log_event_int_t* current_last_event =
Tom Cherry9787f9a2020-05-19 19:01:16 -0700145 reinterpret_cast<const android_log_event_int_t*>(current_last.msg());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700146 int64_t current_last_count = current_last_event->payload.data;
147 android_log_event_int_t* elem_event =
Tom Cherry9787f9a2020-05-19 19:01:16 -0700148 reinterpret_cast<android_log_event_int_t*>(const_cast<char*>(elem.msg()));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700149 int64_t elem_count = elem_event->payload.data;
150
151 int64_t total = current_last_count + elem_count;
152 if (total > std::numeric_limits<int32_t>::max()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700153 SimpleLogBuffer::LogInternal(std::move(current_last));
Tom Cherry13224722020-05-19 18:02:00 -0700154 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700155 return;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800156 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700157 stats()->AddTotal(current_last.log_id(), current_last.msg_len());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700158 elem_event->payload.data = total;
Tom Cherry13224722020-05-19 18:02:00 -0700159 last_logged_elements_[log_id].emplace(std::move(elem));
Tom Cherry8f613462020-05-12 12:46:43 -0700160 return;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800161 }
Mark Salyzyn0175b072014-02-26 09:50:16 -0800162
Tom Cherrya26f7df2020-05-19 17:48:42 -0700163 // 3+ identical messages (not LIBLOG) messages: increase the drop count.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700164 uint16_t dropped_count = duplicate_elements_[log_id]->dropped_count();
Tom Cherrya26f7df2020-05-19 17:48:42 -0700165 if (dropped_count == std::numeric_limits<uint16_t>::max()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700166 SimpleLogBuffer::LogInternal(std::move(*duplicate_elements_[log_id]));
Tom Cherrya26f7df2020-05-19 17:48:42 -0700167 dropped_count = 0;
168 }
169 // We're dropping the current_last log so add its stats to the total.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700170 stats()->AddTotal(current_last.log_id(), current_last.msg_len());
Tom Cherrya26f7df2020-05-19 17:48:42 -0700171 // Use current_last for tracking the dropped count to always use the latest timestamp.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700172 current_last.SetDropped(dropped_count + 1);
Tom Cherry13224722020-05-19 18:02:00 -0700173 duplicate_elements_[log_id].emplace(std::move(current_last));
174 last_logged_elements_[log_id].emplace(std::move(elem));
Mark Salyzyna2c02222016-12-13 10:31:29 -0800175}
176
Tom Cherry8f613462020-05-12 12:46:43 -0700177LogBufferElementCollection::iterator ChattyLogBuffer::Erase(LogBufferElementCollection::iterator it,
Tom Cherryd5b38382020-05-12 13:16:41 -0700178 bool coalesce) {
Tom Cherry13224722020-05-19 18:02:00 -0700179 LogBufferElement& element = *it;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700180 log_id_t id = element.log_id();
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700181
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700182 // Remove iterator references in the various lists that will become stale
183 // after the element is erased from the main logging list.
184
Mark Salyzyn501c3732017-03-10 14:31:54 -0800185 { // start of scope for found iterator
Tom Cherry9787f9a2020-05-19 19:01:16 -0700186 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element.GetTag() : element.uid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700187 LogBufferIteratorMap::iterator found = mLastWorst[id].find(key);
188 if ((found != mLastWorst[id].end()) && (it == found->second)) {
189 mLastWorst[id].erase(found);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700190 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700191 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700192
Mark Salyzyn501c3732017-03-10 14:31:54 -0800193 { // start of scope for pid found iterator
Tom Cherry9787f9a2020-05-19 19:01:16 -0700194 // element->uid() may not be AID_SYSTEM for next-best-watermark.
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700195 // will not assume id != LOG_ID_EVENTS or LOG_ID_SECURITY for KISS and
196 // long term code stability, find() check should be fast for those ids.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700197 LogBufferPidIteratorMap::iterator found = mLastWorstPidOfSystem[id].find(element.pid());
Tom Cherryd5b38382020-05-12 13:16:41 -0700198 if (found != mLastWorstPidOfSystem[id].end() && it == found->second) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700199 mLastWorstPidOfSystem[id].erase(found);
200 }
201 }
202
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700203#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
204 LogBufferElementCollection::iterator bad = it;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700205 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element->GetTag() : element->uid();
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700206#endif
Tom Cherry13224722020-05-19 18:02:00 -0700207
208 if (coalesce) {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700209 stats()->Erase(element.ToLogStatisticsElement());
Tom Cherry13224722020-05-19 18:02:00 -0700210 } else {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700211 stats()->Subtract(element.ToLogStatisticsElement());
Tom Cherry13224722020-05-19 18:02:00 -0700212 }
213
Tom Cherry8f613462020-05-12 12:46:43 -0700214 it = SimpleLogBuffer::Erase(it);
Tom Cherry13224722020-05-19 18:02:00 -0700215
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700216#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
217 log_id_for_each(i) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800218 for (auto b : mLastWorst[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700219 if (bad == b.second) {
Tom Cherryf93b4002020-06-03 09:23:49 -0700220 LOG(ERROR) << StringPrintf("stale mLastWorst[%d] key=%d mykey=%d", i, b.first, key);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700221 }
222 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800223 for (auto b : mLastWorstPidOfSystem[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700224 if (bad == b.second) {
Tom Cherryf93b4002020-06-03 09:23:49 -0700225 LOG(ERROR) << StringPrintf("stale mLastWorstPidOfSystem[%d] pid=%d", i, b.first);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700226 }
227 }
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700228 }
229#endif
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700230 return it;
231}
232
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700233// Define a temporary mechanism to report the last LogBufferElement pointer
234// for the specified uid, pid and tid. Used below to help merge-sort when
235// pruning for worst UID.
Mark Salyzyn511338d2015-05-19 09:12:30 -0700236class LogBufferElementLast {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800237 typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap;
Mark Salyzyn511338d2015-05-19 09:12:30 -0700238 LogBufferElementMap map;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700239
Tom Cherryd5b38382020-05-12 13:16:41 -0700240 public:
Chih-Hung Hsieh08d470b2018-08-13 14:22:56 -0700241 bool coalesce(LogBufferElement* element, uint16_t dropped) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700242 uint64_t key = LogBufferElementKey(element->uid(), element->pid(), element->tid());
Tom Cherrya5151972020-05-15 11:39:58 -0700243 LogBufferElementMap::iterator it = map.find(key);
Mark Salyzyn511338d2015-05-19 09:12:30 -0700244 if (it != map.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800245 LogBufferElement* found = it->second;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700246 uint16_t moreDropped = found->dropped_count();
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700247 if ((dropped + moreDropped) > USHRT_MAX) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700248 map.erase(it);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700249 } else {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700250 found->SetDropped(dropped + moreDropped);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700251 return true;
252 }
253 }
254 return false;
255 }
256
Mark Salyzyn501c3732017-03-10 14:31:54 -0800257 void add(LogBufferElement* element) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700258 uint64_t key = LogBufferElementKey(element->uid(), element->pid(), element->tid());
Tom Cherrya5151972020-05-15 11:39:58 -0700259 map[key] = element;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700260 }
261
Tom Cherryd5b38382020-05-12 13:16:41 -0700262 void clear() { map.clear(); }
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700263
Mark Salyzyn501c3732017-03-10 14:31:54 -0800264 void clear(LogBufferElement* element) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700265 uint64_t current = element->realtime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC);
Mark Salyzyn501c3732017-03-10 14:31:54 -0800266 for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) {
267 LogBufferElement* mapElement = it->second;
Tom Cherry9787f9a2020-05-19 19:01:16 -0700268 if (mapElement->dropped_count() >= EXPIRE_THRESHOLD &&
269 current > mapElement->realtime().nsec()) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700270 it = map.erase(it);
271 } else {
272 ++it;
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700273 }
274 }
275 }
Tom Cherrya5151972020-05-15 11:39:58 -0700276
277 private:
278 uint64_t LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid) {
279 return uint64_t(uid) << 32 | uint64_t(pid) << 16 | uint64_t(tid);
280 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700281};
282
Mark Salyzyn0175b072014-02-26 09:50:16 -0800283// prune "pruneRows" of type "id" from the buffer.
284//
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700285// This garbage collection task is used to expire log entries. It is called to
286// remove all logs (clear), all UID logs (unprivileged clear), or every
287// 256 or 10% of the total logs (whichever is less) to prune the logs.
288//
289// First there is a prep phase where we discover the reader region lock that
290// acts as a backstop to any pruning activity to stop there and go no further.
291//
292// There are three major pruning loops that follow. All expire from the oldest
293// entries. Since there are multiple log buffers, the Android logging facility
294// will appear to drop entries 'in the middle' when looking at multiple log
295// sources and buffers. This effect is slightly more prominent when we prune
296// the worst offender by logging source. Thus the logs slowly loose content
297// and value as you move back in time. This is preferred since chatty sources
298// invariably move the logs value down faster as less chatty sources would be
299// expired in the noise.
300//
301// The first loop performs blacklisting and worst offender pruning. Falling
302// through when there are no notable worst offenders and have not hit the
303// region lock preventing further worst offender pruning. This loop also looks
304// after managing the chatty log entries and merging to help provide
305// statistical basis for blame. The chatty entries are not a notification of
306// how much logs you may have, but instead represent how much logs you would
307// have had in a virtual log buffer that is extended to cover all the in-memory
308// logs without loss. They last much longer than the represented pruned logs
309// since they get multiplied by the gains in the non-chatty log sources.
310//
311// The second loop get complicated because an algorithm of watermarks and
312// history is maintained to reduce the order and keep processing time
313// down to a minimum at scale. These algorithms can be costly in the face
314// of larger log buffers, or severly limited processing time granted to a
315// background task at lowest priority.
316//
317// This second loop does straight-up expiration from the end of the logs
318// (again, remember for the specified log buffer id) but does some whitelist
319// preservation. Thus whitelist is a Hail Mary low priority, blacklists and
320// spam filtration all take priority. This second loop also checks if a region
321// lock is causing us to buffer too much in the logs to help the reader(s),
322// and will tell the slowest reader thread to skip log entries, and if
323// persistent and hits a further threshold, kill the reader thread.
324//
325// The third thread is optional, and only gets hit if there was a whitelist
326// and more needs to be pruned against the backstop of the region lock.
327//
Tom Cherry8f613462020-05-12 12:46:43 -0700328bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
Tom Cherry6ec71e92020-05-04 12:53:36 -0700329 LogReaderThread* oldest = nullptr;
Mark Salyzync5dc9702015-09-16 15:34:00 -0700330 bool busy = false;
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700331 bool clearAll = pruneRows == ULONG_MAX;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800332
Tom Cherry8f613462020-05-12 12:46:43 -0700333 auto reader_threads_lock = std::lock_guard{reader_list()->reader_threads_lock()};
Mark Salyzyn0175b072014-02-26 09:50:16 -0800334
335 // Region locked?
Tom Cherry8f613462020-05-12 12:46:43 -0700336 for (const auto& reader_thread : reader_list()->reader_threads()) {
Tom Cherry68630a02020-05-11 16:29:29 -0700337 if (!reader_thread->IsWatching(id)) {
338 continue;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800339 }
Tom Cherry68630a02020-05-11 16:29:29 -0700340 if (!oldest || oldest->start() > reader_thread->start() ||
341 (oldest->start() == reader_thread->start() &&
342 reader_thread->deadline().time_since_epoch().count() != 0)) {
343 oldest = reader_thread.get();
344 }
Mark Salyzyn0175b072014-02-26 09:50:16 -0800345 }
346
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800347 LogBufferElementCollection::iterator it;
348
Mark Salyzyn501c3732017-03-10 14:31:54 -0800349 if (__predict_false(caller_uid != AID_ROOT)) { // unlikely
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700350 // Only here if clear all request from non system source, so chatty
351 // filter logistics is not required.
Tom Cherry385c2c92020-04-29 17:58:18 -0700352 it = GetOldest(id);
Tom Cherry8f613462020-05-12 12:46:43 -0700353 while (it != logs().end()) {
Tom Cherry13224722020-05-19 18:02:00 -0700354 LogBufferElement& element = *it;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700355
Tom Cherry9787f9a2020-05-19 19:01:16 -0700356 if (element.log_id() != id || element.uid() != caller_uid) {
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700357 ++it;
358 continue;
359 }
360
Tom Cherry9787f9a2020-05-19 19:01:16 -0700361 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry5e266552020-04-08 10:47:26 -0700362 busy = true;
Tom Cherry8f613462020-05-12 12:46:43 -0700363 KickReader(oldest, id, pruneRows);
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700364 break;
365 }
366
Tom Cherry8f613462020-05-12 12:46:43 -0700367 it = Erase(it);
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700368 if (--pruneRows == 0) {
369 break;
370 }
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700371 }
Mark Salyzync5dc9702015-09-16 15:34:00 -0700372 return busy;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700373 }
374
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700375 // prune by worst offenders; by blacklist, UID, and by PID of system UID
Tom Cherry5a3db392020-05-01 17:03:20 -0700376 bool hasBlacklist = (id != LOG_ID_SECURITY) && prune_->naughty();
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700377 while (!clearAll && (pruneRows > 0)) {
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800378 // recalculate the worst offender on every batched pass
Tom Cherry9787f9a2020-05-19 19:01:16 -0700379 int worst = -1; // not valid for uid() or getKey()
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800380 size_t worst_sizes = 0;
381 size_t second_worst_sizes = 0;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800382 pid_t worstPid = 0; // POSIX guarantees PID != 0
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800383
Tom Cherry5a3db392020-05-01 17:03:20 -0700384 if (worstUidEnabledForLogid(id) && prune_->worstUidEnabled()) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700385 // Calculate threshold as 12.5% of available storage
Tom Cherry8f613462020-05-12 12:46:43 -0700386 size_t threshold = max_size(id) / 8;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700387
Tom Cherryb6b78e92020-05-07 09:13:12 -0700388 if (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) {
Tom Cherry8f613462020-05-12 12:46:43 -0700389 stats()->WorstTwoTags(threshold, &worst, &worst_sizes, &second_worst_sizes);
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700390 // per-pid filter for AID_SYSTEM sources is too complex
Mark Salyzyn6a066942016-07-14 15:34:30 -0700391 } else {
Tom Cherry8f613462020-05-12 12:46:43 -0700392 stats()->WorstTwoUids(id, threshold, &worst, &worst_sizes, &second_worst_sizes);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700393
Tom Cherryb6b78e92020-05-07 09:13:12 -0700394 if (worst == AID_SYSTEM && prune_->worstPidOfSystemEnabled()) {
Tom Cherry8f613462020-05-12 12:46:43 -0700395 stats()->WorstTwoSystemPids(id, worst_sizes, &worstPid, &second_worst_sizes);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700396 }
397 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800398 }
399
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700400 // skip if we have neither worst nor naughty filters
Mark Salyzyn6a066942016-07-14 15:34:30 -0700401 if ((worst == -1) && !hasBlacklist) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700402 break;
403 }
404
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800405 bool kick = false;
Tom Cherry385c2c92020-04-29 17:58:18 -0700406 bool leading = true; // true if starting from the oldest log entry, false if starting from
407 // a specific chatty entry.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700408 // Perform at least one mandatory garbage collection cycle in following
409 // - clear leading chatty tags
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700410 // - coalesce chatty tags
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700411 // - check age-out of preserved logs
412 bool gc = pruneRows <= 1;
Mark Salyzyn6a066942016-07-14 15:34:30 -0700413 if (!gc && (worst != -1)) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800414 { // begin scope for worst found iterator
Tom Cherryd5b38382020-05-12 13:16:41 -0700415 LogBufferIteratorMap::iterator found = mLastWorst[id].find(worst);
Tom Cherry8f613462020-05-12 12:46:43 -0700416 if (found != mLastWorst[id].end() && found->second != logs().end()) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700417 leading = false;
418 it = found->second;
419 }
420 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800421 if (worstPid) { // begin scope for pid worst found iterator
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700422 // FYI: worstPid only set if !LOG_ID_EVENTS and
423 // !LOG_ID_SECURITY, not going to make that assumption ...
Tom Cherryd5b38382020-05-12 13:16:41 -0700424 LogBufferPidIteratorMap::iterator found = mLastWorstPidOfSystem[id].find(worstPid);
Tom Cherry8f613462020-05-12 12:46:43 -0700425 if (found != mLastWorstPidOfSystem[id].end() && found->second != logs().end()) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700426 leading = false;
427 it = found->second;
428 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700429 }
430 }
Tom Cherry385c2c92020-04-29 17:58:18 -0700431 if (leading) {
432 it = GetOldest(id);
433 }
Tom Cherrybd80e562020-05-18 08:58:50 -0700434 static const log_time too_old{EXPIRE_HOUR_THRESHOLD * 60 * 60, 0};
Mark Salyzynccfe8442015-08-24 13:43:27 -0700435 LogBufferElementCollection::iterator lastt;
Tom Cherry8f613462020-05-12 12:46:43 -0700436 lastt = logs().end();
Mark Salyzynccfe8442015-08-24 13:43:27 -0700437 --lastt;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700438 LogBufferElementLast last;
Tom Cherry8f613462020-05-12 12:46:43 -0700439 while (it != logs().end()) {
Tom Cherry13224722020-05-19 18:02:00 -0700440 LogBufferElement& element = *it;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800441
Tom Cherry9787f9a2020-05-19 19:01:16 -0700442 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry5e266552020-04-08 10:47:26 -0700443 busy = true;
Mark Salyzyn0878a7c2017-05-11 13:28:33 -0700444 // Do not let chatty eliding trigger any reader mitigation
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800445 break;
446 }
447
Tom Cherry9787f9a2020-05-19 19:01:16 -0700448 if (element.log_id() != id) {
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800449 ++it;
450 continue;
451 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700452 // below this point element->log_id() == id
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800453
Tom Cherry9787f9a2020-05-19 19:01:16 -0700454 uint16_t dropped = element.dropped_count();
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800455
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700456 // remove any leading drops
457 if (leading && dropped) {
Tom Cherry8f613462020-05-12 12:46:43 -0700458 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700459 continue;
460 }
461
Tom Cherry13224722020-05-19 18:02:00 -0700462 if (dropped && last.coalesce(&element, dropped)) {
Tom Cherry8f613462020-05-12 12:46:43 -0700463 it = Erase(it, true);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700464 continue;
465 }
466
Tom Cherry9787f9a2020-05-19 19:01:16 -0700467 int key = (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) ? element.GetTag()
468 : element.uid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700469
Tom Cherry13224722020-05-19 18:02:00 -0700470 if (hasBlacklist && prune_->naughty(&element)) {
471 last.clear(&element);
Tom Cherry8f613462020-05-12 12:46:43 -0700472 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700473 if (dropped) {
474 continue;
475 }
476
477 pruneRows--;
478 if (pruneRows == 0) {
479 break;
480 }
481
Mark Salyzyn6a066942016-07-14 15:34:30 -0700482 if (key == worst) {
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700483 kick = true;
484 if (worst_sizes < second_worst_sizes) {
485 break;
486 }
Tom Cherry9787f9a2020-05-19 19:01:16 -0700487 worst_sizes -= element.msg_len();
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700488 }
489 continue;
490 }
491
Tom Cherry9787f9a2020-05-19 19:01:16 -0700492 if (element.realtime() < (lastt->realtime() - too_old) ||
493 element.realtime() > lastt->realtime()) {
Mark Salyzynccfe8442015-08-24 13:43:27 -0700494 break;
495 }
496
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700497 if (dropped) {
Tom Cherry13224722020-05-19 18:02:00 -0700498 last.add(&element);
Tom Cherry9787f9a2020-05-19 19:01:16 -0700499 if (worstPid && ((!gc && element.pid() == worstPid) ||
500 mLastWorstPidOfSystem[id].find(element.pid()) ==
Tom Cherryd5b38382020-05-12 13:16:41 -0700501 mLastWorstPidOfSystem[id].end())) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700502 // element->uid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700503 // watermark if current one empty. id is not LOG_ID_EVENTS
504 // or LOG_ID_SECURITY because of worstPid check.
Tom Cherry9787f9a2020-05-19 19:01:16 -0700505 mLastWorstPidOfSystem[id][element.pid()] = it;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700506 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800507 if ((!gc && !worstPid && (key == worst)) ||
508 (mLastWorst[id].find(key) == mLastWorst[id].end())) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700509 mLastWorst[id][key] = it;
Mark Salyzyn49afe0d2015-08-24 13:43:27 -0700510 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800511 ++it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700512 continue;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800513 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700514
Tom Cherry9787f9a2020-05-19 19:01:16 -0700515 if (key != worst || (worstPid && element.pid() != worstPid)) {
Mark Salyzyn59212762015-06-01 09:41:19 -0700516 leading = false;
Tom Cherry13224722020-05-19 18:02:00 -0700517 last.clear(&element);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700518 ++it;
519 continue;
520 }
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700521 // key == worst below here
Tom Cherry9787f9a2020-05-19 19:01:16 -0700522 // If worstPid set, then element->pid() == worstPid below here
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700523
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700524 pruneRows--;
525 if (pruneRows == 0) {
526 break;
527 }
528
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700529 kick = true;
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700530
Tom Cherry9787f9a2020-05-19 19:01:16 -0700531 uint16_t len = element.msg_len();
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700532
533 // do not create any leading drops
534 if (leading) {
Tom Cherry8f613462020-05-12 12:46:43 -0700535 it = Erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700536 } else {
Tom Cherry3dd3ec32020-06-02 15:39:21 -0700537 stats()->Drop(element.ToLogStatisticsElement());
Tom Cherry9787f9a2020-05-19 19:01:16 -0700538 element.SetDropped(1);
Tom Cherry13224722020-05-19 18:02:00 -0700539 if (last.coalesce(&element, 1)) {
Tom Cherry8f613462020-05-12 12:46:43 -0700540 it = Erase(it, true);
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700541 } else {
Tom Cherry13224722020-05-19 18:02:00 -0700542 last.add(&element);
Tom Cherryd5b38382020-05-12 13:16:41 -0700543 if (worstPid && (!gc || mLastWorstPidOfSystem[id].find(worstPid) ==
544 mLastWorstPidOfSystem[id].end())) {
Tom Cherry9787f9a2020-05-19 19:01:16 -0700545 // element->uid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700546 // watermark if current one empty. id is not
547 // LOG_ID_EVENTS or LOG_ID_SECURITY because of worstPid.
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700548 mLastWorstPidOfSystem[id][worstPid] = it;
549 }
Tom Cherryd5b38382020-05-12 13:16:41 -0700550 if ((!gc && !worstPid) || mLastWorst[id].find(worst) == mLastWorst[id].end()) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700551 mLastWorst[id][worst] = it;
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700552 }
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700553 ++it;
554 }
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700555 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700556 if (worst_sizes < second_worst_sizes) {
557 break;
558 }
559 worst_sizes -= len;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800560 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700561 last.clear();
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800562
Tom Cherry5a3db392020-05-01 17:03:20 -0700563 if (!kick || !prune_->worstUidEnabled()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800564 break; // the following loop will ask bad clients to skip/drop
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800565 }
566 }
567
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800568 bool whitelist = false;
Tom Cherry5a3db392020-05-01 17:03:20 -0700569 bool hasWhitelist = (id != LOG_ID_SECURITY) && prune_->nice() && !clearAll;
Tom Cherry385c2c92020-04-29 17:58:18 -0700570 it = GetOldest(id);
Tom Cherry8f613462020-05-12 12:46:43 -0700571 while ((pruneRows > 0) && (it != logs().end())) {
Tom Cherry13224722020-05-19 18:02:00 -0700572 LogBufferElement& element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700573
Tom Cherry9787f9a2020-05-19 19:01:16 -0700574 if (element.log_id() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700575 it++;
576 continue;
577 }
578
Tom Cherry9787f9a2020-05-19 19:01:16 -0700579 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry5e266552020-04-08 10:47:26 -0700580 busy = true;
Tom Cherry8f613462020-05-12 12:46:43 -0700581 if (!whitelist) KickReader(oldest, id, pruneRows);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700582 break;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800583 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700584
Tom Cherry9787f9a2020-05-19 19:01:16 -0700585 if (hasWhitelist && !element.dropped_count() && prune_->nice(&element)) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700586 // WhiteListed
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700587 whitelist = true;
588 it++;
589 continue;
590 }
591
Tom Cherry8f613462020-05-12 12:46:43 -0700592 it = Erase(it);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700593 pruneRows--;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800594 }
595
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700596 // Do not save the whitelist if we are reader range limited
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800597 if (whitelist && (pruneRows > 0)) {
Tom Cherry385c2c92020-04-29 17:58:18 -0700598 it = GetOldest(id);
Tom Cherry8f613462020-05-12 12:46:43 -0700599 while ((it != logs().end()) && (pruneRows > 0)) {
Tom Cherry13224722020-05-19 18:02:00 -0700600 LogBufferElement& element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700601
Tom Cherry9787f9a2020-05-19 19:01:16 -0700602 if (element.log_id() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700603 ++it;
604 continue;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800605 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700606
Tom Cherry9787f9a2020-05-19 19:01:16 -0700607 if (oldest && oldest->start() <= element.sequence()) {
Tom Cherry5e266552020-04-08 10:47:26 -0700608 busy = true;
Tom Cherry8f613462020-05-12 12:46:43 -0700609 KickReader(oldest, id, pruneRows);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700610 break;
611 }
612
Tom Cherry8f613462020-05-12 12:46:43 -0700613 it = Erase(it);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700614 pruneRows--;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800615 }
616 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800617
Mark Salyzync5dc9702015-09-16 15:34:00 -0700618 return (pruneRows > 0) && busy;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800619}