Loading logd/CommandListener.cpp +4 −4 Original line number Original line Diff line number Diff line Loading @@ -74,9 +74,9 @@ static void setname() { int CommandListener::ClearCmd::runCommand(SocketClient *cli, int CommandListener::ClearCmd::runCommand(SocketClient *cli, int argc, char **argv) { int argc, char **argv) { setname(); setname(); if (!clientHasLogCredentials(cli)) { uid_t uid = cli->getUid(); cli->sendMsg("Permission Denied"); if (clientHasLogCredentials(cli)) { return 0; uid = AID_ROOT; } } if (argc < 2) { if (argc < 2) { Loading @@ -90,7 +90,7 @@ int CommandListener::ClearCmd::runCommand(SocketClient *cli, return 0; return 0; } } mBuf.clear((log_id_t) id); mBuf.clear((log_id_t) id, uid); cli->sendMsg("success"); cli->sendMsg("success"); return 0; return 0; } } Loading logd/LogBuffer.cpp +35 −3 Original line number Original line Diff line number Diff line Loading @@ -232,7 +232,7 @@ void LogBuffer::maybePrune(log_id_t id) { // prune "pruneRows" of type "id" from the buffer. // prune "pruneRows" of type "id" from the buffer. // // // mLogElementsLock must be held when this function is called. // 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 *oldest = NULL; LogTimeEntry::lock(); LogTimeEntry::lock(); Loading @@ -250,6 +250,38 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { LogBufferElementCollection::iterator it; 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 // prune by worst offender by uid while (pruneRows > 0) { while (pruneRows > 0) { // recalculate the worst offender on every batched pass // recalculate the worst offender on every batched pass Loading Loading @@ -375,9 +407,9 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { } } // clear all rows of type "id" from the buffer. // 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); pthread_mutex_lock(&mLogElementsLock); prune(id, ULONG_MAX); prune(id, ULONG_MAX, uid); pthread_mutex_unlock(&mLogElementsLock); pthread_mutex_unlock(&mLogElementsLock); } } Loading logd/LogBuffer.h +4 −2 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <sysutils/SocketClient.h> #include <sysutils/SocketClient.h> #include <utils/List.h> #include <utils/List.h> #include <private/android_filesystem_config.h> #include "LogBufferElement.h" #include "LogBufferElement.h" #include "LogTimes.h" #include "LogTimes.h" #include "LogStatistics.h" #include "LogStatistics.h" Loading Loading @@ -55,7 +57,7 @@ public: bool (*filter)(const LogBufferElement *element, void *arg) = NULL, bool (*filter)(const LogBufferElement *element, void *arg) = NULL, 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); unsigned long getSize(log_id_t id); int setSize(log_id_t id, unsigned long size); int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); unsigned long getSizeUsed(log_id_t id); Loading @@ -77,7 +79,7 @@ public: private: private: void maybePrune(log_id_t id); 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); }; }; Loading Loading
logd/CommandListener.cpp +4 −4 Original line number Original line Diff line number Diff line Loading @@ -74,9 +74,9 @@ static void setname() { int CommandListener::ClearCmd::runCommand(SocketClient *cli, int CommandListener::ClearCmd::runCommand(SocketClient *cli, int argc, char **argv) { int argc, char **argv) { setname(); setname(); if (!clientHasLogCredentials(cli)) { uid_t uid = cli->getUid(); cli->sendMsg("Permission Denied"); if (clientHasLogCredentials(cli)) { return 0; uid = AID_ROOT; } } if (argc < 2) { if (argc < 2) { Loading @@ -90,7 +90,7 @@ int CommandListener::ClearCmd::runCommand(SocketClient *cli, return 0; return 0; } } mBuf.clear((log_id_t) id); mBuf.clear((log_id_t) id, uid); cli->sendMsg("success"); cli->sendMsg("success"); return 0; return 0; } } Loading
logd/LogBuffer.cpp +35 −3 Original line number Original line Diff line number Diff line Loading @@ -232,7 +232,7 @@ void LogBuffer::maybePrune(log_id_t id) { // prune "pruneRows" of type "id" from the buffer. // prune "pruneRows" of type "id" from the buffer. // // // mLogElementsLock must be held when this function is called. // 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 *oldest = NULL; LogTimeEntry::lock(); LogTimeEntry::lock(); Loading @@ -250,6 +250,38 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { LogBufferElementCollection::iterator it; 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 // prune by worst offender by uid while (pruneRows > 0) { while (pruneRows > 0) { // recalculate the worst offender on every batched pass // recalculate the worst offender on every batched pass Loading Loading @@ -375,9 +407,9 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { } } // clear all rows of type "id" from the buffer. // 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); pthread_mutex_lock(&mLogElementsLock); prune(id, ULONG_MAX); prune(id, ULONG_MAX, uid); pthread_mutex_unlock(&mLogElementsLock); pthread_mutex_unlock(&mLogElementsLock); } } Loading
logd/LogBuffer.h +4 −2 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <sysutils/SocketClient.h> #include <sysutils/SocketClient.h> #include <utils/List.h> #include <utils/List.h> #include <private/android_filesystem_config.h> #include "LogBufferElement.h" #include "LogBufferElement.h" #include "LogTimes.h" #include "LogTimes.h" #include "LogStatistics.h" #include "LogStatistics.h" Loading Loading @@ -55,7 +57,7 @@ public: bool (*filter)(const LogBufferElement *element, void *arg) = NULL, bool (*filter)(const LogBufferElement *element, void *arg) = NULL, 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); unsigned long getSize(log_id_t id); int setSize(log_id_t id, unsigned long size); int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); unsigned long getSizeUsed(log_id_t id); Loading @@ -77,7 +79,7 @@ public: private: private: void maybePrune(log_id_t id); 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); }; }; Loading