diff options
-rw-r--r-- | logd/FlushCommand.cpp | 4 | ||||
-rw-r--r-- | logd/LogAudit.cpp | 4 | ||||
-rw-r--r-- | logd/LogBuffer.cpp | 68 | ||||
-rw-r--r-- | logd/LogBuffer.h | 13 | ||||
-rw-r--r-- | logd/LogBufferElement.cpp | 4 | ||||
-rw-r--r-- | logd/LogKlog.cpp | 2 | ||||
-rw-r--r-- | logd/LogReader.cpp | 4 | ||||
-rw-r--r-- | logd/LogStatistics.cpp | 1 | ||||
-rw-r--r-- | logd/LogTimes.cpp | 10 | ||||
-rw-r--r-- | logd/LogTimes.h | 7 |
10 files changed, 62 insertions, 55 deletions
diff --git a/logd/FlushCommand.cpp b/logd/FlushCommand.cpp index c67d2bfb1..a9edc3ee6 100644 --- a/logd/FlushCommand.cpp +++ b/logd/FlushCommand.cpp | |||
@@ -44,14 +44,14 @@ FlushCommand::FlushCommand(LogReader& reader, bool nonBlock, unsigned long tail, | |||
44 | // LogTimeEntrys, and spawn a transitory per-client thread to | 44 | // LogTimeEntrys, and spawn a transitory per-client thread to |
45 | // work at filing data to the socket. | 45 | // work at filing data to the socket. |
46 | // | 46 | // |
47 | // global LogTimeEntry::lock() is used to protect access, | 47 | // global LogTimeEntry::wrlock() is used to protect access, |
48 | // reference counts are used to ensure that individual | 48 | // reference counts are used to ensure that individual |
49 | // LogTimeEntry lifetime is managed when not protected. | 49 | // LogTimeEntry lifetime is managed when not protected. |
50 | void FlushCommand::runSocketCommand(SocketClient* client) { | 50 | void FlushCommand::runSocketCommand(SocketClient* client) { |
51 | LogTimeEntry* entry = NULL; | 51 | LogTimeEntry* entry = NULL; |
52 | LastLogTimes& times = mReader.logbuf().mTimes; | 52 | LastLogTimes& times = mReader.logbuf().mTimes; |
53 | 53 | ||
54 | LogTimeEntry::lock(); | 54 | LogTimeEntry::wrlock(); |
55 | LastLogTimes::iterator it = times.begin(); | 55 | LastLogTimes::iterator it = times.begin(); |
56 | while (it != times.end()) { | 56 | while (it != times.end()) { |
57 | entry = (*it); | 57 | entry = (*it); |
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index 2d9024ac5..ee38d1c1a 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp | |||
@@ -277,7 +277,7 @@ int LogAudit::logPrint(const char* fmt, ...) { | |||
277 | ++cp; | 277 | ++cp; |
278 | } | 278 | } |
279 | tid = pid; | 279 | tid = pid; |
280 | logbuf->lock(); | 280 | logbuf->wrlock(); |
281 | uid = logbuf->pidToUid(pid); | 281 | uid = logbuf->pidToUid(pid); |
282 | logbuf->unlock(); | 282 | logbuf->unlock(); |
283 | memmove(pidptr, cp, strlen(cp) + 1); | 283 | memmove(pidptr, cp, strlen(cp) + 1); |
@@ -322,7 +322,7 @@ int LogAudit::logPrint(const char* fmt, ...) { | |||
322 | pid = tid; | 322 | pid = tid; |
323 | comm = "auditd"; | 323 | comm = "auditd"; |
324 | } else { | 324 | } else { |
325 | logbuf->lock(); | 325 | logbuf->wrlock(); |
326 | comm = commfree = logbuf->pidToName(pid); | 326 | comm = commfree = logbuf->pidToName(pid); |
327 | logbuf->unlock(); | 327 | logbuf->unlock(); |
328 | if (!comm) { | 328 | if (!comm) { |
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index ed46181b7..d9ec08166 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp | |||
@@ -72,7 +72,7 @@ void LogBuffer::init() { | |||
72 | // as the act of mounting /data would trigger persist.logd.timestamp to | 72 | // as the act of mounting /data would trigger persist.logd.timestamp to |
73 | // be corrected. 1/30 corner case YMMV. | 73 | // be corrected. 1/30 corner case YMMV. |
74 | // | 74 | // |
75 | pthread_mutex_lock(&mLogElementsLock); | 75 | rdlock(); |
76 | LogBufferElementCollection::iterator it = mLogElements.begin(); | 76 | LogBufferElementCollection::iterator it = mLogElements.begin(); |
77 | while ((it != mLogElements.end())) { | 77 | while ((it != mLogElements.end())) { |
78 | LogBufferElement* e = *it; | 78 | LogBufferElement* e = *it; |
@@ -87,7 +87,7 @@ void LogBuffer::init() { | |||
87 | } | 87 | } |
88 | ++it; | 88 | ++it; |
89 | } | 89 | } |
90 | pthread_mutex_unlock(&mLogElementsLock); | 90 | unlock(); |
91 | } | 91 | } |
92 | 92 | ||
93 | // We may have been triggered by a SIGHUP. Release any sleeping reader | 93 | // We may have been triggered by a SIGHUP. Release any sleeping reader |
@@ -95,7 +95,7 @@ void LogBuffer::init() { | |||
95 | // | 95 | // |
96 | // NB: this is _not_ performed in the context of a SIGHUP, it is | 96 | // NB: this is _not_ performed in the context of a SIGHUP, it is |
97 | // performed during startup, and in context of reinit administrative thread | 97 | // performed during startup, and in context of reinit administrative thread |
98 | LogTimeEntry::lock(); | 98 | LogTimeEntry::wrlock(); |
99 | 99 | ||
100 | LastLogTimes::iterator times = mTimes.begin(); | 100 | LastLogTimes::iterator times = mTimes.begin(); |
101 | while (times != mTimes.end()) { | 101 | while (times != mTimes.end()) { |
@@ -111,7 +111,7 @@ void LogBuffer::init() { | |||
111 | 111 | ||
112 | LogBuffer::LogBuffer(LastLogTimes* times) | 112 | LogBuffer::LogBuffer(LastLogTimes* times) |
113 | : monotonic(android_log_clockid() == CLOCK_MONOTONIC), mTimes(*times) { | 113 | : monotonic(android_log_clockid() == CLOCK_MONOTONIC), mTimes(*times) { |
114 | pthread_mutex_init(&mLogElementsLock, nullptr); | 114 | pthread_rwlock_init(&mLogElementsLock, nullptr); |
115 | 115 | ||
116 | log_id_for_each(i) { | 116 | log_id_for_each(i) { |
117 | lastLoggedElements[i] = nullptr; | 117 | lastLoggedElements[i] = nullptr; |
@@ -207,15 +207,15 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, | |||
207 | } | 207 | } |
208 | if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) { | 208 | if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) { |
209 | // Log traffic received to total | 209 | // Log traffic received to total |
210 | pthread_mutex_lock(&mLogElementsLock); | 210 | wrlock(); |
211 | stats.addTotal(elem); | 211 | stats.addTotal(elem); |
212 | pthread_mutex_unlock(&mLogElementsLock); | 212 | unlock(); |
213 | delete elem; | 213 | delete elem; |
214 | return -EACCES; | 214 | return -EACCES; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | pthread_mutex_lock(&mLogElementsLock); | 218 | wrlock(); |
219 | LogBufferElement* currentLast = lastLoggedElements[log_id]; | 219 | LogBufferElement* currentLast = lastLoggedElements[log_id]; |
220 | if (currentLast) { | 220 | if (currentLast) { |
221 | LogBufferElement* dropped = droppedElements[log_id]; | 221 | LogBufferElement* dropped = droppedElements[log_id]; |
@@ -316,14 +316,14 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, | |||
316 | // check for overflow | 316 | // check for overflow |
317 | if (total >= UINT32_MAX) { | 317 | if (total >= UINT32_MAX) { |
318 | log(currentLast); | 318 | log(currentLast); |
319 | pthread_mutex_unlock(&mLogElementsLock); | 319 | unlock(); |
320 | return len; | 320 | return len; |
321 | } | 321 | } |
322 | stats.addTotal(currentLast); | 322 | stats.addTotal(currentLast); |
323 | delete currentLast; | 323 | delete currentLast; |
324 | swab = total; | 324 | swab = total; |
325 | event->payload.data = htole32(swab); | 325 | event->payload.data = htole32(swab); |
326 | pthread_mutex_unlock(&mLogElementsLock); | 326 | unlock(); |
327 | return len; | 327 | return len; |
328 | } | 328 | } |
329 | if (count == USHRT_MAX) { | 329 | if (count == USHRT_MAX) { |
@@ -340,7 +340,7 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, | |||
340 | } | 340 | } |
341 | droppedElements[log_id] = currentLast; | 341 | droppedElements[log_id] = currentLast; |
342 | lastLoggedElements[log_id] = elem; | 342 | lastLoggedElements[log_id] = elem; |
343 | pthread_mutex_unlock(&mLogElementsLock); | 343 | unlock(); |
344 | return len; | 344 | return len; |
345 | } | 345 | } |
346 | if (dropped) { // State 1 or 2 | 346 | if (dropped) { // State 1 or 2 |
@@ -358,12 +358,12 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, | |||
358 | lastLoggedElements[log_id] = new LogBufferElement(*elem); | 358 | lastLoggedElements[log_id] = new LogBufferElement(*elem); |
359 | 359 | ||
360 | log(elem); | 360 | log(elem); |
361 | pthread_mutex_unlock(&mLogElementsLock); | 361 | unlock(); |
362 | 362 | ||
363 | return len; | 363 | return len; |
364 | } | 364 | } |
365 | 365 | ||
366 | // assumes mLogElementsLock held, owns elem, will look after garbage collection | 366 | // assumes LogBuffer::wrlock() held, owns elem, look after garbage collection |
367 | void LogBuffer::log(LogBufferElement* elem) { | 367 | void LogBuffer::log(LogBufferElement* elem) { |
368 | // cap on how far back we will sort in-place, otherwise append | 368 | // cap on how far back we will sort in-place, otherwise append |
369 | static uint32_t too_far_back = 5; // five seconds | 369 | static uint32_t too_far_back = 5; // five seconds |
@@ -384,7 +384,7 @@ void LogBuffer::log(LogBufferElement* elem) { | |||
384 | bool end_set = false; | 384 | bool end_set = false; |
385 | bool end_always = false; | 385 | bool end_always = false; |
386 | 386 | ||
387 | LogTimeEntry::lock(); | 387 | LogTimeEntry::rdlock(); |
388 | 388 | ||
389 | LastLogTimes::iterator times = mTimes.begin(); | 389 | LastLogTimes::iterator times = mTimes.begin(); |
390 | while (times != mTimes.end()) { | 390 | while (times != mTimes.end()) { |
@@ -426,7 +426,7 @@ void LogBuffer::log(LogBufferElement* elem) { | |||
426 | 426 | ||
427 | // Prune at most 10% of the log entries or maxPrune, whichever is less. | 427 | // Prune at most 10% of the log entries or maxPrune, whichever is less. |
428 | // | 428 | // |
429 | // mLogElementsLock must be held when this function is called. | 429 | // LogBuffer::wrlock() must be held when this function is called. |
430 | void LogBuffer::maybePrune(log_id_t id) { | 430 | void LogBuffer::maybePrune(log_id_t id) { |
431 | size_t sizes = stats.sizes(id); | 431 | size_t sizes = stats.sizes(id); |
432 | unsigned long maxSize = log_buffer_size(id); | 432 | unsigned long maxSize = log_buffer_size(id); |
@@ -650,14 +650,14 @@ class LogBufferElementLast { | |||
650 | // The third thread is optional, and only gets hit if there was a whitelist | 650 | // The third thread is optional, and only gets hit if there was a whitelist |
651 | // and more needs to be pruned against the backstop of the region lock. | 651 | // and more needs to be pruned against the backstop of the region lock. |
652 | // | 652 | // |
653 | // mLogElementsLock must be held when this function is called. | 653 | // LogBuffer::wrlock() must be held when this function is called. |
654 | // | 654 | // |
655 | bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { | 655 | bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { |
656 | LogTimeEntry* oldest = nullptr; | 656 | LogTimeEntry* oldest = nullptr; |
657 | bool busy = false; | 657 | bool busy = false; |
658 | bool clearAll = pruneRows == ULONG_MAX; | 658 | bool clearAll = pruneRows == ULONG_MAX; |
659 | 659 | ||
660 | LogTimeEntry::lock(); | 660 | LogTimeEntry::rdlock(); |
661 | 661 | ||
662 | // Region locked? | 662 | // Region locked? |
663 | LastLogTimes::iterator times = mTimes.begin(); | 663 | LastLogTimes::iterator times = mTimes.begin(); |
@@ -1017,15 +1017,15 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) { | |||
1017 | // one entry, not another clear run, so we are looking for | 1017 | // one entry, not another clear run, so we are looking for |
1018 | // the quick side effect of the return value to tell us if | 1018 | // the quick side effect of the return value to tell us if |
1019 | // we have a _blocked_ reader. | 1019 | // we have a _blocked_ reader. |
1020 | pthread_mutex_lock(&mLogElementsLock); | 1020 | wrlock(); |
1021 | busy = prune(id, 1, uid); | 1021 | busy = prune(id, 1, uid); |
1022 | pthread_mutex_unlock(&mLogElementsLock); | 1022 | unlock(); |
1023 | // It is still busy, blocked reader(s), lets kill them all! | 1023 | // It is still busy, blocked reader(s), lets kill them all! |
1024 | // otherwise, lets be a good citizen and preserve the slow | 1024 | // otherwise, lets be a good citizen and preserve the slow |
1025 | // readers and let the clear run (below) deal with determining | 1025 | // readers and let the clear run (below) deal with determining |
1026 | // if we are still blocked and return an error code to caller. | 1026 | // if we are still blocked and return an error code to caller. |
1027 | if (busy) { | 1027 | if (busy) { |
1028 | LogTimeEntry::lock(); | 1028 | LogTimeEntry::wrlock(); |
1029 | LastLogTimes::iterator times = mTimes.begin(); | 1029 | LastLogTimes::iterator times = mTimes.begin(); |
1030 | while (times != mTimes.end()) { | 1030 | while (times != mTimes.end()) { |
1031 | LogTimeEntry* entry = (*times); | 1031 | LogTimeEntry* entry = (*times); |
@@ -1038,9 +1038,9 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) { | |||
1038 | LogTimeEntry::unlock(); | 1038 | LogTimeEntry::unlock(); |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | pthread_mutex_lock(&mLogElementsLock); | 1041 | wrlock(); |
1042 | busy = prune(id, ULONG_MAX, uid); | 1042 | busy = prune(id, ULONG_MAX, uid); |
1043 | pthread_mutex_unlock(&mLogElementsLock); | 1043 | unlock(); |
1044 | if (!busy || !--retry) { | 1044 | if (!busy || !--retry) { |
1045 | break; | 1045 | break; |
1046 | } | 1046 | } |
@@ -1051,9 +1051,9 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) { | |||
1051 | 1051 | ||
1052 | // get the used space associated with "id". | 1052 | // get the used space associated with "id". |
1053 | unsigned long LogBuffer::getSizeUsed(log_id_t id) { | 1053 | unsigned long LogBuffer::getSizeUsed(log_id_t id) { |
1054 | pthread_mutex_lock(&mLogElementsLock); | 1054 | rdlock(); |
1055 | size_t retval = stats.sizes(id); | 1055 | size_t retval = stats.sizes(id); |
1056 | pthread_mutex_unlock(&mLogElementsLock); | 1056 | unlock(); |
1057 | return retval; | 1057 | return retval; |
1058 | } | 1058 | } |
1059 | 1059 | ||
@@ -1063,17 +1063,17 @@ int LogBuffer::setSize(log_id_t id, unsigned long size) { | |||
1063 | if (!__android_logger_valid_buffer_size(size)) { | 1063 | if (!__android_logger_valid_buffer_size(size)) { |
1064 | return -1; | 1064 | return -1; |
1065 | } | 1065 | } |
1066 | pthread_mutex_lock(&mLogElementsLock); | 1066 | wrlock(); |
1067 | log_buffer_size(id) = size; | 1067 | log_buffer_size(id) = size; |
1068 | pthread_mutex_unlock(&mLogElementsLock); | 1068 | unlock(); |
1069 | return 0; | 1069 | return 0; |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | // get the total space allocated to "id" | 1072 | // get the total space allocated to "id" |
1073 | unsigned long LogBuffer::getSize(log_id_t id) { | 1073 | unsigned long LogBuffer::getSize(log_id_t id) { |
1074 | pthread_mutex_lock(&mLogElementsLock); | 1074 | rdlock(); |
1075 | size_t retval = log_buffer_size(id); | 1075 | size_t retval = log_buffer_size(id); |
1076 | pthread_mutex_unlock(&mLogElementsLock); | 1076 | unlock(); |
1077 | return retval; | 1077 | return retval; |
1078 | } | 1078 | } |
1079 | 1079 | ||
@@ -1085,7 +1085,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start, | |||
1085 | LogBufferElementCollection::iterator it; | 1085 | LogBufferElementCollection::iterator it; |
1086 | uid_t uid = reader->getUid(); | 1086 | uid_t uid = reader->getUid(); |
1087 | 1087 | ||
1088 | pthread_mutex_lock(&mLogElementsLock); | 1088 | rdlock(); |
1089 | 1089 | ||
1090 | if (start == log_time::EPOCH) { | 1090 | if (start == log_time::EPOCH) { |
1091 | // client wants to start from the beginning | 1091 | // client wants to start from the beginning |
@@ -1143,7 +1143,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start, | |||
1143 | continue; | 1143 | continue; |
1144 | } | 1144 | } |
1145 | 1145 | ||
1146 | // NB: calling out to another object with mLogElementsLock held (safe) | 1146 | // NB: calling out to another object with wrlock() held (safe) |
1147 | if (filter) { | 1147 | if (filter) { |
1148 | int ret = (*filter)(element, arg); | 1148 | int ret = (*filter)(element, arg); |
1149 | if (ret == false) { | 1149 | if (ret == false) { |
@@ -1166,7 +1166,7 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start, | |||
1166 | (element->getDropped() && !sameTid) ? 0 : element->getTid(); | 1166 | (element->getDropped() && !sameTid) ? 0 : element->getTid(); |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | pthread_mutex_unlock(&mLogElementsLock); | 1169 | unlock(); |
1170 | 1170 | ||
1171 | // range locking in LastLogTimes looks after us | 1171 | // range locking in LastLogTimes looks after us |
1172 | max = element->flushTo(reader, this, privileged, sameTid); | 1172 | max = element->flushTo(reader, this, privileged, sameTid); |
@@ -1176,20 +1176,20 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start, | |||
1176 | } | 1176 | } |
1177 | 1177 | ||
1178 | skip = maxSkip; | 1178 | skip = maxSkip; |
1179 | pthread_mutex_lock(&mLogElementsLock); | 1179 | rdlock(); |
1180 | } | 1180 | } |
1181 | pthread_mutex_unlock(&mLogElementsLock); | 1181 | unlock(); |
1182 | 1182 | ||
1183 | return max; | 1183 | return max; |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, | 1186 | std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, |
1187 | unsigned int logMask) { | 1187 | unsigned int logMask) { |
1188 | pthread_mutex_lock(&mLogElementsLock); | 1188 | wrlock(); |
1189 | 1189 | ||
1190 | std::string ret = stats.format(uid, pid, logMask); | 1190 | std::string ret = stats.format(uid, pid, logMask); |
1191 | 1191 | ||
1192 | pthread_mutex_unlock(&mLogElementsLock); | 1192 | unlock(); |
1193 | 1193 | ||
1194 | return ret; | 1194 | return ret; |
1195 | } | 1195 | } |
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h index 1272c20f6..51edd8628 100644 --- a/logd/LogBuffer.h +++ b/logd/LogBuffer.h | |||
@@ -76,7 +76,7 @@ typedef std::list<LogBufferElement*> LogBufferElementCollection; | |||
76 | 76 | ||
77 | class LogBuffer { | 77 | class LogBuffer { |
78 | LogBufferElementCollection mLogElements; | 78 | LogBufferElementCollection mLogElements; |
79 | pthread_mutex_t mLogElementsLock; | 79 | pthread_rwlock_t mLogElementsLock; |
80 | 80 | ||
81 | LogStatistics stats; | 81 | LogStatistics stats; |
82 | 82 | ||
@@ -154,7 +154,7 @@ class LogBuffer { | |||
154 | return tags.tagToName(tag); | 154 | return tags.tagToName(tag); |
155 | } | 155 | } |
156 | 156 | ||
157 | // helper must be protected directly or implicitly by lock()/unlock() | 157 | // helper must be protected directly or implicitly by wrlock()/unlock() |
158 | const char* pidToName(pid_t pid) { | 158 | const char* pidToName(pid_t pid) { |
159 | return stats.pidToName(pid); | 159 | return stats.pidToName(pid); |
160 | } | 160 | } |
@@ -164,11 +164,14 @@ class LogBuffer { | |||
164 | const char* uidToName(uid_t uid) { | 164 | const char* uidToName(uid_t uid) { |
165 | return stats.uidToName(uid); | 165 | return stats.uidToName(uid); |
166 | } | 166 | } |
167 | void lock() { | 167 | void wrlock() { |
168 | pthread_mutex_lock(&mLogElementsLock); | 168 | pthread_rwlock_wrlock(&mLogElementsLock); |
169 | } | ||
170 | void rdlock() { | ||
171 | pthread_rwlock_rdlock(&mLogElementsLock); | ||
169 | } | 172 | } |
170 | void unlock() { | 173 | void unlock() { |
171 | pthread_mutex_unlock(&mLogElementsLock); | 174 | pthread_rwlock_unlock(&mLogElementsLock); |
172 | } | 175 | } |
173 | 176 | ||
174 | private: | 177 | private: |
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp index 04a620c5c..381c97457 100644 --- a/logd/LogBufferElement.cpp +++ b/logd/LogBufferElement.cpp | |||
@@ -121,7 +121,7 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent | |||
121 | } | 121 | } |
122 | 122 | ||
123 | static const char format_uid[] = "uid=%u%s%s %s %u line%s"; | 123 | static const char format_uid[] = "uid=%u%s%s %s %u line%s"; |
124 | parent->lock(); | 124 | parent->wrlock(); |
125 | const char* name = parent->uidToName(mUid); | 125 | const char* name = parent->uidToName(mUid); |
126 | parent->unlock(); | 126 | parent->unlock(); |
127 | const char* commName = android::tidToName(mTid); | 127 | const char* commName = android::tidToName(mTid); |
@@ -129,7 +129,7 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent | |||
129 | commName = android::tidToName(mPid); | 129 | commName = android::tidToName(mPid); |
130 | } | 130 | } |
131 | if (!commName) { | 131 | if (!commName) { |
132 | parent->lock(); | 132 | parent->wrlock(); |
133 | commName = parent->pidToName(mPid); | 133 | commName = parent->pidToName(mPid); |
134 | parent->unlock(); | 134 | parent->unlock(); |
135 | } | 135 | } |
diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp index d23254d37..a7e72087f 100644 --- a/logd/LogKlog.cpp +++ b/logd/LogKlog.cpp | |||
@@ -579,7 +579,7 @@ int LogKlog::log(const char* buf, ssize_t len) { | |||
579 | const pid_t tid = pid; | 579 | const pid_t tid = pid; |
580 | uid_t uid = AID_ROOT; | 580 | uid_t uid = AID_ROOT; |
581 | if (pid) { | 581 | if (pid) { |
582 | logbuf->lock(); | 582 | logbuf->wrlock(); |
583 | uid = logbuf->pidToUid(pid); | 583 | uid = logbuf->pidToUid(pid); |
584 | logbuf->unlock(); | 584 | logbuf->unlock(); |
585 | } | 585 | } |
diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp index feb105f76..6d6931631 100644 --- a/logd/LogReader.cpp +++ b/logd/LogReader.cpp | |||
@@ -111,7 +111,7 @@ bool LogReader::onDataAvailable(SocketClient* cli) { | |||
111 | if (!fastcmp<strncmp>(buffer, "dumpAndClose", 12)) { | 111 | if (!fastcmp<strncmp>(buffer, "dumpAndClose", 12)) { |
112 | // Allow writer to get some cycles, and wait for pending notifications | 112 | // Allow writer to get some cycles, and wait for pending notifications |
113 | sched_yield(); | 113 | sched_yield(); |
114 | LogTimeEntry::lock(); | 114 | LogTimeEntry::wrlock(); |
115 | LogTimeEntry::unlock(); | 115 | LogTimeEntry::unlock(); |
116 | sched_yield(); | 116 | sched_yield(); |
117 | nonBlock = true; | 117 | nonBlock = true; |
@@ -212,7 +212,7 @@ bool LogReader::onDataAvailable(SocketClient* cli) { | |||
212 | 212 | ||
213 | void LogReader::doSocketDelete(SocketClient* cli) { | 213 | void LogReader::doSocketDelete(SocketClient* cli) { |
214 | LastLogTimes& times = mLogbuf.mTimes; | 214 | LastLogTimes& times = mLogbuf.mTimes; |
215 | LogTimeEntry::lock(); | 215 | LogTimeEntry::wrlock(); |
216 | LastLogTimes::iterator it = times.begin(); | 216 | LastLogTimes::iterator it = times.begin(); |
217 | while (it != times.end()) { | 217 | while (it != times.end()) { |
218 | LogTimeEntry* entry = (*it); | 218 | LogTimeEntry* entry = (*it); |
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index 3f020b64c..0b6b28cf8 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp | |||
@@ -228,6 +228,7 @@ void LogStatistics::drop(LogBufferElement* element) { | |||
228 | } | 228 | } |
229 | 229 | ||
230 | // caller must own and free character string | 230 | // caller must own and free character string |
231 | // Requires parent LogBuffer::wrlock() to be held | ||
231 | const char* LogStatistics::uidToName(uid_t uid) const { | 232 | const char* LogStatistics::uidToName(uid_t uid) const { |
232 | // Local hard coded favourites | 233 | // Local hard coded favourites |
233 | if (uid == AID_LOGD) { | 234 | if (uid == AID_LOGD) { |
diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp index ccc550a73..25c2ad2b7 100644 --- a/logd/LogTimes.cpp +++ b/logd/LogTimes.cpp | |||
@@ -78,7 +78,7 @@ void LogTimeEntry::startReader_Locked(void) { | |||
78 | void LogTimeEntry::threadStop(void* obj) { | 78 | void LogTimeEntry::threadStop(void* obj) { |
79 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); | 79 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); |
80 | 80 | ||
81 | lock(); | 81 | wrlock(); |
82 | 82 | ||
83 | if (me->mNonBlock) { | 83 | if (me->mNonBlock) { |
84 | me->error_Locked(); | 84 | me->error_Locked(); |
@@ -134,7 +134,7 @@ void* LogTimeEntry::threadStart(void* obj) { | |||
134 | 134 | ||
135 | me->leadingDropped = true; | 135 | me->leadingDropped = true; |
136 | 136 | ||
137 | lock(); | 137 | wrlock(); |
138 | 138 | ||
139 | log_time start = me->mStart; | 139 | log_time start = me->mStart; |
140 | 140 | ||
@@ -160,7 +160,7 @@ void* LogTimeEntry::threadStart(void* obj) { | |||
160 | start = logbuf.flushTo(client, start, me->mLastTid, privileged, | 160 | start = logbuf.flushTo(client, start, me->mLastTid, privileged, |
161 | security, FilterSecondPass, me); | 161 | security, FilterSecondPass, me); |
162 | 162 | ||
163 | lock(); | 163 | wrlock(); |
164 | 164 | ||
165 | if (start == LogBufferElement::FLUSH_ERROR) { | 165 | if (start == LogBufferElement::FLUSH_ERROR) { |
166 | me->error_Locked(); | 166 | me->error_Locked(); |
@@ -191,7 +191,7 @@ void* LogTimeEntry::threadStart(void* obj) { | |||
191 | int LogTimeEntry::FilterFirstPass(const LogBufferElement* element, void* obj) { | 191 | int LogTimeEntry::FilterFirstPass(const LogBufferElement* element, void* obj) { |
192 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); | 192 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); |
193 | 193 | ||
194 | LogTimeEntry::lock(); | 194 | LogTimeEntry::wrlock(); |
195 | 195 | ||
196 | if (me->leadingDropped) { | 196 | if (me->leadingDropped) { |
197 | if (element->getDropped()) { | 197 | if (element->getDropped()) { |
@@ -219,7 +219,7 @@ int LogTimeEntry::FilterFirstPass(const LogBufferElement* element, void* obj) { | |||
219 | int LogTimeEntry::FilterSecondPass(const LogBufferElement* element, void* obj) { | 219 | int LogTimeEntry::FilterSecondPass(const LogBufferElement* element, void* obj) { |
220 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); | 220 | LogTimeEntry* me = reinterpret_cast<LogTimeEntry*>(obj); |
221 | 221 | ||
222 | LogTimeEntry::lock(); | 222 | LogTimeEntry::wrlock(); |
223 | 223 | ||
224 | me->mStart = element->getRealTime(); | 224 | me->mStart = element->getRealTime(); |
225 | 225 | ||
diff --git a/logd/LogTimes.h b/logd/LogTimes.h index ec8252e69..9ca2aea5e 100644 --- a/logd/LogTimes.h +++ b/logd/LogTimes.h | |||
@@ -61,7 +61,10 @@ class LogTimeEntry { | |||
61 | const log_time mEnd; // only relevant if mNonBlock | 61 | const log_time mEnd; // only relevant if mNonBlock |
62 | 62 | ||
63 | // Protect List manipulations | 63 | // Protect List manipulations |
64 | static void lock(void) { | 64 | static void wrlock(void) { |
65 | pthread_mutex_lock(×Lock); | ||
66 | } | ||
67 | static void rdlock(void) { | ||
65 | pthread_mutex_lock(×Lock); | 68 | pthread_mutex_lock(×Lock); |
66 | } | 69 | } |
67 | static void unlock(void) { | 70 | static void unlock(void) { |
@@ -104,7 +107,7 @@ class LogTimeEntry { | |||
104 | mError = true; | 107 | mError = true; |
105 | } | 108 | } |
106 | void error(void) { | 109 | void error(void) { |
107 | lock(); | 110 | wrlock(); |
108 | error_Locked(); | 111 | error_Locked(); |
109 | unlock(); | 112 | unlock(); |
110 | } | 113 | } |