Loading logd/LogBuffer.cpp +28 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * See the License for the specific language governing permissions and * limitations under the License. * limitations under the License. */ */ // for manual checking of stale entries during LogBuffer::erase() //#define DEBUG_CHECK_FOR_STALE_ENTRIES #include <ctype.h> #include <ctype.h> #include <errno.h> #include <errno.h> Loading Loading @@ -256,6 +258,11 @@ LogBufferElementCollection::iterator LogBuffer::erase( log_id_for_each(i) { log_id_for_each(i) { doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]); doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]); } } #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES LogBufferElementCollection::iterator bad = it; int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) ? element->getTag() : element->getUid(); #endif it = mLogElements.erase(it); it = mLogElements.erase(it); if (doSetLast) { if (doSetLast) { log_id_for_each(i) { log_id_for_each(i) { Loading @@ -269,6 +276,27 @@ LogBufferElementCollection::iterator LogBuffer::erase( } } } } } } #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES log_id_for_each(i) { for(auto b : mLastWorst[i]) { if (bad == b.second) { android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i, b.first, key); } } for(auto b : mLastWorstPidOfSystem[i]) { if (bad == b.second) { android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i, b.first); } } if (mLastSet[i] && (bad == mLast[i])) { android::prdebug("stale mLast[%d]\n", i); mLastSet[i] = false; mLast[i] = mLogElements.begin(); } } #endif if (coalesce) { if (coalesce) { stats.erase(element); stats.erase(element); } else { } else { Loading logd/LogBufferElement.cpp +8 −13 Original line number Original line Diff line number Diff line Loading @@ -36,29 +36,24 @@ atomic_int_fast64_t LogBufferElement::sequence(1); LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len) : const char *msg, unsigned short len) : mLogId(log_id), mUid(uid), mUid(uid), mPid(pid), mPid(pid), mTid(tid), mTid(tid), mMsgLen(len), mSequence(sequence.fetch_add(1, memory_order_relaxed)), mSequence(sequence.fetch_add(1, memory_order_relaxed)), mRealTime(realtime) { mRealTime(realtime), mMsgLen(len), mLogId(log_id) { mMsg = new char[len]; mMsg = new char[len]; memcpy(mMsg, msg, len); memcpy(mMsg, msg, len); mTag = (isBinary() && (mMsgLen >= sizeof(uint32_t))) ? le32toh(reinterpret_cast<android_event_header_t *>(mMsg)->tag) : 0; } } LogBufferElement::~LogBufferElement() { LogBufferElement::~LogBufferElement() { delete [] mMsg; delete [] mMsg; } } uint32_t LogBufferElement::getTag() const { if (((mLogId != LOG_ID_EVENTS) && (mLogId != LOG_ID_SECURITY)) || !mMsg || (mMsgLen < sizeof(uint32_t))) { return 0; } return le32toh(reinterpret_cast<android_event_header_t *>(mMsg)->tag); } // caller must own and free character string // caller must own and free character string char *android::tidToName(pid_t tid) { char *android::tidToName(pid_t tid) { char *retval = NULL; char *retval = NULL; Loading Loading @@ -164,7 +159,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, size_t hdrLen; size_t hdrLen; // LOG_ID_SECURITY not strictly needed since spam filter not activated, // LOG_ID_SECURITY not strictly needed since spam filter not activated, // but required for accuracy. // but required for accuracy. if ((mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY)) { if (isBinary()) { hdrLen = sizeof(android_log_event_string_t); hdrLen = sizeof(android_log_event_string_t); } else { } else { hdrLen = 1 + sizeof(tag); hdrLen = 1 + sizeof(tag); Loading @@ -178,7 +173,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } } size_t retval = hdrLen + len; size_t retval = hdrLen + len; if ((mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY)) { if (isBinary()) { android_log_event_string_t *event = android_log_event_string_t *event = reinterpret_cast<android_log_event_string_t *>(buffer); reinterpret_cast<android_log_event_string_t *>(buffer); Loading logd/LogBufferElement.h +17 −12 Original line number Original line Diff line number Diff line Loading @@ -36,33 +36,40 @@ class LogBufferElement { friend LogBuffer; friend LogBuffer; const log_id_t mLogId; // sized to match reality of incoming log packets const uid_t mUid; uint32_t mTag; // only valid for isBinary() const pid_t mPid; const uint32_t mUid; const pid_t mTid; const uint32_t mPid; const uint32_t mTid; const uint64_t mSequence; log_time mRealTime; char *mMsg; char *mMsg; union { union { const unsigned short mMsgLen; // mMSg != NULL const uint16_t mMsgLen; // mMSg != NULL unsigned short mDropped; // mMsg == NULL uint16_t mDropped; // mMsg == NULL }; }; const uint64_t mSequence; const uint8_t mLogId; log_time mRealTime; static atomic_int_fast64_t sequence; static atomic_int_fast64_t sequence; // assumption: mMsg == NULL // assumption: mMsg == NULL size_t populateDroppedMessage(char *&buffer, size_t populateDroppedMessage(char *&buffer, LogBuffer *parent); LogBuffer *parent); public: public: LogBufferElement(log_id_t log_id, log_time realtime, LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len); const char *msg, unsigned short len); virtual ~LogBufferElement(); virtual ~LogBufferElement(); log_id_t getLogId() const { return mLogId; } bool isBinary(void) const { return (mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY); } log_id_t getLogId() const { return static_cast<log_id_t>(mLogId); } uid_t getUid(void) const { return mUid; } uid_t getUid(void) const { return mUid; } pid_t getPid(void) const { return mPid; } pid_t getPid(void) const { return mPid; } pid_t getTid(void) const { return mTid; } pid_t getTid(void) const { return mTid; } uint32_t getTag() const { return mTag; } unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; } unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; } unsigned short setDropped(unsigned short value) { unsigned short setDropped(unsigned short value) { if (mMsg) { if (mMsg) { Loading @@ -76,8 +83,6 @@ public: static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); } static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); } log_time getRealTime(void) const { return mRealTime; } log_time getRealTime(void) const { return mRealTime; } uint32_t getTag(void) const; static const uint64_t FLUSH_ERROR; static const uint64_t FLUSH_ERROR; uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); }; }; Loading Loading
logd/LogBuffer.cpp +28 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * See the License for the specific language governing permissions and * limitations under the License. * limitations under the License. */ */ // for manual checking of stale entries during LogBuffer::erase() //#define DEBUG_CHECK_FOR_STALE_ENTRIES #include <ctype.h> #include <ctype.h> #include <errno.h> #include <errno.h> Loading Loading @@ -256,6 +258,11 @@ LogBufferElementCollection::iterator LogBuffer::erase( log_id_for_each(i) { log_id_for_each(i) { doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]); doSetLast |= setLast[i] = mLastSet[i] && (it == mLast[i]); } } #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES LogBufferElementCollection::iterator bad = it; int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) ? element->getTag() : element->getUid(); #endif it = mLogElements.erase(it); it = mLogElements.erase(it); if (doSetLast) { if (doSetLast) { log_id_for_each(i) { log_id_for_each(i) { Loading @@ -269,6 +276,27 @@ LogBufferElementCollection::iterator LogBuffer::erase( } } } } } } #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES log_id_for_each(i) { for(auto b : mLastWorst[i]) { if (bad == b.second) { android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i, b.first, key); } } for(auto b : mLastWorstPidOfSystem[i]) { if (bad == b.second) { android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i, b.first); } } if (mLastSet[i] && (bad == mLast[i])) { android::prdebug("stale mLast[%d]\n", i); mLastSet[i] = false; mLast[i] = mLogElements.begin(); } } #endif if (coalesce) { if (coalesce) { stats.erase(element); stats.erase(element); } else { } else { Loading
logd/LogBufferElement.cpp +8 −13 Original line number Original line Diff line number Diff line Loading @@ -36,29 +36,24 @@ atomic_int_fast64_t LogBufferElement::sequence(1); LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len) : const char *msg, unsigned short len) : mLogId(log_id), mUid(uid), mUid(uid), mPid(pid), mPid(pid), mTid(tid), mTid(tid), mMsgLen(len), mSequence(sequence.fetch_add(1, memory_order_relaxed)), mSequence(sequence.fetch_add(1, memory_order_relaxed)), mRealTime(realtime) { mRealTime(realtime), mMsgLen(len), mLogId(log_id) { mMsg = new char[len]; mMsg = new char[len]; memcpy(mMsg, msg, len); memcpy(mMsg, msg, len); mTag = (isBinary() && (mMsgLen >= sizeof(uint32_t))) ? le32toh(reinterpret_cast<android_event_header_t *>(mMsg)->tag) : 0; } } LogBufferElement::~LogBufferElement() { LogBufferElement::~LogBufferElement() { delete [] mMsg; delete [] mMsg; } } uint32_t LogBufferElement::getTag() const { if (((mLogId != LOG_ID_EVENTS) && (mLogId != LOG_ID_SECURITY)) || !mMsg || (mMsgLen < sizeof(uint32_t))) { return 0; } return le32toh(reinterpret_cast<android_event_header_t *>(mMsg)->tag); } // caller must own and free character string // caller must own and free character string char *android::tidToName(pid_t tid) { char *android::tidToName(pid_t tid) { char *retval = NULL; char *retval = NULL; Loading Loading @@ -164,7 +159,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, size_t hdrLen; size_t hdrLen; // LOG_ID_SECURITY not strictly needed since spam filter not activated, // LOG_ID_SECURITY not strictly needed since spam filter not activated, // but required for accuracy. // but required for accuracy. if ((mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY)) { if (isBinary()) { hdrLen = sizeof(android_log_event_string_t); hdrLen = sizeof(android_log_event_string_t); } else { } else { hdrLen = 1 + sizeof(tag); hdrLen = 1 + sizeof(tag); Loading @@ -178,7 +173,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } } size_t retval = hdrLen + len; size_t retval = hdrLen + len; if ((mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY)) { if (isBinary()) { android_log_event_string_t *event = android_log_event_string_t *event = reinterpret_cast<android_log_event_string_t *>(buffer); reinterpret_cast<android_log_event_string_t *>(buffer); Loading
logd/LogBufferElement.h +17 −12 Original line number Original line Diff line number Diff line Loading @@ -36,33 +36,40 @@ class LogBufferElement { friend LogBuffer; friend LogBuffer; const log_id_t mLogId; // sized to match reality of incoming log packets const uid_t mUid; uint32_t mTag; // only valid for isBinary() const pid_t mPid; const uint32_t mUid; const pid_t mTid; const uint32_t mPid; const uint32_t mTid; const uint64_t mSequence; log_time mRealTime; char *mMsg; char *mMsg; union { union { const unsigned short mMsgLen; // mMSg != NULL const uint16_t mMsgLen; // mMSg != NULL unsigned short mDropped; // mMsg == NULL uint16_t mDropped; // mMsg == NULL }; }; const uint64_t mSequence; const uint8_t mLogId; log_time mRealTime; static atomic_int_fast64_t sequence; static atomic_int_fast64_t sequence; // assumption: mMsg == NULL // assumption: mMsg == NULL size_t populateDroppedMessage(char *&buffer, size_t populateDroppedMessage(char *&buffer, LogBuffer *parent); LogBuffer *parent); public: public: LogBufferElement(log_id_t log_id, log_time realtime, LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, uid_t uid, pid_t pid, pid_t tid, const char *msg, unsigned short len); const char *msg, unsigned short len); virtual ~LogBufferElement(); virtual ~LogBufferElement(); log_id_t getLogId() const { return mLogId; } bool isBinary(void) const { return (mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY); } log_id_t getLogId() const { return static_cast<log_id_t>(mLogId); } uid_t getUid(void) const { return mUid; } uid_t getUid(void) const { return mUid; } pid_t getPid(void) const { return mPid; } pid_t getPid(void) const { return mPid; } pid_t getTid(void) const { return mTid; } pid_t getTid(void) const { return mTid; } uint32_t getTag() const { return mTag; } unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; } unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; } unsigned short setDropped(unsigned short value) { unsigned short setDropped(unsigned short value) { if (mMsg) { if (mMsg) { Loading @@ -76,8 +83,6 @@ public: static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); } static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); } log_time getRealTime(void) const { return mRealTime; } log_time getRealTime(void) const { return mRealTime; } uint32_t getTag(void) const; static const uint64_t FLUSH_ERROR; static const uint64_t FLUSH_ERROR; uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); }; }; Loading