summaryrefslogtreecommitdiffstats
path: root/logd/LogBuffer.cpp
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-06-12 11:16:16 -0700
committerMark Salyzyn <salyzyn@google.com>2014-06-13 08:06:14 -0700
commit1a240b47903c0dc3d7f23b609b6520f17f11b953 (patch)
tree62ee2f447e067464c65e9f6a4fe272037faffd67 /logd/LogBuffer.cpp
parent7fa1cd19638c8ada0786e03abe50b5fe9b9f4270 (diff)
downloadsystem_core-1a240b47903c0dc3d7f23b609b6520f17f11b953.zip
system_core-1a240b47903c0dc3d7f23b609b6520f17f11b953.tar.gz
system_core-1a240b47903c0dc3d7f23b609b6520f17f11b953.tar.bz2
logd: Allow apps to clear their UID-specific data
Bug: 13501501 Change-Id: Ia72e25fc19430ce63fb359cd9b3f0523d41f5aa8
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r--logd/LogBuffer.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 0448afa..cd9ea20 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -232,7 +232,7 @@ void LogBuffer::maybePrune(log_id_t id) {
// prune "pruneRows" of type "id" from the buffer.
//
// mLogElementsLock must be held when this function is called.
-void LogBuffer::prune(log_id_t id, unsigned long pruneRows) {
+void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
LogTimeEntry *oldest = NULL;
LogTimeEntry::lock();
@@ -250,6 +250,38 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) {
LogBufferElementCollection::iterator it;
+ if (caller_uid != AID_ROOT) {
+ for(it = mLogElements.begin(); it != mLogElements.end();) {
+ LogBufferElement *e = *it;
+
+ if (oldest && (oldest->mStart <= e->getMonotonicTime())) {
+ break;
+ }
+
+ if (e->getLogId() != id) {
+ ++it;
+ continue;
+ }
+
+ uid_t uid = e->getUid();
+
+ if (uid == caller_uid) {
+ it = mLogElements.erase(it);
+ unsigned short len = e->getMsgLen();
+ stats.subtract(len, id, uid, e->getPid());
+ delete e;
+ pruneRows--;
+ if (pruneRows == 0) {
+ break;
+ }
+ } else {
+ ++it;
+ }
+ }
+ LogTimeEntry::unlock();
+ return;
+ }
+
// prune by worst offender by uid
while (pruneRows > 0) {
// recalculate the worst offender on every batched pass
@@ -375,9 +407,9 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) {
}
// clear all rows of type "id" from the buffer.
-void LogBuffer::clear(log_id_t id) {
+void LogBuffer::clear(log_id_t id, uid_t uid) {
pthread_mutex_lock(&mLogElementsLock);
- prune(id, ULONG_MAX);
+ prune(id, ULONG_MAX, uid);
pthread_mutex_unlock(&mLogElementsLock);
}