Merge "logd: serialize accesses to stats helpers" into mnc-dev

This commit is contained in:
Mark Salyzyn 2015-06-25 15:35:44 +00:00 committed by Android (Google) Code Review
commit e27ee08abb
4 changed files with 19 additions and 4 deletions

View File

@ -145,7 +145,9 @@ int LogAudit::logPrint(const char *fmt, ...) {
++cp;
}
tid = pid;
logbuf->lock();
uid = logbuf->pidToUid(pid);
logbuf->unlock();
memmove(pidptr, cp, strlen(cp) + 1);
}
@ -180,14 +182,20 @@ int LogAudit::logPrint(const char *fmt, ...) {
static const char comm_str[] = " comm=\"";
const char *comm = strstr(str, comm_str);
const char *estr = str + strlen(str);
char *commfree = NULL;
if (comm) {
estr = comm;
comm += sizeof(comm_str) - 1;
} else if (pid == getpid()) {
pid = tid;
comm = "auditd";
} else if (!(comm = logbuf->pidToName(pid))) {
comm = "unknown";
} else {
logbuf->lock();
comm = commfree = logbuf->pidToName(pid);
logbuf->unlock();
if (!comm) {
comm = "unknown";
}
}
const char *ecomm = strchr(comm, '"');
@ -218,6 +226,7 @@ int LogAudit::logPrint(const char *fmt, ...) {
}
}
free(commfree);
free(str);
if (notify) {

View File

@ -71,10 +71,12 @@ public:
// *strp uses malloc, use free to release.
void formatPrune(char **strp) { mPrune.format(strp); }
// helper
// helper must be protected directly or implicitly by lock()/unlock()
char *pidToName(pid_t pid) { return stats.pidToName(pid); }
uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); }
char *uidToName(uid_t uid) { return stats.uidToName(uid); }
void lock() { pthread_mutex_lock(&mLogElementsLock); }
void unlock() { pthread_mutex_unlock(&mLogElementsLock); }
private:
void maybePrune(log_id_t id);

View File

@ -111,13 +111,17 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer,
}
static const char format_uid[] = "uid=%u%s%s expire %u line%s";
parent->lock();
char *name = parent->uidToName(mUid);
parent->unlock();
char *commName = android::tidToName(mTid);
if (!commName && (mTid != mPid)) {
commName = android::tidToName(mPid);
}
if (!commName) {
parent->lock();
commName = parent->pidToName(mPid);
parent->unlock();
}
size_t len = name ? strlen(name) : 0;
if (len && commName && !strncmp(name, commName, len)) {

View File

@ -334,7 +334,7 @@ public:
// *strp = malloc, balance with free
void format(char **strp, uid_t uid, unsigned int logMask);
// helper
// helper (must be locked directly or implicitly by mLogElementsLock)
char *pidToName(pid_t pid);
uid_t pidToUid(pid_t pid);
char *uidToName(uid_t uid);