blob: fbd04ef8c8926d28fa941ba4de99dc7bf011233e [file] [log] [blame]
Mark Salyzyn12bac902014-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 Salyzyn21fc3932016-10-24 16:22:17 -070016// for manual checking of stale entries during LogBuffer::erase()
17//#define DEBUG_CHECK_FOR_STALE_ENTRIES
Mark Salyzyn12bac902014-02-26 09:50:16 -080018
Mark Salyzyn4e756fb2014-05-06 07:34:59 -070019#include <ctype.h>
Mark Salyzynedb18aa2016-12-16 16:09:15 -080020#include <endian.h>
Mark Salyzyn88fe7cc2015-02-09 08:21:05 -080021#include <errno.h>
Mark Salyzyn12bac902014-02-26 09:50:16 -080022#include <stdio.h>
23#include <string.h>
Mark Salyzyn2e86fa42016-10-24 08:20:26 -070024#include <sys/cdefs.h>
Mark Salyzyn7b85c592014-05-09 17:44:18 -070025#include <sys/user.h>
Mark Salyzyn12bac902014-02-26 09:50:16 -080026#include <time.h>
27#include <unistd.h>
28
Mark Salyzyn6a404192015-05-19 09:12:30 -070029#include <unordered_map>
Mark Salyzyn399d5b92017-03-03 10:21:23 -080030#include <utility>
Mark Salyzyn6a404192015-05-19 09:12:30 -070031
Mark Salyzyn4e756fb2014-05-06 07:34:59 -070032#include <cutils/properties.h>
Mark Salyzynf4693f32016-09-27 13:08:23 -070033#include <private/android_logger.h>
Mark Salyzyn12bac902014-02-26 09:50:16 -080034
35#include "LogBuffer.h"
Mark Salyzyn2b4a7632015-09-08 08:56:32 -070036#include "LogKlog.h"
Mark Salyzyn4e756fb2014-05-06 07:34:59 -070037#include "LogReader.h"
Mark Salyzyn2456d042016-12-13 10:31:29 -080038#include "LogUtils.h"
Mark Salyzyn12bac902014-02-26 09:50:16 -080039
Mark Salyzyn2e86fa42016-10-24 08:20:26 -070040#ifndef __predict_false
41#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
42#endif
43
Mark Salyzync89839a2014-02-11 12:29:31 -080044// Default
Mark Salyzync89839a2014-02-11 12:29:31 -080045#define log_buffer_size(id) mMaxSize[id]
Mark Salyzyn4e756fb2014-05-06 07:34:59 -070046
Mark Salyzyn3fe25932015-03-10 16:45:17 -070047void LogBuffer::init() {
Mark Salyzync89839a2014-02-11 12:29:31 -080048 log_id_for_each(i) {
Mark Salyzyn7a3c2822016-01-11 10:58:09 -080049 mLastSet[i] = false;
50 mLast[i] = mLogElements.begin();
51
Mark Salyzynf4693f32016-09-27 13:08:23 -070052 if (setSize(i, __android_logger_get_buffer_size(i))) {
Mark Salyzyn7b85c592014-05-09 17:44:18 -070053 setSize(i, LOG_BUFFER_MIN_SIZE);
54 }
Mark Salyzync89839a2014-02-11 12:29:31 -080055 }
Mark Salyzyn2b4a7632015-09-08 08:56:32 -070056 bool lastMonotonic = monotonic;
Mark Salyzyn2d4f9bc2015-12-01 15:57:25 -080057 monotonic = android_log_clockid() == CLOCK_MONOTONIC;
Mark Salyzyn552b4752015-11-30 11:35:56 -080058 if (lastMonotonic != monotonic) {
59 //
60 // Fixup all timestamps, may not be 100% accurate, but better than
61 // throwing what we have away when we get 'surprised' by a change.
62 // In-place element fixup so no need to check reader-lock. Entries
63 // should already be in timestamp order, but we could end up with a
64 // few out-of-order entries if new monotonics come in before we
65 // are notified of the reinit change in status. A Typical example would
66 // be:
67 // --------- beginning of system
68 // 10.494082 184 201 D Cryptfs : Just triggered post_fs_data
69 // --------- beginning of kernel
70 // 0.000000 0 0 I : Initializing cgroup subsys
71 // as the act of mounting /data would trigger persist.logd.timestamp to
72 // be corrected. 1/30 corner case YMMV.
73 //
74 pthread_mutex_lock(&mLogElementsLock);
75 LogBufferElementCollection::iterator it = mLogElements.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -080076 while ((it != mLogElements.end())) {
77 LogBufferElement* e = *it;
Mark Salyzyn552b4752015-11-30 11:35:56 -080078 if (monotonic) {
79 if (!android::isMonotonic(e->mRealTime)) {
80 LogKlog::convertRealToMonotonic(e->mRealTime);
81 }
82 } else {
83 if (android::isMonotonic(e->mRealTime)) {
84 LogKlog::convertMonotonicToReal(e->mRealTime);
85 }
86 }
87 ++it;
88 }
89 pthread_mutex_unlock(&mLogElementsLock);
Mark Salyzyn2b4a7632015-09-08 08:56:32 -070090 }
91
Mark Salyzyn552b4752015-11-30 11:35:56 -080092 // We may have been triggered by a SIGHUP. Release any sleeping reader
93 // threads to dump their current content.
Mark Salyzyn2b4a7632015-09-08 08:56:32 -070094 //
Mark Salyzyn552b4752015-11-30 11:35:56 -080095 // NB: this is _not_ performed in the context of a SIGHUP, it is
96 // performed during startup, and in context of reinit administrative thread
97 LogTimeEntry::lock();
98
99 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800100 while (times != mTimes.end()) {
101 LogTimeEntry* entry = (*times);
Mark Salyzyn552b4752015-11-30 11:35:56 -0800102 if (entry->owned_Locked()) {
103 entry->triggerReader_Locked();
Mark Salyzyn2b4a7632015-09-08 08:56:32 -0700104 }
Mark Salyzyn552b4752015-11-30 11:35:56 -0800105 times++;
Mark Salyzyn2b4a7632015-09-08 08:56:32 -0700106 }
Mark Salyzyn552b4752015-11-30 11:35:56 -0800107
108 LogTimeEntry::unlock();
Mark Salyzyn12bac902014-02-26 09:50:16 -0800109}
110
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800111LogBuffer::LogBuffer(LastLogTimes* times)
112 : monotonic(android_log_clockid() == CLOCK_MONOTONIC), mTimes(*times) {
Mark Salyzyn3fe25932015-03-10 16:45:17 -0700113 pthread_mutex_init(&mLogElementsLock, NULL);
114
Mark Salyzyn2456d042016-12-13 10:31:29 -0800115 log_id_for_each(i) {
116 lastLoggedElements[i] = NULL;
117 droppedElements[i] = NULL;
118 }
119
Mark Salyzyn3fe25932015-03-10 16:45:17 -0700120 init();
121}
122
Mark Salyzyn2456d042016-12-13 10:31:29 -0800123LogBuffer::~LogBuffer() {
124 log_id_for_each(i) {
125 delete lastLoggedElements[i];
126 delete droppedElements[i];
127 }
128}
129
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800130enum match_type { DIFFERENT, SAME, SAME_LIBLOG };
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800131
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800132static enum match_type identical(LogBufferElement* elem,
133 LogBufferElement* last) {
Mark Salyzyn2456d042016-12-13 10:31:29 -0800134 // is it mostly identical?
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800135 // if (!elem) return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800136 unsigned short lenl = elem->getMsgLen();
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800137 if (!lenl) return DIFFERENT;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800138 // if (!last) return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800139 unsigned short lenr = last->getMsgLen();
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800140 if (!lenr) return DIFFERENT;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800141 // if (elem->getLogId() != last->getLogId()) return DIFFERENT;
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800142 if (elem->getUid() != last->getUid()) return DIFFERENT;
143 if (elem->getPid() != last->getPid()) return DIFFERENT;
144 if (elem->getTid() != last->getTid()) return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800145
146 // last is more than a minute old, stop squashing identical messages
147 if (elem->getRealTime().nsec() >
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800148 (last->getRealTime().nsec() + 60 * NS_PER_SEC))
149 return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800150
151 // Identical message
152 const char* msgl = elem->getMsg();
153 const char* msgr = last->getMsg();
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800154 if (lenl == lenr) {
155 if (!fastcmp<memcmp>(msgl, msgr, lenl)) return SAME;
156 // liblog tagged messages (content gets summed)
157 if ((elem->getLogId() == LOG_ID_EVENTS) &&
158 (lenl == sizeof(android_log_event_int_t)) &&
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800159 !fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_int_t) -
160 sizeof(int32_t)) &&
161 (elem->getTag() == LIBLOG_LOG_TAG))
162 return SAME_LIBLOG;
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800163 }
Mark Salyzyn2456d042016-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 Salyzynda65bcb2017-03-10 14:31:54 -0800169 if (fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_string_t) -
170 sizeof(int32_t)))
171 return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800172 msgl += sizeof(android_log_event_string_t);
173 lenl -= sizeof(android_log_event_string_t);
174 msgr += sizeof(android_log_event_string_t);
175 lenr -= sizeof(android_log_event_string_t);
176 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800177 const char* avcl = android::strnstr(msgl, lenl, avc);
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800178 if (!avcl) return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800179 lenl -= avcl - msgl;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800180 const char* avcr = android::strnstr(msgr, lenr, avc);
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800181 if (!avcr) return DIFFERENT;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800182 lenr -= avcr - msgr;
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800183 if (lenl != lenr) return DIFFERENT;
Evgenii Stepanov77e48b62017-03-14 14:47:25 -0700184 // TODO: After b/35468874 is addressed, revisit "lenl > strlen(avc)"
185 // condition, it might become superflous.
186 if (lenl > strlen(avc) &&
187 fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc),
188 lenl - strlen(avc))) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800189 return DIFFERENT;
Evgenii Stepanov77e48b62017-03-14 14:47:25 -0700190 }
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800191 return SAME;
Mark Salyzyn2456d042016-12-13 10:31:29 -0800192}
193
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800194int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
195 pid_t tid, const char* msg, unsigned short len) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800196 if ((log_id >= LOG_ID_MAX) || (log_id < 0)) {
Mark Salyzyn88fe7cc2015-02-09 08:21:05 -0800197 return -EINVAL;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800198 }
Mark Salyzyn19c91112014-10-02 13:07:05 -0700199
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800200 LogBufferElement* elem =
201 new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len);
Mark Salyzyn4a8d2502016-01-06 21:17:43 +0000202 if (log_id != LOG_ID_SECURITY) {
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800203 int prio = ANDROID_LOG_INFO;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800204 const char* tag = NULL;
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800205 if (log_id == LOG_ID_EVENTS) {
Mark Salyzyndb9d0f62016-09-12 14:51:54 -0700206 tag = tagToName(elem->getTag());
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800207 } else {
208 prio = *msg;
209 tag = msg + 1;
210 }
Mark Salyzyndb9d0f62016-09-12 14:51:54 -0700211 if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800212 // Log traffic received to total
213 pthread_mutex_lock(&mLogElementsLock);
214 stats.add(elem);
215 stats.subtract(elem);
216 pthread_mutex_unlock(&mLogElementsLock);
217 delete elem;
218 return -EACCES;
219 }
Mark Salyzyn19c91112014-10-02 13:07:05 -0700220 }
Mark Salyzyn12bac902014-02-26 09:50:16 -0800221
222 pthread_mutex_lock(&mLogElementsLock);
Mark Salyzyn2456d042016-12-13 10:31:29 -0800223 LogBufferElement* currentLast = lastLoggedElements[log_id];
224 if (currentLast) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800225 LogBufferElement* dropped = droppedElements[log_id];
Mark Salyzyn2456d042016-12-13 10:31:29 -0800226 unsigned short count = dropped ? dropped->getDropped() : 0;
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800227 //
228 // State Init
229 // incoming:
230 // dropped = NULL
231 // currentLast = NULL;
232 // elem = incoming message
233 // outgoing:
234 // dropped = NULL -> State 0
235 // currentLast = copy of elem
236 // log elem
237 // State 0
238 // incoming:
239 // count = 0
240 // dropped = NULL
241 // currentLast = copy of last message
242 // elem = incoming message
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800243 // outgoing: if match != DIFFERENT
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800244 // dropped = copy of first identical message -> State 1
245 // currentLast = reference to elem
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800246 // break: if match == DIFFERENT
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800247 // dropped = NULL -> State 0
248 // delete copy of last message (incoming currentLast)
249 // currentLast = copy of elem
250 // log elem
251 // State 1
252 // incoming:
253 // count = 0
254 // dropped = copy of first identical message
255 // currentLast = reference to last held-back incoming
256 // message
257 // elem = incoming message
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800258 // outgoing: if match == SAME
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800259 // delete copy of first identical message (dropped)
260 // dropped = reference to last held-back incoming
261 // message set to chatty count of 1 -> State 2
262 // currentLast = reference to elem
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800263 // outgoing: if match == SAME_LIBLOG
264 // dropped = copy of first identical message -> State 1
265 // take sum of currentLast and elem
266 // if sum overflows:
267 // log currentLast
268 // currentLast = reference to elem
269 // else
270 // delete currentLast
271 // currentLast = reference to elem, sum liblog.
272 // break: if match == DIFFERENT
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800273 // delete dropped
274 // dropped = NULL -> State 0
275 // log reference to last held-back (currentLast)
276 // currentLast = copy of elem
277 // log elem
278 // State 2
279 // incoming:
280 // count = chatty count
281 // dropped = chatty message holding count
282 // currentLast = reference to last held-back incoming
283 // message.
284 // dropped = chatty message holding count
285 // elem = incoming message
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800286 // outgoing: if match != DIFFERENT
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800287 // delete chatty message holding count
288 // dropped = reference to last held-back incoming
289 // message, set to chatty count + 1
290 // currentLast = reference to elem
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800291 // break: if match == DIFFERENT
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800292 // log dropped (chatty message)
293 // dropped = NULL -> State 0
294 // log reference to last held-back (currentLast)
295 // currentLast = copy of elem
296 // log elem
297 //
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800298 enum match_type match = identical(elem, currentLast);
299 if (match != DIFFERENT) {
Mark Salyzyn2456d042016-12-13 10:31:29 -0800300 if (dropped) {
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800301 // Sum up liblog tag messages?
302 if ((count == 0) /* at Pass 1 */ && (match == SAME_LIBLOG)) {
303 android_log_event_int_t* event =
304 reinterpret_cast<android_log_event_int_t*>(
305 const_cast<char*>(currentLast->getMsg()));
306 //
307 // To unit test, differentiate with something like:
308 // event->header.tag = htole32(CHATTY_LOG_TAG);
309 // here, then instead of delete currentLast below,
310 // log(currentLast) to see the incremental sums form.
311 //
312 uint32_t swab = event->payload.data;
313 unsigned long long total = htole32(swab);
314 event = reinterpret_cast<android_log_event_int_t*>(
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800315 const_cast<char*>(elem->getMsg()));
Mark Salyzynedb18aa2016-12-16 16:09:15 -0800316 swab = event->payload.data;
317
318 lastLoggedElements[LOG_ID_EVENTS] = elem;
319 total += htole32(swab);
320 // check for overflow
321 if (total >= UINT32_MAX) {
322 log(currentLast);
323 pthread_mutex_unlock(&mLogElementsLock);
324 return len;
325 }
326 stats.add(currentLast);
327 stats.subtract(currentLast);
328 delete currentLast;
329 swab = total;
330 event->payload.data = htole32(swab);
331 pthread_mutex_unlock(&mLogElementsLock);
332 return len;
333 }
Mark Salyzyn2456d042016-12-13 10:31:29 -0800334 if (count == USHRT_MAX) {
335 log(dropped);
336 count = 1;
337 } else {
338 delete dropped;
339 ++count;
340 }
341 }
342 if (count) {
343 stats.add(currentLast);
344 stats.subtract(currentLast);
345 currentLast->setDropped(count);
346 }
347 droppedElements[log_id] = currentLast;
348 lastLoggedElements[log_id] = elem;
349 pthread_mutex_unlock(&mLogElementsLock);
350 return len;
351 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800352 if (dropped) { // State 1 or 2
353 if (count) { // State 2
354 log(dropped); // report chatty
355 } else { // State 1
356 delete dropped;
Mark Salyzyn9361c0b2016-12-16 16:09:15 -0800357 }
Mark Salyzyn2456d042016-12-13 10:31:29 -0800358 droppedElements[log_id] = NULL;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800359 log(currentLast); // report last message in the series
360 } else { // State 0
Mark Salyzyn2456d042016-12-13 10:31:29 -0800361 delete currentLast;
362 }
363 }
364 lastLoggedElements[log_id] = new LogBufferElement(*elem);
Mark Salyzyn12bac902014-02-26 09:50:16 -0800365
Mark Salyzyn2456d042016-12-13 10:31:29 -0800366 log(elem);
367 pthread_mutex_unlock(&mLogElementsLock);
368
369 return len;
370}
371
372// assumes mLogElementsLock held, owns elem, will look after garbage collection
373void LogBuffer::log(LogBufferElement* elem) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800374 // Insert elements in time sorted order if possible
375 // NB: if end is region locked, place element at end of list
376 LogBufferElementCollection::iterator it = mLogElements.end();
377 LogBufferElementCollection::iterator last = it;
Mark Salyzyn399d5b92017-03-03 10:21:23 -0800378 if (__predict_true(it != mLogElements.begin())) --it;
379 if (__predict_false(it == mLogElements.begin()) ||
380 __predict_true((*it)->getRealTime() <= elem->getRealTime())) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800381 mLogElements.push_back(elem);
382 } else {
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -0800383 uint64_t end = 1;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800384 bool end_set = false;
385 bool end_always = false;
386
387 LogTimeEntry::lock();
388
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700389 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800390 while (times != mTimes.end()) {
Mark Salyzyn2456d042016-12-13 10:31:29 -0800391 LogTimeEntry* entry = (*times);
Mark Salyzyn12bac902014-02-26 09:50:16 -0800392 if (entry->owned_Locked()) {
393 if (!entry->mNonBlock) {
394 end_always = true;
395 break;
396 }
Mark Salyzyn399d5b92017-03-03 10:21:23 -0800397 // it passing mEnd is blocked by the following checks.
Mark Salyzyn12bac902014-02-26 09:50:16 -0800398 if (!end_set || (end <= entry->mEnd)) {
399 end = entry->mEnd;
400 end_set = true;
401 }
402 }
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700403 times++;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800404 }
405
Mark Salyzyn399d5b92017-03-03 10:21:23 -0800406 if (end_always || (end_set && (end > (*it)->getSequence()))) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800407 mLogElements.push_back(elem);
408 } else {
Mark Salyzyn399d5b92017-03-03 10:21:23 -0800409 // should be short as timestamps are localized near end()
410 do {
411 last = it;
412 if (__predict_false(it == mLogElements.begin())) {
413 break;
414 }
415
416 std::swap((*it)->mSequence, elem->mSequence);
417
418 --it;
419 } while (((*it)->getRealTime() > elem->getRealTime()) &&
420 (!end_set || (end <= (*it)->getSequence())));
Mark Salyzyn2456d042016-12-13 10:31:29 -0800421 mLogElements.insert(last, elem);
Mark Salyzyn12bac902014-02-26 09:50:16 -0800422 }
Mark Salyzyn12bac902014-02-26 09:50:16 -0800423 LogTimeEntry::unlock();
424 }
425
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700426 stats.add(elem);
Mark Salyzyn2456d042016-12-13 10:31:29 -0800427 maybePrune(elem->getLogId());
Mark Salyzyn12bac902014-02-26 09:50:16 -0800428}
429
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700430// Prune at most 10% of the log entries or maxPrune, whichever is less.
Mark Salyzyn12bac902014-02-26 09:50:16 -0800431//
432// mLogElementsLock must be held when this function is called.
433void LogBuffer::maybePrune(log_id_t id) {
Mark Salyzynd774bce2014-02-06 14:48:50 -0800434 size_t sizes = stats.sizes(id);
Mark Salyzyn4436d4c2015-08-10 10:23:56 -0700435 unsigned long maxSize = log_buffer_size(id);
436 if (sizes > maxSize) {
Mark Salyzyn63745722015-08-19 12:20:36 -0700437 size_t sizeOver = sizes - ((maxSize * 9) / 10);
Mark Salyzynd745c722015-09-30 07:40:09 -0700438 size_t elements = stats.realElements(id);
439 size_t minElements = elements / 100;
440 if (minElements < minPrune) {
441 minElements = minPrune;
442 }
Mark Salyzyn4436d4c2015-08-10 10:23:56 -0700443 unsigned long pruneRows = elements * sizeOver / sizes;
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700444 if (pruneRows < minElements) {
Mark Salyzyn4436d4c2015-08-10 10:23:56 -0700445 pruneRows = minElements;
Mark Salyzyn9d4e34e2014-01-13 16:37:51 -0800446 }
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700447 if (pruneRows > maxPrune) {
448 pruneRows = maxPrune;
Mark Salyzyn63745722015-08-19 12:20:36 -0700449 }
Mark Salyzyn9d4e34e2014-01-13 16:37:51 -0800450 prune(id, pruneRows);
Mark Salyzyn12bac902014-02-26 09:50:16 -0800451 }
452}
453
Mark Salyzyn57b82a62015-09-03 16:08:50 -0700454LogBufferElementCollection::iterator LogBuffer::erase(
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800455 LogBufferElementCollection::iterator it, bool coalesce) {
456 LogBufferElement* element = *it;
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700457 log_id_t id = element->getLogId();
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700458
Mark Salyzyn628d9372016-10-21 09:46:42 -0700459 // Remove iterator references in the various lists that will become stale
460 // after the element is erased from the main logging list.
461
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800462 { // start of scope for found iterator
463 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
464 ? element->getTag()
465 : element->getUid();
Mark Salyzync572fc62016-07-14 15:34:30 -0700466 LogBufferIteratorMap::iterator found = mLastWorst[id].find(key);
467 if ((found != mLastWorst[id].end()) && (it == found->second)) {
468 mLastWorst[id].erase(found);
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700469 }
Mark Salyzyncfcffdaf2015-08-19 17:06:11 -0700470 }
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700471
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800472 { // start of scope for pid found iterator
Mark Salyzyn628d9372016-10-21 09:46:42 -0700473 // element->getUid() may not be AID_SYSTEM for next-best-watermark.
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700474 // will not assume id != LOG_ID_EVENTS or LOG_ID_SECURITY for KISS and
475 // long term code stability, find() check should be fast for those ids.
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700476 LogBufferPidIteratorMap::iterator found =
477 mLastWorstPidOfSystem[id].find(element->getPid());
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800478 if ((found != mLastWorstPidOfSystem[id].end()) &&
479 (it == found->second)) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700480 mLastWorstPidOfSystem[id].erase(found);
481 }
482 }
483
Mark Salyzynd701b782016-01-19 16:04:41 -0800484 bool setLast[LOG_ID_MAX];
485 bool doSetLast = false;
486 log_id_for_each(i) {
487 doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]);
488 }
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700489#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
490 LogBufferElementCollection::iterator bad = it;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800491 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
492 ? element->getTag()
493 : element->getUid();
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700494#endif
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700495 it = mLogElements.erase(it);
Mark Salyzynd701b782016-01-19 16:04:41 -0800496 if (doSetLast) {
497 log_id_for_each(i) {
498 if (setLast[i]) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800499 if (__predict_false(it == mLogElements.end())) { // impossible
Mark Salyzynd701b782016-01-19 16:04:41 -0800500 mLastSet[i] = false;
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700501 mLast[i] = mLogElements.begin();
Mark Salyzynd701b782016-01-19 16:04:41 -0800502 } else {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800503 mLast[i] = it; // push down the road as next-best-watermark
Mark Salyzynd701b782016-01-19 16:04:41 -0800504 }
505 }
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800506 }
507 }
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700508#ifdef DEBUG_CHECK_FOR_STALE_ENTRIES
509 log_id_for_each(i) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800510 for (auto b : mLastWorst[i]) {
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700511 if (bad == b.second) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800512 android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i,
513 b.first, key);
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700514 }
515 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800516 for (auto b : mLastWorstPidOfSystem[i]) {
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700517 if (bad == b.second) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800518 android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i,
519 b.first);
Mark Salyzyn21fc3932016-10-24 16:22:17 -0700520 }
521 }
522 if (mLastSet[i] && (bad == mLast[i])) {
523 android::prdebug("stale mLast[%d]\n", i);
524 mLastSet[i] = false;
525 mLast[i] = mLogElements.begin();
526 }
527 }
528#endif
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700529 if (coalesce) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700530 stats.erase(element);
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700531 } else {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700532 stats.subtract(element);
Mark Salyzyn57b82a62015-09-03 16:08:50 -0700533 }
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700534 delete element;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700535
536 return it;
537}
538
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700539// Define a temporary mechanism to report the last LogBufferElement pointer
540// for the specified uid, pid and tid. Used below to help merge-sort when
541// pruning for worst UID.
542class LogBufferElementKey {
543 const union {
544 struct {
Mark Salyzync4595602016-12-13 12:44:20 -0800545 uint32_t uid;
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700546 uint16_t pid;
547 uint16_t tid;
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700548 } __packed;
549 uint64_t value;
550 } __packed;
551
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800552 public:
553 LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid)
554 : uid(uid), pid(pid), tid(tid) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700555 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800556 explicit LogBufferElementKey(uint64_t key) : value(key) {
557 }
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700558
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800559 uint64_t getKey() {
560 return value;
561 }
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700562};
563
Mark Salyzyn6a404192015-05-19 09:12:30 -0700564class LogBufferElementLast {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800565 typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap;
Mark Salyzyn6a404192015-05-19 09:12:30 -0700566 LogBufferElementMap map;
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700567
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800568 public:
569 bool coalesce(LogBufferElement* element, unsigned short dropped) {
570 LogBufferElementKey key(element->getUid(), element->getPid(),
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700571 element->getTid());
Mark Salyzyn6a404192015-05-19 09:12:30 -0700572 LogBufferElementMap::iterator it = map.find(key.getKey());
573 if (it != map.end()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800574 LogBufferElement* found = it->second;
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700575 unsigned short moreDropped = found->getDropped();
576 if ((dropped + moreDropped) > USHRT_MAX) {
Mark Salyzyn6a404192015-05-19 09:12:30 -0700577 map.erase(it);
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700578 } else {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700579 found->setDropped(dropped + moreDropped);
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700580 return true;
581 }
582 }
583 return false;
584 }
585
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800586 void add(LogBufferElement* element) {
587 LogBufferElementKey key(element->getUid(), element->getPid(),
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700588 element->getTid());
589 map[key.getKey()] = element;
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700590 }
591
Mark Salyzynbe1a30c2015-04-20 14:08:56 -0700592 inline void clear() {
Mark Salyzyn6a404192015-05-19 09:12:30 -0700593 map.clear();
Mark Salyzynbe1a30c2015-04-20 14:08:56 -0700594 }
595
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800596 void clear(LogBufferElement* element) {
597 uint64_t current =
598 element->getRealTime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC);
599 for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) {
600 LogBufferElement* mapElement = it->second;
601 if ((mapElement->getDropped() >= EXPIRE_THRESHOLD) &&
602 (current > mapElement->getRealTime().nsec())) {
Mark Salyzyn6a404192015-05-19 09:12:30 -0700603 it = map.erase(it);
604 } else {
605 ++it;
Mark Salyzynbe1a30c2015-04-20 14:08:56 -0700606 }
607 }
608 }
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700609};
610
Mark Salyzyn12bac902014-02-26 09:50:16 -0800611// prune "pruneRows" of type "id" from the buffer.
612//
Mark Salyzyn50e21082015-09-08 09:12:51 -0700613// This garbage collection task is used to expire log entries. It is called to
614// remove all logs (clear), all UID logs (unprivileged clear), or every
615// 256 or 10% of the total logs (whichever is less) to prune the logs.
616//
617// First there is a prep phase where we discover the reader region lock that
618// acts as a backstop to any pruning activity to stop there and go no further.
619//
620// There are three major pruning loops that follow. All expire from the oldest
621// entries. Since there are multiple log buffers, the Android logging facility
622// will appear to drop entries 'in the middle' when looking at multiple log
623// sources and buffers. This effect is slightly more prominent when we prune
624// the worst offender by logging source. Thus the logs slowly loose content
625// and value as you move back in time. This is preferred since chatty sources
626// invariably move the logs value down faster as less chatty sources would be
627// expired in the noise.
628//
629// The first loop performs blacklisting and worst offender pruning. Falling
630// through when there are no notable worst offenders and have not hit the
631// region lock preventing further worst offender pruning. This loop also looks
632// after managing the chatty log entries and merging to help provide
633// statistical basis for blame. The chatty entries are not a notification of
634// how much logs you may have, but instead represent how much logs you would
635// have had in a virtual log buffer that is extended to cover all the in-memory
636// logs without loss. They last much longer than the represented pruned logs
637// since they get multiplied by the gains in the non-chatty log sources.
638//
639// The second loop get complicated because an algorithm of watermarks and
640// history is maintained to reduce the order and keep processing time
641// down to a minimum at scale. These algorithms can be costly in the face
642// of larger log buffers, or severly limited processing time granted to a
643// background task at lowest priority.
644//
645// This second loop does straight-up expiration from the end of the logs
646// (again, remember for the specified log buffer id) but does some whitelist
647// preservation. Thus whitelist is a Hail Mary low priority, blacklists and
648// spam filtration all take priority. This second loop also checks if a region
649// lock is causing us to buffer too much in the logs to help the reader(s),
650// and will tell the slowest reader thread to skip log entries, and if
651// persistent and hits a further threshold, kill the reader thread.
652//
653// The third thread is optional, and only gets hit if there was a whitelist
654// and more needs to be pruned against the backstop of the region lock.
655//
Mark Salyzyn12bac902014-02-26 09:50:16 -0800656// mLogElementsLock must be held when this function is called.
Mark Salyzyn50e21082015-09-08 09:12:51 -0700657//
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700658bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800659 LogTimeEntry* oldest = NULL;
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700660 bool busy = false;
Mark Salyzynd280d812015-09-16 15:34:00 -0700661 bool clearAll = pruneRows == ULONG_MAX;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800662
663 LogTimeEntry::lock();
664
665 // Region locked?
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700666 LastLogTimes::iterator times = mTimes.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800667 while (times != mTimes.end()) {
668 LogTimeEntry* entry = (*times);
669 if (entry->owned_Locked() && entry->isWatching(id) &&
670 (!oldest || (oldest->mStart > entry->mStart) ||
671 ((oldest->mStart == entry->mStart) &&
672 (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec)))) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800673 oldest = entry;
674 }
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700675 times++;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800676 }
677
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800678 LogBufferElementCollection::iterator it;
679
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800680 if (__predict_false(caller_uid != AID_ROOT)) { // unlikely
Mark Salyzyn4e23c6e2016-09-01 15:48:36 -0700681 // Only here if clear all request from non system source, so chatty
682 // filter logistics is not required.
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800683 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
684 while (it != mLogElements.end()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800685 LogBufferElement* element = *it;
Mark Salyzyn276d5352014-06-12 11:16:16 -0700686
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800687 if ((element->getLogId() != id) ||
688 (element->getUid() != caller_uid)) {
Mark Salyzynd280d812015-09-16 15:34:00 -0700689 ++it;
690 continue;
691 }
692
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800693 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
694 mLast[id] = it;
695 mLastSet[id] = true;
696 }
697
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700698 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700699 busy = true;
Mark Salyzyn552b4752015-11-30 11:35:56 -0800700 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
701 oldest->triggerReader_Locked();
702 } else {
703 oldest->triggerSkip_Locked(id, pruneRows);
704 }
Mark Salyzyn276d5352014-06-12 11:16:16 -0700705 break;
706 }
707
Mark Salyzynd280d812015-09-16 15:34:00 -0700708 it = erase(it);
Mark Salyzyn4e23c6e2016-09-01 15:48:36 -0700709 if (--pruneRows == 0) {
710 break;
711 }
Mark Salyzyn276d5352014-06-12 11:16:16 -0700712 }
713 LogTimeEntry::unlock();
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700714 return busy;
Mark Salyzyn276d5352014-06-12 11:16:16 -0700715 }
716
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700717 // prune by worst offenders; by blacklist, UID, and by PID of system UID
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800718 bool hasBlacklist = (id != LOG_ID_SECURITY) && mPrune.naughty();
Mark Salyzynd280d812015-09-16 15:34:00 -0700719 while (!clearAll && (pruneRows > 0)) {
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800720 // recalculate the worst offender on every batched pass
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800721 int worst = -1; // not valid for getUid() or getKey()
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800722 size_t worst_sizes = 0;
723 size_t second_worst_sizes = 0;
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800724 pid_t worstPid = 0; // POSIX guarantees PID != 0
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800725
Mark Salyzyn0e765c62015-03-17 17:17:25 -0700726 if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) {
Mark Salyzync572fc62016-07-14 15:34:30 -0700727 // Calculate threshold as 12.5% of available storage
728 size_t threshold = log_buffer_size(id) / 8;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700729
Mark Salyzync572fc62016-07-14 15:34:30 -0700730 if ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800731 stats.sortTags(AID_ROOT, (pid_t)0, 2, id)
732 .findWorst(worst, worst_sizes, second_worst_sizes,
733 threshold);
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700734 // per-pid filter for AID_SYSTEM sources is too complex
Mark Salyzync572fc62016-07-14 15:34:30 -0700735 } else {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800736 stats.sort(AID_ROOT, (pid_t)0, 2, id)
737 .findWorst(worst, worst_sizes, second_worst_sizes,
738 threshold);
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700739
Mark Salyzync572fc62016-07-14 15:34:30 -0700740 if ((worst == AID_SYSTEM) && mPrune.worstPidOfSystemEnabled()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800741 stats.sortPids(worst, (pid_t)0, 2, id)
742 .findWorst(worstPid, worst_sizes, second_worst_sizes);
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700743 }
744 }
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800745 }
746
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700747 // skip if we have neither worst nor naughty filters
Mark Salyzync572fc62016-07-14 15:34:30 -0700748 if ((worst == -1) && !hasBlacklist) {
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700749 break;
750 }
751
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800752 bool kick = false;
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700753 bool leading = true;
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800754 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzyn50e21082015-09-08 09:12:51 -0700755 // Perform at least one mandatory garbage collection cycle in following
756 // - clear leading chatty tags
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700757 // - coalesce chatty tags
Mark Salyzyn50e21082015-09-08 09:12:51 -0700758 // - check age-out of preserved logs
759 bool gc = pruneRows <= 1;
Mark Salyzync572fc62016-07-14 15:34:30 -0700760 if (!gc && (worst != -1)) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800761 { // begin scope for worst found iterator
762 LogBufferIteratorMap::iterator found =
763 mLastWorst[id].find(worst);
764 if ((found != mLastWorst[id].end()) &&
765 (found->second != mLogElements.end())) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700766 leading = false;
767 it = found->second;
768 }
769 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800770 if (worstPid) { // begin scope for pid worst found iterator
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700771 // FYI: worstPid only set if !LOG_ID_EVENTS and
772 // !LOG_ID_SECURITY, not going to make that assumption ...
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800773 LogBufferPidIteratorMap::iterator found =
774 mLastWorstPidOfSystem[id].find(worstPid);
775 if ((found != mLastWorstPidOfSystem[id].end()) &&
776 (found->second != mLogElements.end())) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700777 leading = false;
778 it = found->second;
779 }
Mark Salyzyncfcffdaf2015-08-19 17:06:11 -0700780 }
781 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800782 static const timespec too_old = { EXPIRE_HOUR_THRESHOLD * 60 * 60, 0 };
Mark Salyzyn4e29e172015-08-24 13:43:27 -0700783 LogBufferElementCollection::iterator lastt;
784 lastt = mLogElements.end();
785 --lastt;
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700786 LogBufferElementLast last;
Mark Salyzyncfcffdaf2015-08-19 17:06:11 -0700787 while (it != mLogElements.end()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800788 LogBufferElement* element = *it;
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800789
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700790 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700791 busy = true;
Mark Salyzyn552b4752015-11-30 11:35:56 -0800792 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
793 oldest->triggerReader_Locked();
794 }
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800795 break;
796 }
797
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700798 if (element->getLogId() != id) {
Mark Salyzync89839a2014-02-11 12:29:31 -0800799 ++it;
800 continue;
801 }
Mark Salyzyn628d9372016-10-21 09:46:42 -0700802 // below this point element->getLogId() == id
Mark Salyzync89839a2014-02-11 12:29:31 -0800803
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800804 if (leading && (!mLastSet[id] || ((*mLast[id])->getLogId() != id))) {
805 mLast[id] = it;
806 mLastSet[id] = true;
807 }
808
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700809 unsigned short dropped = element->getDropped();
Mark Salyzync89839a2014-02-11 12:29:31 -0800810
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700811 // remove any leading drops
812 if (leading && dropped) {
813 it = erase(it);
814 continue;
815 }
816
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700817 if (dropped && last.coalesce(element, dropped)) {
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700818 it = erase(it, true);
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700819 continue;
820 }
821
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800822 int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY))
823 ? element->getTag()
824 : element->getUid();
Mark Salyzync572fc62016-07-14 15:34:30 -0700825
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700826 if (hasBlacklist && mPrune.naughty(element)) {
827 last.clear(element);
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700828 it = erase(it);
829 if (dropped) {
830 continue;
831 }
832
833 pruneRows--;
834 if (pruneRows == 0) {
835 break;
836 }
837
Mark Salyzync572fc62016-07-14 15:34:30 -0700838 if (key == worst) {
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700839 kick = true;
840 if (worst_sizes < second_worst_sizes) {
841 break;
842 }
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700843 worst_sizes -= element->getMsgLen();
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700844 }
845 continue;
846 }
847
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800848 if ((element->getRealTime() < ((*lastt)->getRealTime() - too_old)) ||
849 (element->getRealTime() > (*lastt)->getRealTime())) {
Mark Salyzyn4e29e172015-08-24 13:43:27 -0700850 break;
851 }
852
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700853 if (dropped) {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700854 last.add(element);
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800855 if (worstPid &&
856 ((!gc && (element->getPid() == worstPid)) ||
857 (mLastWorstPidOfSystem[id].find(element->getPid()) ==
858 mLastWorstPidOfSystem[id].end()))) {
Mark Salyzyn628d9372016-10-21 09:46:42 -0700859 // element->getUid() may not be AID_SYSTEM, next best
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700860 // watermark if current one empty. id is not LOG_ID_EVENTS
861 // or LOG_ID_SECURITY because of worstPid check.
Mark Salyzyn9faf9082016-09-01 07:28:44 -0700862 mLastWorstPidOfSystem[id][element->getPid()] = it;
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700863 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800864 if ((!gc && !worstPid && (key == worst)) ||
865 (mLastWorst[id].find(key) == mLastWorst[id].end())) {
Mark Salyzync572fc62016-07-14 15:34:30 -0700866 mLastWorst[id][key] = it;
Mark Salyzyncb15c7c2015-08-24 13:43:27 -0700867 }
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800868 ++it;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700869 continue;
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800870 }
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700871
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800872 if ((key != worst) ||
873 (worstPid && (element->getPid() != worstPid))) {
Mark Salyzynfd318a82015-06-01 09:41:19 -0700874 leading = false;
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700875 last.clear(element);
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700876 ++it;
877 continue;
878 }
Mark Salyzyn628d9372016-10-21 09:46:42 -0700879 // key == worst below here
880 // If worstPid set, then element->getPid() == worstPid below here
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700881
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700882 pruneRows--;
883 if (pruneRows == 0) {
884 break;
885 }
886
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700887 kick = true;
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700888
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700889 unsigned short len = element->getMsgLen();
Mark Salyzyn65ec8602015-05-22 10:03:31 -0700890
891 // do not create any leading drops
892 if (leading) {
893 it = erase(it);
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700894 } else {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700895 stats.drop(element);
896 element->setDropped(1);
897 if (last.coalesce(element, 1)) {
Mark Salyzyn95ff2482015-09-30 07:40:09 -0700898 it = erase(it, true);
Mark Salyzyn65ec8602015-05-22 10:03:31 -0700899 } else {
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700900 last.add(element);
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800901 if (worstPid &&
902 (!gc || (mLastWorstPidOfSystem[id].find(worstPid) ==
903 mLastWorstPidOfSystem[id].end()))) {
Mark Salyzyn628d9372016-10-21 09:46:42 -0700904 // element->getUid() may not be AID_SYSTEM, next best
Mark Salyzyn2e86fa42016-10-24 08:20:26 -0700905 // watermark if current one empty. id is not
906 // LOG_ID_EVENTS or LOG_ID_SECURITY because of worstPid.
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700907 mLastWorstPidOfSystem[id][worstPid] = it;
908 }
Mark Salyzync572fc62016-07-14 15:34:30 -0700909 if ((!gc && !worstPid) ||
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800910 (mLastWorst[id].find(worst) == mLastWorst[id].end())) {
Mark Salyzync572fc62016-07-14 15:34:30 -0700911 mLastWorst[id][worst] = it;
Mark Salyzyn50e21082015-09-08 09:12:51 -0700912 }
Mark Salyzyn65ec8602015-05-22 10:03:31 -0700913 ++it;
914 }
Mark Salyzyna69d5a42015-03-16 12:04:09 -0700915 }
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700916 if (worst_sizes < second_worst_sizes) {
917 break;
918 }
919 worst_sizes -= len;
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800920 }
Mark Salyzynd84b27e2015-04-17 15:38:04 -0700921 last.clear();
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800922
Mark Salyzync402bc72014-04-01 17:19:47 -0700923 if (!kick || !mPrune.worstUidEnabled()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800924 break; // the following loop will ask bad clients to skip/drop
Mark Salyzyn5c06ca42014-02-06 18:11:13 -0800925 }
926 }
927
Mark Salyzync89839a2014-02-11 12:29:31 -0800928 bool whitelist = false;
Mark Salyzyn8885daf2015-12-04 10:59:45 -0800929 bool hasWhitelist = (id != LOG_ID_SECURITY) && mPrune.nice() && !clearAll;
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800930 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800931 while ((pruneRows > 0) && (it != mLogElements.end())) {
932 LogBufferElement* element = *it;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700933
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700934 if (element->getLogId() != id) {
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700935 it++;
936 continue;
937 }
938
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800939 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
940 mLast[id] = it;
941 mLastSet[id] = true;
942 }
943
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700944 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700945 busy = true;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700946 if (whitelist) {
Mark Salyzyn12bac902014-02-26 09:50:16 -0800947 break;
948 }
Mark Salyzync402bc72014-04-01 17:19:47 -0700949
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700950 if (stats.sizes(id) > (2 * log_buffer_size(id))) {
951 // kick a misbehaving log reader client off the island
952 oldest->release_Locked();
Mark Salyzyn552b4752015-11-30 11:35:56 -0800953 } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
954 oldest->triggerReader_Locked();
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700955 } else {
956 oldest->triggerSkip_Locked(id, pruneRows);
Mark Salyzync89839a2014-02-11 12:29:31 -0800957 }
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700958 break;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800959 }
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700960
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700961 if (hasWhitelist && !element->getDropped() && mPrune.nice(element)) {
962 // WhiteListed
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700963 whitelist = true;
964 it++;
965 continue;
966 }
967
968 it = erase(it);
969 pruneRows--;
Mark Salyzyn12bac902014-02-26 09:50:16 -0800970 }
971
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700972 // Do not save the whitelist if we are reader range limited
Mark Salyzync89839a2014-02-11 12:29:31 -0800973 if (whitelist && (pruneRows > 0)) {
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800974 it = mLastSet[id] ? mLast[id] : mLogElements.begin();
Mark Salyzynda65bcb2017-03-10 14:31:54 -0800975 while ((it != mLogElements.end()) && (pruneRows > 0)) {
976 LogBufferElement* element = *it;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700977
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700978 if (element->getLogId() != id) {
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700979 ++it;
980 continue;
Mark Salyzync89839a2014-02-11 12:29:31 -0800981 }
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700982
Mark Salyzyn7a3c2822016-01-11 10:58:09 -0800983 if (!mLastSet[id] || ((*mLast[id])->getLogId() != id)) {
984 mLast[id] = it;
985 mLastSet[id] = true;
986 }
987
Mark Salyzyn538c6a92015-08-28 08:02:59 -0700988 if (oldest && (oldest->mStart <= element->getSequence())) {
Mark Salyzyn7702c3e2015-09-16 15:34:00 -0700989 busy = true;
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700990 if (stats.sizes(id) > (2 * log_buffer_size(id))) {
991 // kick a misbehaving log reader client off the island
992 oldest->release_Locked();
Mark Salyzyn552b4752015-11-30 11:35:56 -0800993 } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
994 oldest->triggerReader_Locked();
Mark Salyzyn9cf5d402015-03-10 13:51:35 -0700995 } else {
996 oldest->triggerSkip_Locked(id, pruneRows);
997 }
998 break;
999 }
1000
1001 it = erase(it);
1002 pruneRows--;
Mark Salyzync89839a2014-02-11 12:29:31 -08001003 }
1004 }
Mark Salyzync89839a2014-02-11 12:29:31 -08001005
Mark Salyzyn12bac902014-02-26 09:50:16 -08001006 LogTimeEntry::unlock();
Mark Salyzyn7702c3e2015-09-16 15:34:00 -07001007
1008 return (pruneRows > 0) && busy;
Mark Salyzyn12bac902014-02-26 09:50:16 -08001009}
1010
1011// clear all rows of type "id" from the buffer.
Mark Salyzyn7702c3e2015-09-16 15:34:00 -07001012bool LogBuffer::clear(log_id_t id, uid_t uid) {
1013 bool busy = true;
1014 // If it takes more than 4 tries (seconds) to clear, then kill reader(s)
1015 for (int retry = 4;;) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001016 if (retry == 1) { // last pass
Mark Salyzyn7702c3e2015-09-16 15:34:00 -07001017 // Check if it is still busy after the sleep, we say prune
1018 // one entry, not another clear run, so we are looking for
1019 // the quick side effect of the return value to tell us if
1020 // we have a _blocked_ reader.
1021 pthread_mutex_lock(&mLogElementsLock);
1022 busy = prune(id, 1, uid);
1023 pthread_mutex_unlock(&mLogElementsLock);
1024 // It is still busy, blocked reader(s), lets kill them all!
1025 // otherwise, lets be a good citizen and preserve the slow
1026 // readers and let the clear run (below) deal with determining
1027 // if we are still blocked and return an error code to caller.
1028 if (busy) {
1029 LogTimeEntry::lock();
1030 LastLogTimes::iterator times = mTimes.begin();
1031 while (times != mTimes.end()) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001032 LogTimeEntry* entry = (*times);
Mark Salyzyn7702c3e2015-09-16 15:34:00 -07001033 // Killer punch
1034 if (entry->owned_Locked() && entry->isWatching(id)) {
1035 entry->release_Locked();
1036 }
1037 times++;
1038 }
1039 LogTimeEntry::unlock();
1040 }
1041 }
1042 pthread_mutex_lock(&mLogElementsLock);
1043 busy = prune(id, ULONG_MAX, uid);
1044 pthread_mutex_unlock(&mLogElementsLock);
1045 if (!busy || !--retry) {
1046 break;
1047 }
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001048 sleep(1); // Let reader(s) catch up after notification
Mark Salyzyn7702c3e2015-09-16 15:34:00 -07001049 }
1050 return busy;
Mark Salyzyn12bac902014-02-26 09:50:16 -08001051}
1052
1053// get the used space associated with "id".
1054unsigned long LogBuffer::getSizeUsed(log_id_t id) {
1055 pthread_mutex_lock(&mLogElementsLock);
Mark Salyzynd774bce2014-02-06 14:48:50 -08001056 size_t retval = stats.sizes(id);
Mark Salyzyn12bac902014-02-26 09:50:16 -08001057 pthread_mutex_unlock(&mLogElementsLock);
1058 return retval;
1059}
1060
Mark Salyzync89839a2014-02-11 12:29:31 -08001061// set the total space allocated to "id"
1062int LogBuffer::setSize(log_id_t id, unsigned long size) {
1063 // Reasonable limits ...
Mark Salyzynf4693f32016-09-27 13:08:23 -07001064 if (!__android_logger_valid_buffer_size(size)) {
Mark Salyzync89839a2014-02-11 12:29:31 -08001065 return -1;
1066 }
1067 pthread_mutex_lock(&mLogElementsLock);
1068 log_buffer_size(id) = size;
1069 pthread_mutex_unlock(&mLogElementsLock);
1070 return 0;
1071}
1072
1073// get the total space allocated to "id"
1074unsigned long LogBuffer::getSize(log_id_t id) {
1075 pthread_mutex_lock(&mLogElementsLock);
1076 size_t retval = log_buffer_size(id);
1077 pthread_mutex_unlock(&mLogElementsLock);
1078 return retval;
1079}
1080
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001081uint64_t LogBuffer::flushTo(
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001082 SocketClient* reader, const uint64_t start, bool privileged, bool security,
1083 int (*filter)(const LogBufferElement* element, void* arg), void* arg) {
Mark Salyzyn12bac902014-02-26 09:50:16 -08001084 LogBufferElementCollection::iterator it;
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001085 uint64_t max = start;
Mark Salyzyn12bac902014-02-26 09:50:16 -08001086 uid_t uid = reader->getUid();
1087
1088 pthread_mutex_lock(&mLogElementsLock);
Dragoslav Mitrinovic81624f22015-01-15 09:29:43 -06001089
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001090 if (start <= 1) {
Dragoslav Mitrinovic81624f22015-01-15 09:29:43 -06001091 // client wants to start from the beginning
1092 it = mLogElements.begin();
1093 } else {
1094 // Client wants to start from some specified time. Chances are
1095 // we are better off starting from the end of the time sorted list.
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001096 for (it = mLogElements.end(); it != mLogElements.begin();
1097 /* do nothing */) {
Dragoslav Mitrinovic81624f22015-01-15 09:29:43 -06001098 --it;
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001099 LogBufferElement* element = *it;
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001100 if (element->getSequence() <= start) {
Dragoslav Mitrinovic81624f22015-01-15 09:29:43 -06001101 it++;
1102 break;
1103 }
1104 }
1105 }
1106
Mark Salyzyn99a671a2017-01-23 14:20:31 -08001107 // Help detect if the valid message before is from the same source so
1108 // we can differentiate chatty filter types.
1109 pid_t lastTid[LOG_ID_MAX] = { 0 };
1110
Dragoslav Mitrinovic81624f22015-01-15 09:29:43 -06001111 for (; it != mLogElements.end(); ++it) {
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001112 LogBufferElement* element = *it;
Mark Salyzyn12bac902014-02-26 09:50:16 -08001113
1114 if (!privileged && (element->getUid() != uid)) {
1115 continue;
1116 }
1117
Mark Salyzyn924c0b32016-01-26 14:32:35 -08001118 if (!security && (element->getLogId() == LOG_ID_SECURITY)) {
1119 continue;
1120 }
1121
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001122 if (element->getSequence() <= start) {
Mark Salyzyn12bac902014-02-26 09:50:16 -08001123 continue;
1124 }
1125
1126 // NB: calling out to another object with mLogElementsLock held (safe)
Mark Salyzyn0aaf6cd2015-03-03 13:39:37 -08001127 if (filter) {
1128 int ret = (*filter)(element, arg);
1129 if (ret == false) {
1130 continue;
1131 }
1132 if (ret != true) {
1133 break;
1134 }
Mark Salyzyn12bac902014-02-26 09:50:16 -08001135 }
1136
Mark Salyzyn99a671a2017-01-23 14:20:31 -08001137 bool sameTid = lastTid[element->getLogId()] == element->getTid();
1138 // Dropped (chatty) immediately following a valid log from the
1139 // same source in the same log buffer indicates we have a
1140 // multiple identical squash. chatty that differs source
1141 // is due to spam filter. chatty to chatty of different
1142 // source is also due to spam filter.
Mark Salyzynda65bcb2017-03-10 14:31:54 -08001143 lastTid[element->getLogId()] =
1144 (element->getDropped() && !sameTid) ? 0 : element->getTid();
Mark Salyzyn99a671a2017-01-23 14:20:31 -08001145
Mark Salyzyn12bac902014-02-26 09:50:16 -08001146 pthread_mutex_unlock(&mLogElementsLock);
1147
1148 // range locking in LastLogTimes looks after us
Mark Salyzyn99a671a2017-01-23 14:20:31 -08001149 max = element->flushTo(reader, this, privileged, sameTid);
Mark Salyzyn12bac902014-02-26 09:50:16 -08001150
1151 if (max == element->FLUSH_ERROR) {
1152 return max;
1153 }
1154
1155 pthread_mutex_lock(&mLogElementsLock);
1156 }
1157 pthread_mutex_unlock(&mLogElementsLock);
1158
1159 return max;
1160}
Mark Salyzynd774bce2014-02-06 14:48:50 -08001161
Mark Salyzynb921ab52015-12-17 09:58:43 -08001162std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid,
1163 unsigned int logMask) {
Mark Salyzynd774bce2014-02-06 14:48:50 -08001164 pthread_mutex_lock(&mLogElementsLock);
1165
Mark Salyzynb921ab52015-12-17 09:58:43 -08001166 std::string ret = stats.format(uid, pid, logMask);
Mark Salyzynd774bce2014-02-06 14:48:50 -08001167
1168 pthread_mutex_unlock(&mLogElementsLock);
Mark Salyzyn1c7b6fb2015-08-20 10:01:44 -07001169
1170 return ret;
Mark Salyzynd774bce2014-02-06 14:48:50 -08001171}