summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-06-18 21:09:34 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-18 21:09:34 +0000
commite53714bf59db13d0e0cd6f4b0c5361fd49697abe (patch)
treeb183b5cff189da2ef5f88f24e829c27a7fffa8bd
parent722e859dec25b97e6d535ebfc545e78d0b2acc0c (diff)
parent2757d76cd6f0b0c0560751f5e8b9c2656692ffa9 (diff)
downloadsystem_core-e53714bf59db13d0e0cd6f4b0c5361fd49697abe.zip
system_core-e53714bf59db13d0e0cd6f4b0c5361fd49697abe.tar.gz
system_core-e53714bf59db13d0e0cd6f4b0c5361fd49697abe.tar.bz2
am 2757d76c: am deae968a: am 4da93e34: Merge "logd: Allow apps to clear their UID-specific data"
* commit '2757d76cd6f0b0c0560751f5e8b9c2656692ffa9': logd: Allow apps to clear their UID-specific data
-rw-r--r--logd/CommandListener.cpp8
-rw-r--r--logd/LogBuffer.cpp38
-rw-r--r--logd/LogBuffer.h6
3 files changed, 43 insertions, 9 deletions
diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp
index 9d7d152..d7088b4 100644
--- a/logd/CommandListener.cpp
+++ b/logd/CommandListener.cpp
@@ -74,9 +74,9 @@ static void setname() {
int CommandListener::ClearCmd::runCommand(SocketClient *cli,
int argc, char **argv) {
setname();
- if (!clientHasLogCredentials(cli)) {
- cli->sendMsg("Permission Denied");
- return 0;
+ uid_t uid = cli->getUid();
+ if (clientHasLogCredentials(cli)) {
+ uid = AID_ROOT;
}
if (argc < 2) {
@@ -90,7 +90,7 @@ int CommandListener::ClearCmd::runCommand(SocketClient *cli,
return 0;
}
- mBuf.clear((log_id_t) id);
+ mBuf.clear((log_id_t) id, uid);
cli->sendMsg("success");
return 0;
}
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);
}
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index b8a54b9..4b982a8 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -23,6 +23,8 @@
#include <sysutils/SocketClient.h>
#include <utils/List.h>
+#include <private/android_filesystem_config.h>
+
#include "LogBufferElement.h"
#include "LogTimes.h"
#include "LogStatistics.h"
@@ -55,7 +57,7 @@ public:
bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
void *arg = NULL);
- void clear(log_id_t id);
+ void clear(log_id_t id, uid_t uid = AID_ROOT);
unsigned long getSize(log_id_t id);
int setSize(log_id_t id, unsigned long size);
unsigned long getSizeUsed(log_id_t id);
@@ -77,7 +79,7 @@ public:
private:
void maybePrune(log_id_t id);
- void prune(log_id_t id, unsigned long pruneRows);
+ void prune(log_id_t id, unsigned long pruneRows, uid_t uid = AID_ROOT);
};