blob: 60d647d77d8061760738d9c28db475b4b17c5c4e [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 */
Mark Salyzyn60636fa2016-10-24 16:22:17 -070016// for manual checking of stale entries during LogBuffer::erase()
17//#define DEBUG_CHECK_FOR_STALE_ENTRIES
Mark Salyzyn0175b072014-02-26 09:50:16 -080018
Mark Salyzyn671e3432014-05-06 07:34:59 -070019#include <ctype.h>
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -080020#include <endian.h>
Mark Salyzyn202e1532015-02-09 08:21:05 -080021#include <errno.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080022#include <stdio.h>
23#include <string.h>
Mark Salyzyn8fcfd852016-10-24 08:20:26 -070024#include <sys/cdefs.h>
Mark Salyzyn57a0af92014-05-09 17:44:18 -070025#include <sys/user.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080026#include <time.h>
27#include <unistd.h>
28
Mark Salyzyn511338d2015-05-19 09:12:30 -070029#include <unordered_map>
30
Mark Salyzyn671e3432014-05-06 07:34:59 -070031#include <cutils/properties.h>
Mark Salyzynf10e2732016-09-27 13:08:23 -070032#include <private/android_logger.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080033
34#include "LogBuffer.h"
Mark Salyzynb6bee332015-09-08 08:56:32 -070035#include "LogKlog.h"
Mark Salyzyn671e3432014-05-06 07:34:59 -070036#include "LogReader.h"
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
Mark Salyzyndfa7a072014-02-11 12:29:31 -080043// Default
Mark Salyzyndfa7a072014-02-11 12:29:31 -080044#define log_buffer_size(id) mMaxSize[id]
Mark Salyzyn671e3432014-05-06 07:34:59 -070045
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070046void LogBuffer::init() {
Mark Salyzyndfa7a072014-02-11 12:29:31 -080047 log_id_for_each(i) {
Mark Salyzyn507eb9f2016-01-11 10:58:09 -080048 mLastSet[i] = false;
49 mLast[i] = mLogElements.begin();
50
Mark Salyzynf10e2732016-09-27 13:08:23 -070051 if (setSize(i, __android_logger_get_buffer_size(i))) {
Mark Salyzyn57a0af92014-05-09 17:44:18 -070052 setSize(i, LOG_BUFFER_MIN_SIZE);
53 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -080054 }
Mark Salyzynb6bee332015-09-08 08:56:32 -070055 bool lastMonotonic = monotonic;
Mark Salyzynba7a9a02015-12-01 15:57:25 -080056 monotonic = android_log_clockid() == CLOCK_MONOTONIC;
Mark Salyzynb75cce02015-11-30 11:35:56 -080057 if (lastMonotonic != monotonic) {
58 //
59 // Fixup all timestamps, may not be 100% accurate, but better than
60 // throwing what we have away when we get 'surprised' by a change.
61 // In-place element fixup so no need to check reader-lock. Entries
62 // should already be in timestamp order, but we could end up with a
63 // few out-of-order entries if new monotonics come in before we
64 // are notified of the reinit change in status. A Typical example would
65 // be:
66 // --------- beginning of system
67 // 10.494082 184 201 D Cryptfs : Just triggered post_fs_data
68 // --------- beginning of kernel
69 // 0.000000 0 0 I : Initializing cgroup subsys
70 // as the act of mounting /data would trigger persist.logd.timestamp to
71 // be corrected. 1/30 corner case YMMV.
72 //
73 pthread_mutex_lock(&mLogElementsLock);
74 LogBufferElementCollection::iterator it = mLogElements.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -080075 while ((it != mLogElements.end())) {
76 LogBufferElement* e = *it;
Mark Salyzynb75cce02015-11-30 11:35:56 -080077 if (monotonic) {
78 if (!android::isMonotonic(e->mRealTime)) {
79 LogKlog::convertRealToMonotonic(e->mRealTime);
80 }
81 } else {
82 if (android::isMonotonic(e->mRealTime)) {
83 LogKlog::convertMonotonicToReal(e->mRealTime);
84 }
85 }
86 ++it;
87 }
88 pthread_mutex_unlock(&mLogElementsLock);
Mark Salyzynb6bee332015-09-08 08:56:32 -070089 }
90
Mark Salyzynb75cce02015-11-30 11:35:56 -080091 // We may have been triggered by a SIGHUP. Release any sleeping reader
92 // threads to dump their current content.
Mark Salyzynb6bee332015-09-08 08:56:32 -070093 //
Mark Salyzynb75cce02015-11-30 11:35:56 -080094 // NB: this is _not_ performed in the context of a SIGHUP, it is
95 // performed during startup, and in context of reinit administrative thread
96 LogTimeEntry::lock();
97
98 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -080099 while (times != mTimes.end()) {
100 LogTimeEntry* entry = (*times);
Mark Salyzynb75cce02015-11-30 11:35:56 -0800101 if (entry->owned_Locked()) {
102 entry->triggerReader_Locked();
Mark Salyzynb6bee332015-09-08 08:56:32 -0700103 }
Mark Salyzynb75cce02015-11-30 11:35:56 -0800104 times++;
Mark Salyzynb6bee332015-09-08 08:56:32 -0700105 }
Mark Salyzynb75cce02015-11-30 11:35:56 -0800106
107 LogTimeEntry::unlock();
Mark Salyzyn0175b072014-02-26 09:50:16 -0800108}
109
Mark Salyzyn501c3732017-03-10 14:31:54 -0800110LogBuffer::LogBuffer(LastLogTimes* times)
111 : monotonic(android_log_clockid() == CLOCK_MONOTONIC), mTimes(*times) {
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700112 pthread_mutex_init(&mLogElementsLock, NULL);
113
Mark Salyzyna2c02222016-12-13 10:31:29 -0800114 log_id_for_each(i) {
115 lastLoggedElements[i] = NULL;
116 droppedElements[i] = NULL;
117 }
118
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700119 init();
120}
121
Mark Salyzyna2c02222016-12-13 10:31:29 -0800122LogBuffer::~LogBuffer() {
123 log_id_for_each(i) {
124 delete lastLoggedElements[i];
125 delete droppedElements[i];
126 }
127}
128
Mark Salyzyn501c3732017-03-10 14:31:54 -0800129enum match_type { DIFFERENT, SAME, SAME_LIBLOG };
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800130
Mark Salyzyn501c3732017-03-10 14:31:54 -0800131static enum match_type identical(LogBufferElement* elem,
132 LogBufferElement* last) {
Mark Salyzyna2c02222016-12-13 10:31:29 -0800133 // is it mostly identical?
Mark Salyzyn501c3732017-03-10 14:31:54 -0800134 // if (!elem) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800135 unsigned short lenl = elem->getMsgLen();
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800136 if (!lenl) return DIFFERENT;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800137 // if (!last) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800138 unsigned short lenr = last->getMsgLen();
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800139 if (!lenr) return DIFFERENT;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800140 // if (elem->getLogId() != last->getLogId()) return DIFFERENT;
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800141 if (elem->getUid() != last->getUid()) return DIFFERENT;
142 if (elem->getPid() != last->getPid()) return DIFFERENT;
143 if (elem->getTid() != last->getTid()) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800144
145 // last is more than a minute old, stop squashing identical messages
146 if (elem->getRealTime().nsec() >
Mark Salyzyn501c3732017-03-10 14:31:54 -0800147 (last->getRealTime().nsec() + 60 * NS_PER_SEC))
148 return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800149
150 // Identical message
151 const char* msgl = elem->getMsg();
152 const char* msgr = last->getMsg();
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800153 if (lenl == lenr) {
154 if (!fastcmp<memcmp>(msgl, msgr, lenl)) return SAME;
155 // liblog tagged messages (content gets summed)
156 if ((elem->getLogId() == LOG_ID_EVENTS) &&
157 (lenl == sizeof(android_log_event_int_t)) &&
Mark Salyzyn501c3732017-03-10 14:31:54 -0800158 !fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_int_t) -
159 sizeof(int32_t)) &&
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700160 (elem->getTag() == LIBLOG_LOG_TAG)) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800161 return SAME_LIBLOG;
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700162 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800163 }
Mark Salyzyna2c02222016-12-13 10:31:29 -0800164
165 // audit message (except sequence number) identical?
166 static const char avc[] = "): avc: ";
167
168 if (last->isBinary()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800169 if (fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_string_t) -
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700170 sizeof(int32_t))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800171 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700172 }
Mark Salyzyna2c02222016-12-13 10:31:29 -0800173 msgl += sizeof(android_log_event_string_t);
174 lenl -= sizeof(android_log_event_string_t);
175 msgr += sizeof(android_log_event_string_t);
176 lenr -= sizeof(android_log_event_string_t);
177 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800178 const char* avcl = android::strnstr(msgl, lenl, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800179 if (!avcl) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800180 lenl -= avcl - msgl;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800181 const char* avcr = android::strnstr(msgr, lenr, avc);
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800182 if (!avcr) return DIFFERENT;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800183 lenr -= avcr - msgr;
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800184 if (lenl != lenr) return DIFFERENT;
Alex Shlyapnikov589f4e72017-02-14 17:21:55 -0800185 // TODO: After b/35468874 is addressed, revisit "lenl > strlen(avc)"
186 // condition, it might become superflous.
187 if (lenl > strlen(avc) &&
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700188 fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc),
189 lenl - strlen(avc))) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800190 return DIFFERENT;
Mark Salyzyn1598fe02017-03-13 15:41:59 -0700191 }
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800192 return SAME;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800193}
194
Mark Salyzyn501c3732017-03-10 14:31:54 -0800195int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
196 pid_t tid, const char* msg, unsigned short len) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800197 if ((log_id >= LOG_ID_MAX) || (log_id < 0)) {
Mark Salyzyn202e1532015-02-09 08:21:05 -0800198 return -EINVAL;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800199 }
Mark Salyzyne59c4692014-10-02 13:07:05 -0700200
Mark Salyzyn501c3732017-03-10 14:31:54 -0800201 LogBufferElement* elem =
202 new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len);
Mark Salyzyn0ee8de32016-01-06 21:17:43 +0000203 if (log_id != LOG_ID_SECURITY) {
Mark Salyzyn083b0372015-12-04 10:59:45 -0800204 int prio = ANDROID_LOG_INFO;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800205 const char* tag = NULL;
Mark Salyzyn083b0372015-12-04 10:59:45 -0800206 if (log_id == LOG_ID_EVENTS) {
Mark Salyzyn61e9ce62016-09-12 14:51:54 -0700207 tag = tagToName(elem->getTag());
Mark Salyzyn083b0372015-12-04 10:59:45 -0800208 } else {
209 prio = *msg;
210 tag = msg + 1;
211 }
Mark Salyzyn61e9ce62016-09-12 14:51:54 -0700212 if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
Mark Salyzyn083b0372015-12-04 10:59:45 -0800213 // Log traffic received to total
214 pthread_mutex_lock(&mLogElementsLock);
215 stats.add(elem);
216 stats.subtract(elem);
217 pthread_mutex_unlock(&mLogElementsLock);
218 delete elem;
219 return -EACCES;
220 }
Mark Salyzyne59c4692014-10-02 13:07:05 -0700221 }
Mark Salyzyn0175b072014-02-26 09:50:16 -0800222
223 pthread_mutex_lock(&mLogElementsLock);
Mark Salyzyna2c02222016-12-13 10:31:29 -0800224 LogBufferElement* currentLast = lastLoggedElements[log_id];
225 if (currentLast) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800226 LogBufferElement* dropped = droppedElements[log_id];
Mark Salyzyna2c02222016-12-13 10:31:29 -0800227 unsigned short count = dropped ? dropped->getDropped() : 0;
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800228 //
229 // State Init
230 // incoming:
231 // dropped = NULL
232 // currentLast = NULL;
233 // elem = incoming message
234 // outgoing:
235 // dropped = NULL -> State 0
236 // currentLast = copy of elem
237 // log elem
238 // State 0
239 // incoming:
240 // count = 0
241 // dropped = NULL
242 // currentLast = copy of last message
243 // elem = incoming message
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800244 // outgoing: if match != DIFFERENT
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800245 // dropped = copy of first identical message -> State 1
246 // currentLast = reference to elem
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800247 // break: if match == DIFFERENT
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800248 // dropped = NULL -> State 0
249 // delete copy of last message (incoming currentLast)
250 // currentLast = copy of elem
251 // log elem
252 // State 1
253 // incoming:
254 // count = 0
255 // dropped = copy of first identical message
256 // currentLast = reference to last held-back incoming
257 // message
258 // elem = incoming message
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800259 // outgoing: if match == SAME
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800260 // delete copy of first identical message (dropped)
261 // dropped = reference to last held-back incoming
262 // message set to chatty count of 1 -> State 2
263 // currentLast = reference to elem
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800264 // outgoing: if match == SAME_LIBLOG
265 // dropped = copy of first identical message -> State 1
266 // take sum of currentLast and elem
267 // if sum overflows:
268 // log currentLast
269 // currentLast = reference to elem
270 // else
271 // delete currentLast
272 // currentLast = reference to elem, sum liblog.
273 // break: if match == DIFFERENT
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800274 // delete dropped
275 // dropped = NULL -> State 0
276 // log reference to last held-back (currentLast)
277 // currentLast = copy of elem
278 // log elem
279 // State 2
280 // incoming:
281 // count = chatty count
282 // dropped = chatty message holding count
283 // currentLast = reference to last held-back incoming
284 // message.
285 // dropped = chatty message holding count
286 // elem = incoming message
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800287 // outgoing: if match != DIFFERENT
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800288 // delete chatty message holding count
289 // dropped = reference to last held-back incoming
290 // message, set to chatty count + 1
291 // currentLast = reference to elem
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800292 // break: if match == DIFFERENT
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800293 // log dropped (chatty message)
294 // dropped = NULL -> State 0
295 // log reference to last held-back (currentLast)
296 // currentLast = copy of elem
297 // log elem
298 //
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800299 enum match_type match = identical(elem, currentLast);
300 if (match != DIFFERENT) {
Mark Salyzyna2c02222016-12-13 10:31:29 -0800301 if (dropped) {
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800302 // Sum up liblog tag messages?
303 if ((count == 0) /* at Pass 1 */ && (match == SAME_LIBLOG)) {
304 android_log_event_int_t* event =
305 reinterpret_cast<android_log_event_int_t*>(
306 const_cast<char*>(currentLast->getMsg()));
307 //
308 // To unit test, differentiate with something like:
309 // event->header.tag = htole32(CHATTY_LOG_TAG);
310 // here, then instead of delete currentLast below,
311 // log(currentLast) to see the incremental sums form.
312 //
313 uint32_t swab = event->payload.data;
314 unsigned long long total = htole32(swab);
315 event = reinterpret_cast<android_log_event_int_t*>(
Mark Salyzyn501c3732017-03-10 14:31:54 -0800316 const_cast<char*>(elem->getMsg()));
Mark Salyzyn1dfb4de2016-12-16 16:09:15 -0800317 swab = event->payload.data;
318
319 lastLoggedElements[LOG_ID_EVENTS] = elem;
320 total += htole32(swab);
321 // check for overflow
322 if (total >= UINT32_MAX) {
323 log(currentLast);
324 pthread_mutex_unlock(&mLogElementsLock);
325 return len;
326 }
327 stats.add(currentLast);
328 stats.subtract(currentLast);
329 delete currentLast;
330 swab = total;
331 event->payload.data = htole32(swab);
332 pthread_mutex_unlock(&mLogElementsLock);
333 return len;
334 }
Mark Salyzyna2c02222016-12-13 10:31:29 -0800335 if (count == USHRT_MAX) {
336 log(dropped);
337 count = 1;
338 } else {
339 delete dropped;
340 ++count;
341 }
342 }
343 if (count) {
344 stats.add(currentLast);
345 stats.subtract(currentLast);
346 currentLast->setDropped(count);
347 }
348 droppedElements[log_id] = currentLast;
349 lastLoggedElements[log_id] = elem;
350 pthread_mutex_unlock(&mLogElementsLock);
351 return len;
352 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800353 if (dropped) { // State 1 or 2
354 if (count) { // State 2
355 log(dropped); // report chatty
356 } else { // State 1
357 delete dropped;
Mark Salyzyn8f83a352016-12-16 16:09:15 -0800358 }
Mark Salyzyna2c02222016-12-13 10:31:29 -0800359 droppedElements[log_id] = NULL;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800360 log(currentLast); // report last message in the series
361 } else { // State 0
Mark Salyzyna2c02222016-12-13 10:31:29 -0800362 delete currentLast;
363 }
364 }
365 lastLoggedElements[log_id] = new LogBufferElement(*elem);
Mark Salyzyn0175b072014-02-26 09:50:16 -0800366
Mark Salyzyna2c02222016-12-13 10:31:29 -0800367 log(elem);
368 pthread_mutex_unlock(&mLogElementsLock);
369
370 return len;
371}
372
373// assumes mLogElementsLock held, owns elem, will look after garbage collection
374void LogBuffer::log(LogBufferElement* elem) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800375 // Insert elements in time sorted order if possible
376 // NB: if end is region locked, place element at end of list
377 LogBufferElementCollection::iterator it = mLogElements.end();
378 LogBufferElementCollection::iterator last = it;
Mark Salyzyneae155e2014-10-13 16:49:47 -0700379 while (last != mLogElements.begin()) {
380 --it;
Mark Salyzyna2c02222016-12-13 10:31:29 -0800381 if ((*it)->getRealTime() <= elem->getRealTime()) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800382 break;
383 }
384 last = it;
385 }
Mark Salyzync03e72c2014-02-18 11:23:53 -0800386
Mark Salyzyn0175b072014-02-26 09:50:16 -0800387 if (last == mLogElements.end()) {
388 mLogElements.push_back(elem);
389 } else {
Mark Salyzynf7c0f752015-03-03 13:39:37 -0800390 uint64_t end = 1;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800391 bool end_set = false;
392 bool end_always = false;
393
394 LogTimeEntry::lock();
395
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700396 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -0800397 while (times != mTimes.end()) {
Mark Salyzyna2c02222016-12-13 10:31:29 -0800398 LogTimeEntry* entry = (*times);
Mark Salyzyn0175b072014-02-26 09:50:16 -0800399 if (entry->owned_Locked()) {
400 if (!entry->mNonBlock) {
401 end_always = true;
402 break;
403 }
404 if (!end_set || (end <= entry->mEnd)) {
405 end = entry->mEnd;
406 end_set = true;
407 }
408 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700409 times++;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800410 }
411
Mark Salyzyn501c3732017-03-10 14:31:54 -0800412 if (end_always || (end_set && (end >= (*last)->getSequence()))) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800413 mLogElements.push_back(elem);
414 } else {
Mark Salyzyna2c02222016-12-13 10:31:29 -0800415 mLogElements.insert(last, elem);
Mark Salyzyn0175b072014-02-26 09:50:16 -0800416 }
417
418 LogTimeEntry::unlock();
419 }
420
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700421 stats.add(elem);
Mark Salyzyna2c02222016-12-13 10:31:29 -0800422 maybePrune(elem->getLogId());
Mark Salyzyn0175b072014-02-26 09:50:16 -0800423}
424
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700425// Prune at most 10% of the log entries or maxPrune, whichever is less.
Mark Salyzyn0175b072014-02-26 09:50:16 -0800426//
427// mLogElementsLock must be held when this function is called.
428void LogBuffer::maybePrune(log_id_t id) {
Mark Salyzyn34facab2014-02-06 14:48:50 -0800429 size_t sizes = stats.sizes(id);
Mark Salyzyn62ab0fd2015-08-10 10:23:56 -0700430 unsigned long maxSize = log_buffer_size(id);
431 if (sizes > maxSize) {
Mark Salyzynb39ed0c2015-08-19 12:20:36 -0700432 size_t sizeOver = sizes - ((maxSize * 9) / 10);
Mark Salyzyn58b8be82015-09-30 07:40:09 -0700433 size_t elements = stats.realElements(id);
434 size_t minElements = elements / 100;
435 if (minElements < minPrune) {
436 minElements = minPrune;
437 }
Mark Salyzyn62ab0fd2015-08-10 10:23:56 -0700438 unsigned long pruneRows = elements * sizeOver / sizes;
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700439 if (pruneRows < minElements) {
Mark Salyzyn62ab0fd2015-08-10 10:23:56 -0700440 pruneRows = minElements;
Mark Salyzyn740f9b42014-01-13 16:37:51 -0800441 }
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700442 if (pruneRows > maxPrune) {
443 pruneRows = maxPrune;
Mark Salyzynb39ed0c2015-08-19 12:20:36 -0700444 }
Mark Salyzyn740f9b42014-01-13 16:37:51 -0800445 prune(id, pruneRows);
Mark Salyzyn0175b072014-02-26 09:50:16 -0800446 }
447}
448
Mark Salyzyn831aa292015-09-03 16:08:50 -0700449LogBufferElementCollection::iterator LogBuffer::erase(
Mark Salyzyn501c3732017-03-10 14:31:54 -0800450 LogBufferElementCollection::iterator it, bool coalesce) {
451 LogBufferElement* element = *it;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700452 log_id_t id = element->getLogId();
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700453
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700454 // Remove iterator references in the various lists that will become stale
455 // after the element is erased from the main logging list.
456
Mark Salyzyn501c3732017-03-10 14:31:54 -0800457 { // start of scope for found iterator
458 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
459 ? element->getTag()
460 : element->getUid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700461 LogBufferIteratorMap::iterator found = mLastWorst[id].find(key);
462 if ((found != mLastWorst[id].end()) && (it == found->second)) {
463 mLastWorst[id].erase(found);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700464 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700465 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700466
Mark Salyzyn501c3732017-03-10 14:31:54 -0800467 { // start of scope for pid found iterator
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700468 // element->getUid() may not be AID_SYSTEM for next-best-watermark.
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700469 // will not assume id != LOG_ID_EVENTS or LOG_ID_SECURITY for KISS and
470 // long term code stability, find() check should be fast for those ids.
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700471 LogBufferPidIteratorMap::iterator found =
472 mLastWorstPidOfSystem[id].find(element->getPid());
Mark Salyzyn501c3732017-03-10 14:31:54 -0800473 if ((found != mLastWorstPidOfSystem[id].end()) &&
474 (it == found->second)) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700475 mLastWorstPidOfSystem[id].erase(found);
476 }
477 }
478
Mark Salyzyn7fd6c5c2016-01-19 16:04:41 -0800479 bool setLast[LOG_ID_MAX];
480 bool doSetLast = false;
481 log_id_for_each(i) {
482 doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]);
483 }
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700484#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
485 LogBufferElementCollection::iterator bad = it;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800486 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
487 ? element->getTag()
488 : element->getUid();
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700489#endif
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700490 it = mLogElements.erase(it);
Mark Salyzyn7fd6c5c2016-01-19 16:04:41 -0800491 if (doSetLast) {
492 log_id_for_each(i) {
493 if (setLast[i]) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800494 if (__predict_false(it == mLogElements.end())) { // impossible
Mark Salyzyn7fd6c5c2016-01-19 16:04:41 -0800495 mLastSet[i] = false;
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700496 mLast[i] = mLogElements.begin();
Mark Salyzyn7fd6c5c2016-01-19 16:04:41 -0800497 } else {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800498 mLast[i] = it; // push down the road as next-best-watermark
Mark Salyzyn7fd6c5c2016-01-19 16:04:41 -0800499 }
500 }
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800501 }
502 }
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700503#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
504 log_id_for_each(i) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800505 for (auto b : mLastWorst[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700506 if (bad == b.second) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800507 android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i,
508 b.first, key);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700509 }
510 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800511 for (auto b : mLastWorstPidOfSystem[i]) {
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700512 if (bad == b.second) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800513 android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i,
514 b.first);
Mark Salyzyn60636fa2016-10-24 16:22:17 -0700515 }
516 }
517 if (mLastSet[i] && (bad == mLast[i])) {
518 android::prdebug("stale mLast[%d]\n", i);
519 mLastSet[i] = false;
520 mLast[i] = mLogElements.begin();
521 }
522 }
523#endif
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700524 if (coalesce) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700525 stats.erase(element);
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700526 } else {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700527 stats.subtract(element);
Mark Salyzyn831aa292015-09-03 16:08:50 -0700528 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700529 delete element;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700530
531 return it;
532}
533
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700534// Define a temporary mechanism to report the last LogBufferElement pointer
535// for the specified uid, pid and tid. Used below to help merge-sort when
536// pruning for worst UID.
537class LogBufferElementKey {
538 const union {
539 struct {
Mark Salyzyn684bdb52016-12-13 12:44:20 -0800540 uint32_t uid;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700541 uint16_t pid;
542 uint16_t tid;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700543 } __packed;
544 uint64_t value;
545 } __packed;
546
Mark Salyzyn501c3732017-03-10 14:31:54 -0800547 public:
548 LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid)
549 : uid(uid), pid(pid), tid(tid) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700550 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800551 explicit LogBufferElementKey(uint64_t key) : value(key) {
552 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700553
Mark Salyzyn501c3732017-03-10 14:31:54 -0800554 uint64_t getKey() {
555 return value;
556 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700557};
558
Mark Salyzyn511338d2015-05-19 09:12:30 -0700559class LogBufferElementLast {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800560 typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap;
Mark Salyzyn511338d2015-05-19 09:12:30 -0700561 LogBufferElementMap map;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700562
Mark Salyzyn501c3732017-03-10 14:31:54 -0800563 public:
564 bool coalesce(LogBufferElement* element, unsigned short dropped) {
565 LogBufferElementKey key(element->getUid(), element->getPid(),
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700566 element->getTid());
Mark Salyzyn511338d2015-05-19 09:12:30 -0700567 LogBufferElementMap::iterator it = map.find(key.getKey());
568 if (it != map.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800569 LogBufferElement* found = it->second;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700570 unsigned short moreDropped = found->getDropped();
571 if ((dropped + moreDropped) > USHRT_MAX) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700572 map.erase(it);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700573 } else {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700574 found->setDropped(dropped + moreDropped);
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700575 return true;
576 }
577 }
578 return false;
579 }
580
Mark Salyzyn501c3732017-03-10 14:31:54 -0800581 void add(LogBufferElement* element) {
582 LogBufferElementKey key(element->getUid(), element->getPid(),
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700583 element->getTid());
584 map[key.getKey()] = element;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700585 }
586
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700587 inline void clear() {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700588 map.clear();
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700589 }
590
Mark Salyzyn501c3732017-03-10 14:31:54 -0800591 void clear(LogBufferElement* element) {
592 uint64_t current =
593 element->getRealTime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC);
594 for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) {
595 LogBufferElement* mapElement = it->second;
596 if ((mapElement->getDropped() >= EXPIRE_THRESHOLD) &&
597 (current > mapElement->getRealTime().nsec())) {
Mark Salyzyn511338d2015-05-19 09:12:30 -0700598 it = map.erase(it);
599 } else {
600 ++it;
Mark Salyzyne06a6e02015-04-20 14:08:56 -0700601 }
602 }
603 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700604};
605
Mark Salyzyn0175b072014-02-26 09:50:16 -0800606// prune "pruneRows" of type "id" from the buffer.
607//
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700608// This garbage collection task is used to expire log entries. It is called to
609// remove all logs (clear), all UID logs (unprivileged clear), or every
610// 256 or 10% of the total logs (whichever is less) to prune the logs.
611//
612// First there is a prep phase where we discover the reader region lock that
613// acts as a backstop to any pruning activity to stop there and go no further.
614//
615// There are three major pruning loops that follow. All expire from the oldest
616// entries. Since there are multiple log buffers, the Android logging facility
617// will appear to drop entries 'in the middle' when looking at multiple log
618// sources and buffers. This effect is slightly more prominent when we prune
619// the worst offender by logging source. Thus the logs slowly loose content
620// and value as you move back in time. This is preferred since chatty sources
621// invariably move the logs value down faster as less chatty sources would be
622// expired in the noise.
623//
624// The first loop performs blacklisting and worst offender pruning. Falling
625// through when there are no notable worst offenders and have not hit the
626// region lock preventing further worst offender pruning. This loop also looks
627// after managing the chatty log entries and merging to help provide
628// statistical basis for blame. The chatty entries are not a notification of
629// how much logs you may have, but instead represent how much logs you would
630// have had in a virtual log buffer that is extended to cover all the in-memory
631// logs without loss. They last much longer than the represented pruned logs
632// since they get multiplied by the gains in the non-chatty log sources.
633//
634// The second loop get complicated because an algorithm of watermarks and
635// history is maintained to reduce the order and keep processing time
636// down to a minimum at scale. These algorithms can be costly in the face
637// of larger log buffers, or severly limited processing time granted to a
638// background task at lowest priority.
639//
640// This second loop does straight-up expiration from the end of the logs
641// (again, remember for the specified log buffer id) but does some whitelist
642// preservation. Thus whitelist is a Hail Mary low priority, blacklists and
643// spam filtration all take priority. This second loop also checks if a region
644// lock is causing us to buffer too much in the logs to help the reader(s),
645// and will tell the slowest reader thread to skip log entries, and if
646// persistent and hits a further threshold, kill the reader thread.
647//
648// The third thread is optional, and only gets hit if there was a whitelist
649// and more needs to be pruned against the backstop of the region lock.
650//
Mark Salyzyn0175b072014-02-26 09:50:16 -0800651// mLogElementsLock must be held when this function is called.
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700652//
Mark Salyzync5dc9702015-09-16 15:34:00 -0700653bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800654 LogTimeEntry* oldest = NULL;
Mark Salyzync5dc9702015-09-16 15:34:00 -0700655 bool busy = false;
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700656 bool clearAll = pruneRows == ULONG_MAX;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800657
658 LogTimeEntry::lock();
659
660 // Region locked?
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700661 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -0800662 while (times != mTimes.end()) {
663 LogTimeEntry* entry = (*times);
664 if (entry->owned_Locked() && entry->isWatching(id) &&
665 (!oldest || (oldest->mStart > entry->mStart) ||
666 ((oldest->mStart == entry->mStart) &&
667 (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec)))) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800668 oldest = entry;
669 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700670 times++;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800671 }
672
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800673 LogBufferElementCollection::iterator it;
674
Mark Salyzyn501c3732017-03-10 14:31:54 -0800675 if (__predict_false(caller_uid != AID_ROOT)) { // unlikely
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700676 // Only here if clear all request from non system source, so chatty
677 // filter logistics is not required.
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800678 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
679 while (it != mLogElements.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800680 LogBufferElement* element = *it;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700681
Mark Salyzyn501c3732017-03-10 14:31:54 -0800682 if ((element->getLogId() != id) ||
683 (element->getUid() != caller_uid)) {
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700684 ++it;
685 continue;
686 }
687
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800688 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
689 mLast[id] = it;
690 mLastSet[id] = true;
691 }
692
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700693 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzync5dc9702015-09-16 15:34:00 -0700694 busy = true;
Mark Salyzynb75cce02015-11-30 11:35:56 -0800695 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
696 oldest->triggerReader_Locked();
697 } else {
698 oldest->triggerSkip_Locked(id, pruneRows);
699 }
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700700 break;
701 }
702
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700703 it = erase(it);
Mark Salyzyn43a5f312016-09-01 15:48:36 -0700704 if (--pruneRows == 0) {
705 break;
706 }
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700707 }
708 LogTimeEntry::unlock();
Mark Salyzync5dc9702015-09-16 15:34:00 -0700709 return busy;
Mark Salyzyn1a240b42014-06-12 11:16:16 -0700710 }
711
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700712 // prune by worst offenders; by blacklist, UID, and by PID of system UID
Mark Salyzyn083b0372015-12-04 10:59:45 -0800713 bool hasBlacklist = (id != LOG_ID_SECURITY) && mPrune.naughty();
Mark Salyzyn2b25c662015-09-16 15:34:00 -0700714 while (!clearAll && (pruneRows > 0)) {
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800715 // recalculate the worst offender on every batched pass
Mark Salyzyn501c3732017-03-10 14:31:54 -0800716 int worst = -1; // not valid for getUid() or getKey()
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800717 size_t worst_sizes = 0;
718 size_t second_worst_sizes = 0;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800719 pid_t worstPid = 0; // POSIX guarantees PID != 0
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800720
Mark Salyzynae769232015-03-17 17:17:25 -0700721 if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700722 // Calculate threshold as 12.5% of available storage
723 size_t threshold = log_buffer_size(id) / 8;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700724
Mark Salyzyn6a066942016-07-14 15:34:30 -0700725 if ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800726 stats.sortTags(AID_ROOT, (pid_t)0, 2, id)
727 .findWorst(worst, worst_sizes, second_worst_sizes,
728 threshold);
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700729 // per-pid filter for AID_SYSTEM sources is too complex
Mark Salyzyn6a066942016-07-14 15:34:30 -0700730 } else {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800731 stats.sort(AID_ROOT, (pid_t)0, 2, id)
732 .findWorst(worst, worst_sizes, second_worst_sizes,
733 threshold);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700734
Mark Salyzyn6a066942016-07-14 15:34:30 -0700735 if ((worst == AID_SYSTEM) && mPrune.worstPidOfSystemEnabled()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800736 stats.sortPids(worst, (pid_t)0, 2, id)
737 .findWorst(worstPid, worst_sizes, second_worst_sizes);
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700738 }
739 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800740 }
741
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700742 // skip if we have neither worst nor naughty filters
Mark Salyzyn6a066942016-07-14 15:34:30 -0700743 if ((worst == -1) && !hasBlacklist) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700744 break;
745 }
746
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800747 bool kick = false;
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700748 bool leading = true;
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800749 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700750 // Perform at least one mandatory garbage collection cycle in following
751 // - clear leading chatty tags
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700752 // - coalesce chatty tags
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700753 // - check age-out of preserved logs
754 bool gc = pruneRows <= 1;
Mark Salyzyn6a066942016-07-14 15:34:30 -0700755 if (!gc && (worst != -1)) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800756 { // begin scope for worst found iterator
757 LogBufferIteratorMap::iterator found =
758 mLastWorst[id].find(worst);
759 if ((found != mLastWorst[id].end()) &&
760 (found->second != mLogElements.end())) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700761 leading = false;
762 it = found->second;
763 }
764 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800765 if (worstPid) { // begin scope for pid worst found iterator
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700766 // FYI: worstPid only set if !LOG_ID_EVENTS and
767 // !LOG_ID_SECURITY, not going to make that assumption ...
Mark Salyzyn501c3732017-03-10 14:31:54 -0800768 LogBufferPidIteratorMap::iterator found =
769 mLastWorstPidOfSystem[id].find(worstPid);
770 if ((found != mLastWorstPidOfSystem[id].end()) &&
771 (found->second != mLogElements.end())) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700772 leading = false;
773 it = found->second;
774 }
Mark Salyzync892ea32015-08-19 17:06:11 -0700775 }
776 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800777 static const timespec too_old = { EXPIRE_HOUR_THRESHOLD * 60 * 60, 0 };
Mark Salyzynccfe8442015-08-24 13:43:27 -0700778 LogBufferElementCollection::iterator lastt;
779 lastt = mLogElements.end();
780 --lastt;
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700781 LogBufferElementLast last;
Mark Salyzync892ea32015-08-19 17:06:11 -0700782 while (it != mLogElements.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800783 LogBufferElement* element = *it;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800784
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700785 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzync5dc9702015-09-16 15:34:00 -0700786 busy = true;
Mark Salyzynb75cce02015-11-30 11:35:56 -0800787 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
788 oldest->triggerReader_Locked();
789 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800790 break;
791 }
792
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700793 if (element->getLogId() != id) {
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800794 ++it;
795 continue;
796 }
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700797 // below this point element->getLogId() == id
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800798
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800799 if (leading && (!mLastSet[id] || ((*mLast[id])->getLogId() != id))) {
800 mLast[id] = it;
801 mLastSet[id] = true;
802 }
803
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700804 unsigned short dropped = element->getDropped();
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800805
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700806 // remove any leading drops
807 if (leading && dropped) {
808 it = erase(it);
809 continue;
810 }
811
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700812 if (dropped && last.coalesce(element, dropped)) {
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700813 it = erase(it, true);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700814 continue;
815 }
816
Mark Salyzyn501c3732017-03-10 14:31:54 -0800817 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
818 ? element->getTag()
819 : element->getUid();
Mark Salyzyn6a066942016-07-14 15:34:30 -0700820
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700821 if (hasBlacklist && mPrune.naughty(element)) {
822 last.clear(element);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700823 it = erase(it);
824 if (dropped) {
825 continue;
826 }
827
828 pruneRows--;
829 if (pruneRows == 0) {
830 break;
831 }
832
Mark Salyzyn6a066942016-07-14 15:34:30 -0700833 if (key == worst) {
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700834 kick = true;
835 if (worst_sizes < second_worst_sizes) {
836 break;
837 }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700838 worst_sizes -= element->getMsgLen();
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700839 }
840 continue;
841 }
842
Mark Salyzyn501c3732017-03-10 14:31:54 -0800843 if ((element->getRealTime() < ((*lastt)->getRealTime() - too_old)) ||
844 (element->getRealTime() > (*lastt)->getRealTime())) {
Mark Salyzynccfe8442015-08-24 13:43:27 -0700845 break;
846 }
847
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700848 if (dropped) {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700849 last.add(element);
Mark Salyzyn501c3732017-03-10 14:31:54 -0800850 if (worstPid &&
851 ((!gc && (element->getPid() == worstPid)) ||
852 (mLastWorstPidOfSystem[id].find(element->getPid()) ==
853 mLastWorstPidOfSystem[id].end()))) {
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700854 // element->getUid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700855 // watermark if current one empty. id is not LOG_ID_EVENTS
856 // or LOG_ID_SECURITY because of worstPid check.
Mark Salyzyn1eefca22016-09-01 07:28:44 -0700857 mLastWorstPidOfSystem[id][element->getPid()] = it;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700858 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800859 if ((!gc && !worstPid && (key == worst)) ||
860 (mLastWorst[id].find(key) == mLastWorst[id].end())) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700861 mLastWorst[id][key] = it;
Mark Salyzyn49afe0d2015-08-24 13:43:27 -0700862 }
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800863 ++it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700864 continue;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800865 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700866
Mark Salyzyn501c3732017-03-10 14:31:54 -0800867 if ((key != worst) ||
868 (worstPid && (element->getPid() != worstPid))) {
Mark Salyzyn59212762015-06-01 09:41:19 -0700869 leading = false;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700870 last.clear(element);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700871 ++it;
872 continue;
873 }
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700874 // key == worst below here
875 // If worstPid set, then element->getPid() == worstPid below here
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700876
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700877 pruneRows--;
878 if (pruneRows == 0) {
879 break;
880 }
881
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700882 kick = true;
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700883
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700884 unsigned short len = element->getMsgLen();
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700885
886 // do not create any leading drops
887 if (leading) {
888 it = erase(it);
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700889 } else {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700890 stats.drop(element);
891 element->setDropped(1);
892 if (last.coalesce(element, 1)) {
Mark Salyzynaaad42f2015-09-30 07:40:09 -0700893 it = erase(it, true);
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700894 } else {
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700895 last.add(element);
Mark Salyzyn501c3732017-03-10 14:31:54 -0800896 if (worstPid &&
897 (!gc || (mLastWorstPidOfSystem[id].find(worstPid) ==
898 mLastWorstPidOfSystem[id].end()))) {
Mark Salyzynfa07f9d2016-10-21 09:46:42 -0700899 // element->getUid() may not be AID_SYSTEM, next best
Mark Salyzyn8fcfd852016-10-24 08:20:26 -0700900 // watermark if current one empty. id is not
901 // LOG_ID_EVENTS or LOG_ID_SECURITY because of worstPid.
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700902 mLastWorstPidOfSystem[id][worstPid] = it;
903 }
Mark Salyzyn6a066942016-07-14 15:34:30 -0700904 if ((!gc && !worstPid) ||
Mark Salyzyn501c3732017-03-10 14:31:54 -0800905 (mLastWorst[id].find(worst) == mLastWorst[id].end())) {
Mark Salyzyn6a066942016-07-14 15:34:30 -0700906 mLastWorst[id][worst] = it;
Mark Salyzyn5bb29722015-09-08 09:12:51 -0700907 }
Mark Salyzyn5392aac2015-05-22 10:03:31 -0700908 ++it;
909 }
Mark Salyzynab0dcf62015-03-16 12:04:09 -0700910 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700911 if (worst_sizes < second_worst_sizes) {
912 break;
913 }
914 worst_sizes -= len;
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800915 }
Mark Salyzyn2c9d9092015-04-17 15:38:04 -0700916 last.clear();
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800917
Mark Salyzyn1c950472014-04-01 17:19:47 -0700918 if (!kick || !mPrune.worstUidEnabled()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -0800919 break; // the following loop will ask bad clients to skip/drop
Mark Salyzyn64d6fe92014-02-06 18:11:13 -0800920 }
921 }
922
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800923 bool whitelist = false;
Mark Salyzyn083b0372015-12-04 10:59:45 -0800924 bool hasWhitelist = (id != LOG_ID_SECURITY) && mPrune.nice() && !clearAll;
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800925 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -0800926 while ((pruneRows > 0) && (it != mLogElements.end())) {
927 LogBufferElement* element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700928
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700929 if (element->getLogId() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700930 it++;
931 continue;
932 }
933
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800934 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
935 mLast[id] = it;
936 mLastSet[id] = true;
937 }
938
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700939 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzync5dc9702015-09-16 15:34:00 -0700940 busy = true;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700941 if (whitelist) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800942 break;
943 }
Mark Salyzyn1c950472014-04-01 17:19:47 -0700944
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700945 if (stats.sizes(id) > (2 * log_buffer_size(id))) {
946 // kick a misbehaving log reader client off the island
947 oldest->release_Locked();
Mark Salyzynb75cce02015-11-30 11:35:56 -0800948 } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
949 oldest->triggerReader_Locked();
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700950 } else {
951 oldest->triggerSkip_Locked(id, pruneRows);
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800952 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700953 break;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800954 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700955
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700956 if (hasWhitelist && !element->getDropped() && mPrune.nice(element)) {
957 // WhiteListed
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700958 whitelist = true;
959 it++;
960 continue;
961 }
962
963 it = erase(it);
964 pruneRows--;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800965 }
966
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700967 // Do not save the whitelist if we are reader range limited
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800968 if (whitelist && (pruneRows > 0)) {
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800969 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzyn501c3732017-03-10 14:31:54 -0800970 while ((it != mLogElements.end()) && (pruneRows > 0)) {
971 LogBufferElement* element = *it;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700972
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700973 if (element->getLogId() != id) {
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700974 ++it;
975 continue;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800976 }
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700977
Mark Salyzyn507eb9f2016-01-11 10:58:09 -0800978 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
979 mLast[id] = it;
980 mLastSet[id] = true;
981 }
982
Mark Salyzynbec3c3d2015-08-28 08:02:59 -0700983 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzync5dc9702015-09-16 15:34:00 -0700984 busy = true;
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700985 if (stats.sizes(id) > (2 * log_buffer_size(id))) {
986 // kick a misbehaving log reader client off the island
987 oldest->release_Locked();
Mark Salyzynb75cce02015-11-30 11:35:56 -0800988 } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
989 oldest->triggerReader_Locked();
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -0700990 } else {
991 oldest->triggerSkip_Locked(id, pruneRows);
992 }
993 break;
994 }
995
996 it = erase(it);
997 pruneRows--;
Mark Salyzyndfa7a072014-02-11 12:29:31 -0800998 }
999 }
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001000
Mark Salyzyn0175b072014-02-26 09:50:16 -08001001 LogTimeEntry::unlock();
Mark Salyzync5dc9702015-09-16 15:34:00 -07001002
1003 return (pruneRows > 0) && busy;
Mark Salyzyn0175b072014-02-26 09:50:16 -08001004}
1005
1006// clear all rows of type "id" from the buffer.
Mark Salyzync5dc9702015-09-16 15:34:00 -07001007bool LogBuffer::clear(log_id_t id, uid_t uid) {
1008 bool busy = true;
1009 // If it takes more than 4 tries (seconds) to clear, then kill reader(s)
1010 for (int retry = 4;;) {
Mark Salyzyn501c3732017-03-10 14:31:54 -08001011 if (retry == 1) { // last pass
Mark Salyzync5dc9702015-09-16 15:34:00 -07001012 // Check if it is still busy after the sleep, we say prune
1013 // one entry, not another clear run, so we are looking for
1014 // the quick side effect of the return value to tell us if
1015 // we have a _blocked_ reader.
1016 pthread_mutex_lock(&mLogElementsLock);
1017 busy = prune(id, 1, uid);
1018 pthread_mutex_unlock(&mLogElementsLock);
1019 // It is still busy, blocked reader(s), lets kill them all!
1020 // otherwise, lets be a good citizen and preserve the slow
1021 // readers and let the clear run (below) deal with determining
1022 // if we are still blocked and return an error code to caller.
1023 if (busy) {
1024 LogTimeEntry::lock();
1025 LastLogTimes::iterator times = mTimes.begin();
1026 while (times != mTimes.end()) {
Mark Salyzyn501c3732017-03-10 14:31:54 -08001027 LogTimeEntry* entry = (*times);
Mark Salyzync5dc9702015-09-16 15:34:00 -07001028 // Killer punch
1029 if (entry->owned_Locked() && entry->isWatching(id)) {
1030 entry->release_Locked();
1031 }
1032 times++;
1033 }
1034 LogTimeEntry::unlock();
1035 }
1036 }
1037 pthread_mutex_lock(&mLogElementsLock);
1038 busy = prune(id, ULONG_MAX, uid);
1039 pthread_mutex_unlock(&mLogElementsLock);
1040 if (!busy || !--retry) {
1041 break;
1042 }
Mark Salyzyn501c3732017-03-10 14:31:54 -08001043 sleep(1); // Let reader(s) catch up after notification
Mark Salyzync5dc9702015-09-16 15:34:00 -07001044 }
1045 return busy;
Mark Salyzyn0175b072014-02-26 09:50:16 -08001046}
1047
1048// get the used space associated with "id".
1049unsigned long LogBuffer::getSizeUsed(log_id_t id) {
1050 pthread_mutex_lock(&mLogElementsLock);
Mark Salyzyn34facab2014-02-06 14:48:50 -08001051 size_t retval = stats.sizes(id);
Mark Salyzyn0175b072014-02-26 09:50:16 -08001052 pthread_mutex_unlock(&mLogElementsLock);
1053 return retval;
1054}
1055
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001056// set the total space allocated to "id"
1057int LogBuffer::setSize(log_id_t id, unsigned long size) {
1058 // Reasonable limits ...
Mark Salyzynf10e2732016-09-27 13:08:23 -07001059 if (!__android_logger_valid_buffer_size(size)) {
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001060 return -1;
1061 }
1062 pthread_mutex_lock(&mLogElementsLock);
1063 log_buffer_size(id) = size;
1064 pthread_mutex_unlock(&mLogElementsLock);
1065 return 0;
1066}
1067
1068// get the total space allocated to "id"
1069unsigned long LogBuffer::getSize(log_id_t id) {
1070 pthread_mutex_lock(&mLogElementsLock);
1071 size_t retval = log_buffer_size(id);
1072 pthread_mutex_unlock(&mLogElementsLock);
1073 return retval;
1074}
1075
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001076uint64_t LogBuffer::flushTo(
Mark Salyzyn501c3732017-03-10 14:31:54 -08001077 SocketClient* reader, const uint64_t start, bool privileged, bool security,
1078 int (*filter)(const LogBufferElement* element, void* arg), void* arg) {
Mark Salyzyn0175b072014-02-26 09:50:16 -08001079 LogBufferElementCollection::iterator it;
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001080 uint64_t max = start;
Mark Salyzyn0175b072014-02-26 09:50:16 -08001081 uid_t uid = reader->getUid();
1082
1083 pthread_mutex_lock(&mLogElementsLock);
Dragoslav Mitrinovic8e8e8db2015-01-15 09:29:43 -06001084
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001085 if (start <= 1) {
Dragoslav Mitrinovic8e8e8db2015-01-15 09:29:43 -06001086 // client wants to start from the beginning
1087 it = mLogElements.begin();
1088 } else {
1089 // Client wants to start from some specified time. Chances are
1090 // we are better off starting from the end of the time sorted list.
Mark Salyzyn501c3732017-03-10 14:31:54 -08001091 for (it = mLogElements.end(); it != mLogElements.begin();
1092 /* do nothing */) {
Dragoslav Mitrinovic8e8e8db2015-01-15 09:29:43 -06001093 --it;
Mark Salyzyn501c3732017-03-10 14:31:54 -08001094 LogBufferElement* element = *it;
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001095 if (element->getSequence() <= start) {
Dragoslav Mitrinovic8e8e8db2015-01-15 09:29:43 -06001096 it++;
1097 break;
1098 }
1099 }
1100 }
1101
Mark Salyzynb5b87962017-01-23 14:20:31 -08001102 // Help detect if the valid message before is from the same source so
1103 // we can differentiate chatty filter types.
1104 pid_t lastTid[LOG_ID_MAX] = { 0 };
1105
Dragoslav Mitrinovic8e8e8db2015-01-15 09:29:43 -06001106 for (; it != mLogElements.end(); ++it) {
Mark Salyzyn501c3732017-03-10 14:31:54 -08001107 LogBufferElement* element = *it;
Mark Salyzyn0175b072014-02-26 09:50:16 -08001108
1109 if (!privileged && (element->getUid() != uid)) {
1110 continue;
1111 }
1112
Mark Salyzyn8fa88962016-01-26 14:32:35 -08001113 if (!security && (element->getLogId() == LOG_ID_SECURITY)) {
1114 continue;
1115 }
1116
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001117 if (element->getSequence() <= start) {
Mark Salyzyn0175b072014-02-26 09:50:16 -08001118 continue;
1119 }
1120
1121 // NB: calling out to another object with mLogElementsLock held (safe)
Mark Salyzynf7c0f752015-03-03 13:39:37 -08001122 if (filter) {
1123 int ret = (*filter)(element, arg);
1124 if (ret == false) {
1125 continue;
1126 }
1127 if (ret != true) {
1128 break;
1129 }
Mark Salyzyn0175b072014-02-26 09:50:16 -08001130 }
1131
Mark Salyzynb5b87962017-01-23 14:20:31 -08001132 bool sameTid = lastTid[element->getLogId()] == element->getTid();
1133 // Dropped (chatty) immediately following a valid log from the
1134 // same source in the same log buffer indicates we have a
1135 // multiple identical squash. chatty that differs source
1136 // is due to spam filter. chatty to chatty of different
1137 // source is also due to spam filter.
Mark Salyzyn501c3732017-03-10 14:31:54 -08001138 lastTid[element->getLogId()] =
1139 (element->getDropped() && !sameTid) ? 0 : element->getTid();
Mark Salyzynb5b87962017-01-23 14:20:31 -08001140
Mark Salyzyn0175b072014-02-26 09:50:16 -08001141 pthread_mutex_unlock(&mLogElementsLock);
1142
1143 // range locking in LastLogTimes looks after us
Mark Salyzynb5b87962017-01-23 14:20:31 -08001144 max = element->flushTo(reader, this, privileged, sameTid);
Mark Salyzyn0175b072014-02-26 09:50:16 -08001145
1146 if (max == element->FLUSH_ERROR) {
1147 return max;
1148 }
1149
1150 pthread_mutex_lock(&mLogElementsLock);
1151 }
1152 pthread_mutex_unlock(&mLogElementsLock);
1153
1154 return max;
1155}
Mark Salyzyn34facab2014-02-06 14:48:50 -08001156
Mark Salyzynee3b8382015-12-17 09:58:43 -08001157std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid,
1158 unsigned int logMask) {
Mark Salyzyn34facab2014-02-06 14:48:50 -08001159 pthread_mutex_lock(&mLogElementsLock);
1160
Mark Salyzynee3b8382015-12-17 09:58:43 -08001161 std::string ret = stats.format(uid, pid, logMask);
Mark Salyzyn34facab2014-02-06 14:48:50 -08001162
1163 pthread_mutex_unlock(&mLogElementsLock);
Mark Salyzyn73160ac2015-08-20 10:01:44 -07001164
1165 return ret;
Mark Salyzyn34facab2014-02-06 14:48:50 -08001166}