Loading logd/FlushCommand.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ FlushCommand::FlushCommand(LogReader &reader, unsigned long tail, unsigned int logMask, pid_t pid, log_time start) uint64_t start) : mReader(reader) , mNonBlock(nonBlock) , mTail(tail) Loading logd/FlushCommand.h +2 −2 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ class FlushCommand : public SocketClientCommand { unsigned long mTail; unsigned int mLogMask; pid_t mPid; log_time mStart; uint64_t mStart; public: FlushCommand(LogReader &mReader, Loading @@ -39,7 +39,7 @@ public: unsigned long tail = -1, unsigned int logMask = -1, pid_t pid = 0, log_time start = LogTimeEntry::EPOCH); uint64_t start = 1); virtual void runSocketCommand(SocketClient *client); static bool hasReadLogs(SocketClient *client); Loading logd/LogBuffer.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, if (last == mLogElements.end()) { mLogElements.push_back(elem); } else { log_time end = log_time::EPOCH; uint64_t end = 1; bool end_set = false; bool end_always = false; Loading @@ -184,7 +184,7 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, } if (end_always || (end_set && (end >= (*last)->getMonotonicTime()))) { || (end_set && (end >= (*last)->getSequence()))) { mLogElements.push_back(elem); } else { mLogElements.insert(last,elem); Loading Loading @@ -241,7 +241,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { for(it = mLogElements.begin(); it != mLogElements.end();) { LogBufferElement *e = *it; if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { break; } Loading Loading @@ -293,7 +293,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { for(it = mLogElements.begin(); it != mLogElements.end();) { LogBufferElement *e = *it; if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { break; } Loading Loading @@ -334,7 +334,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { while((pruneRows > 0) && (it != mLogElements.end())) { LogBufferElement *e = *it; if (e->getLogId() == id) { if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { if (!whitelist) { if (stats.sizes(id) > (2 * log_buffer_size(id))) { // kick a misbehaving log reader client off the island Loading Loading @@ -366,7 +366,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { while((it != mLogElements.end()) && (pruneRows > 0)) { LogBufferElement *e = *it; if (e->getLogId() == id) { if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { if (stats.sizes(id) > (2 * log_buffer_size(id))) { // kick a misbehaving log reader client off the island oldest->release_Locked(); Loading Loading @@ -423,16 +423,16 @@ unsigned long LogBuffer::getSize(log_id_t id) { return retval; } log_time LogBuffer::flushTo( SocketClient *reader, const log_time start, bool privileged, bool (*filter)(const LogBufferElement *element, void *arg), void *arg) { uint64_t LogBuffer::flushTo( SocketClient *reader, const uint64_t start, bool privileged, int (*filter)(const LogBufferElement *element, void *arg), void *arg) { LogBufferElementCollection::iterator it; log_time max = start; uint64_t max = start; uid_t uid = reader->getUid(); pthread_mutex_lock(&mLogElementsLock); if (start == LogTimeEntry::EPOCH) { if (start <= 1) { // client wants to start from the beginning it = mLogElements.begin(); } else { Loading @@ -441,7 +441,7 @@ log_time LogBuffer::flushTo( for (it = mLogElements.end(); it != mLogElements.begin(); /* do nothing */) { --it; LogBufferElement *element = *it; if (element->getMonotonicTime() <= start) { if (element->getSequence() <= start) { it++; break; } Loading @@ -455,14 +455,20 @@ log_time LogBuffer::flushTo( continue; } if (element->getMonotonicTime() <= start) { if (element->getSequence() <= start) { continue; } // NB: calling out to another object with mLogElementsLock held (safe) if (filter && !(*filter)(element, arg)) { if (filter) { int ret = (*filter)(element, arg); if (ret == false) { continue; } if (ret != true) { break; } } pthread_mutex_unlock(&mLogElementsLock); Loading @@ -481,7 +487,7 @@ log_time LogBuffer::flushTo( } void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { log_time oldest(CLOCK_MONOTONIC); uint64_t oldest = UINT64_MAX; pthread_mutex_lock(&mLogElementsLock); Loading @@ -491,7 +497,7 @@ void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { LogBufferElement *element = *it; if ((logMask & (1 << element->getLogId()))) { oldest = element->getMonotonicTime(); oldest = element->getSequence(); break; } } Loading logd/LogBuffer.h +2 −2 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public: void log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len); log_time flushTo(SocketClient *writer, const log_time start, uint64_t flushTo(SocketClient *writer, const uint64_t start, bool privileged, bool (*filter)(const LogBufferElement *element, void *arg) = NULL, int (*filter)(const LogBufferElement *element, void *arg) = NULL, void *arg = NULL); void clear(log_id_t id, uid_t uid = AID_ROOT); Loading logd/LogBufferElement.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ #include "LogBufferElement.h" #include "LogReader.h" const log_time LogBufferElement::FLUSH_ERROR((uint32_t)0, (uint32_t)0); const uint64_t LogBufferElement::FLUSH_ERROR(0); atomic_int_fast64_t LogBufferElement::sequence; LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, Loading @@ -34,7 +35,7 @@ LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, , mPid(pid) , mTid(tid) , mMsgLen(len) , mMonotonicTime(CLOCK_MONOTONIC) , mSequence(sequence.fetch_add(1, memory_order_relaxed)) , mRealTime(realtime) { mMsg = new char[len]; memcpy(mMsg, msg, len); Loading @@ -44,7 +45,7 @@ LogBufferElement::~LogBufferElement() { delete [] mMsg; } log_time LogBufferElement::flushTo(SocketClient *reader) { uint64_t LogBufferElement::flushTo(SocketClient *reader) { struct logger_entry_v3 entry; memset(&entry, 0, sizeof(struct logger_entry_v3)); entry.hdr_size = sizeof(struct logger_entry_v3); Loading @@ -64,5 +65,5 @@ log_time LogBufferElement::flushTo(SocketClient *reader) { return FLUSH_ERROR; } return mMonotonicTime; return mSequence; } Loading
logd/FlushCommand.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ FlushCommand::FlushCommand(LogReader &reader, unsigned long tail, unsigned int logMask, pid_t pid, log_time start) uint64_t start) : mReader(reader) , mNonBlock(nonBlock) , mTail(tail) Loading
logd/FlushCommand.h +2 −2 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ class FlushCommand : public SocketClientCommand { unsigned long mTail; unsigned int mLogMask; pid_t mPid; log_time mStart; uint64_t mStart; public: FlushCommand(LogReader &mReader, Loading @@ -39,7 +39,7 @@ public: unsigned long tail = -1, unsigned int logMask = -1, pid_t pid = 0, log_time start = LogTimeEntry::EPOCH); uint64_t start = 1); virtual void runSocketCommand(SocketClient *client); static bool hasReadLogs(SocketClient *client); Loading
logd/LogBuffer.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, if (last == mLogElements.end()) { mLogElements.push_back(elem); } else { log_time end = log_time::EPOCH; uint64_t end = 1; bool end_set = false; bool end_always = false; Loading @@ -184,7 +184,7 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, } if (end_always || (end_set && (end >= (*last)->getMonotonicTime()))) { || (end_set && (end >= (*last)->getSequence()))) { mLogElements.push_back(elem); } else { mLogElements.insert(last,elem); Loading Loading @@ -241,7 +241,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { for(it = mLogElements.begin(); it != mLogElements.end();) { LogBufferElement *e = *it; if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { break; } Loading Loading @@ -293,7 +293,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { for(it = mLogElements.begin(); it != mLogElements.end();) { LogBufferElement *e = *it; if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { break; } Loading Loading @@ -334,7 +334,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { while((pruneRows > 0) && (it != mLogElements.end())) { LogBufferElement *e = *it; if (e->getLogId() == id) { if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { if (!whitelist) { if (stats.sizes(id) > (2 * log_buffer_size(id))) { // kick a misbehaving log reader client off the island Loading Loading @@ -366,7 +366,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { while((it != mLogElements.end()) && (pruneRows > 0)) { LogBufferElement *e = *it; if (e->getLogId() == id) { if (oldest && (oldest->mStart <= e->getMonotonicTime())) { if (oldest && (oldest->mStart <= e->getSequence())) { if (stats.sizes(id) > (2 * log_buffer_size(id))) { // kick a misbehaving log reader client off the island oldest->release_Locked(); Loading Loading @@ -423,16 +423,16 @@ unsigned long LogBuffer::getSize(log_id_t id) { return retval; } log_time LogBuffer::flushTo( SocketClient *reader, const log_time start, bool privileged, bool (*filter)(const LogBufferElement *element, void *arg), void *arg) { uint64_t LogBuffer::flushTo( SocketClient *reader, const uint64_t start, bool privileged, int (*filter)(const LogBufferElement *element, void *arg), void *arg) { LogBufferElementCollection::iterator it; log_time max = start; uint64_t max = start; uid_t uid = reader->getUid(); pthread_mutex_lock(&mLogElementsLock); if (start == LogTimeEntry::EPOCH) { if (start <= 1) { // client wants to start from the beginning it = mLogElements.begin(); } else { Loading @@ -441,7 +441,7 @@ log_time LogBuffer::flushTo( for (it = mLogElements.end(); it != mLogElements.begin(); /* do nothing */) { --it; LogBufferElement *element = *it; if (element->getMonotonicTime() <= start) { if (element->getSequence() <= start) { it++; break; } Loading @@ -455,14 +455,20 @@ log_time LogBuffer::flushTo( continue; } if (element->getMonotonicTime() <= start) { if (element->getSequence() <= start) { continue; } // NB: calling out to another object with mLogElementsLock held (safe) if (filter && !(*filter)(element, arg)) { if (filter) { int ret = (*filter)(element, arg); if (ret == false) { continue; } if (ret != true) { break; } } pthread_mutex_unlock(&mLogElementsLock); Loading @@ -481,7 +487,7 @@ log_time LogBuffer::flushTo( } void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { log_time oldest(CLOCK_MONOTONIC); uint64_t oldest = UINT64_MAX; pthread_mutex_lock(&mLogElementsLock); Loading @@ -491,7 +497,7 @@ void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { LogBufferElement *element = *it; if ((logMask & (1 << element->getLogId()))) { oldest = element->getMonotonicTime(); oldest = element->getSequence(); break; } } Loading
logd/LogBuffer.h +2 −2 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ public: void log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len); log_time flushTo(SocketClient *writer, const log_time start, uint64_t flushTo(SocketClient *writer, const uint64_t start, bool privileged, bool (*filter)(const LogBufferElement *element, void *arg) = NULL, int (*filter)(const LogBufferElement *element, void *arg) = NULL, void *arg = NULL); void clear(log_id_t id, uid_t uid = AID_ROOT); Loading
logd/LogBufferElement.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ #include "LogBufferElement.h" #include "LogReader.h" const log_time LogBufferElement::FLUSH_ERROR((uint32_t)0, (uint32_t)0); const uint64_t LogBufferElement::FLUSH_ERROR(0); atomic_int_fast64_t LogBufferElement::sequence; LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, Loading @@ -34,7 +35,7 @@ LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, , mPid(pid) , mTid(tid) , mMsgLen(len) , mMonotonicTime(CLOCK_MONOTONIC) , mSequence(sequence.fetch_add(1, memory_order_relaxed)) , mRealTime(realtime) { mMsg = new char[len]; memcpy(mMsg, msg, len); Loading @@ -44,7 +45,7 @@ LogBufferElement::~LogBufferElement() { delete [] mMsg; } log_time LogBufferElement::flushTo(SocketClient *reader) { uint64_t LogBufferElement::flushTo(SocketClient *reader) { struct logger_entry_v3 entry; memset(&entry, 0, sizeof(struct logger_entry_v3)); entry.hdr_size = sizeof(struct logger_entry_v3); Loading @@ -64,5 +65,5 @@ log_time LogBufferElement::flushTo(SocketClient *reader) { return FLUSH_ERROR; } return mMonotonicTime; return mSequence; }