From 8daa9af02dc0e63ce220e3fa95bf5fe4d6b7a99a Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 28 Apr 2014 14:07:23 -0700 Subject: logd: add thread setname - permits easier determination of logd thread at fault in a stack trace from debuggerd. Bug: 14275676 Change-Id: Iac2c523147e2bcce34ab7ddcecd02582c5fa7cc0 --- logd/CommandListener.cpp | 12 ++++++++++++ logd/LogAudit.cpp | 3 +++ logd/LogListener.cpp | 3 +++ logd/LogReader.cpp | 3 +++ logd/LogTimes.cpp | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp index a7bf92b..1f3fd0e 100644 --- a/logd/CommandListener.cpp +++ b/logd/CommandListener.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -66,8 +67,13 @@ CommandListener::ClearCmd::ClearCmd(LogBuffer *buf) , mBuf(*buf) { } +static void setname() { + prctl(PR_SET_NAME, "logd.control"); +} + int CommandListener::ClearCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); if (!clientHasLogCredentials(cli)) { cli->sendMsg("Permission Denied"); return 0; @@ -96,6 +102,7 @@ CommandListener::GetBufSizeCmd::GetBufSizeCmd(LogBuffer *buf) int CommandListener::GetBufSizeCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); if (argc < 2) { cli->sendMsg("Missing Argument"); return 0; @@ -121,6 +128,7 @@ CommandListener::SetBufSizeCmd::SetBufSizeCmd(LogBuffer *buf) int CommandListener::SetBufSizeCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); if (!clientHasLogCredentials(cli)) { cli->sendMsg("Permission Denied"); return 0; @@ -154,6 +162,7 @@ CommandListener::GetBufSizeUsedCmd::GetBufSizeUsedCmd(LogBuffer *buf) int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); if (argc < 2) { cli->sendMsg("Missing Argument"); return 0; @@ -197,6 +206,7 @@ static void package_string(char **strp) { int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); uid_t uid = cli->getUid(); gid_t gid = cli->getGid(); if (clientHasLogCredentials(cli)) { @@ -236,6 +246,7 @@ CommandListener::GetPruneListCmd::GetPruneListCmd(LogBuffer *buf) int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli, int /*argc*/, char ** /*argv*/) { + setname(); char *buf = NULL; mBuf.formatPrune(&buf); if (!buf) { @@ -255,6 +266,7 @@ CommandListener::SetPruneListCmd::SetPruneListCmd(LogBuffer *buf) int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, int argc, char **argv) { + setname(); if (!clientHasLogCredentials(cli)) { cli->sendMsg("Permission Denied"); return 0; diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index ea6eece..1056ae4 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "libaudit.h" @@ -34,6 +35,8 @@ LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmsg) } bool LogAudit::onDataAvailable(SocketClient *cli) { + prctl(PR_SET_NAME, "logd.auditd"); + struct audit_message rep; if (audit_get_reply(cli->getSocket(), &rep, GET_REPLY_BLOCKING, 0) < 0) { diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp index 1d0a51c..bc7622b 100644 --- a/logd/LogListener.cpp +++ b/logd/LogListener.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -31,6 +32,8 @@ LogListener::LogListener(LogBuffer *buf, LogReader *reader) { } bool LogListener::onDataAvailable(SocketClient *cli) { + prctl(PR_SET_NAME, "logd.writer"); + char buffer[sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time) + LOGGER_ENTRY_MAX_PAYLOAD]; struct iovec iov = { buffer, sizeof(buffer) }; diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp index 51aa2ad..8458c19 100644 --- a/logd/LogReader.cpp +++ b/logd/LogReader.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -36,6 +37,8 @@ void LogReader::notifyNewLog() { } bool LogReader::onDataAvailable(SocketClient *cli) { + prctl(PR_SET_NAME, "logd.reader"); + char buffer[255]; int len = read(cli->getSocket(), buffer, sizeof(buffer) - 1); diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp index c32ac2d..1a9a548 100644 --- a/logd/LogTimes.cpp +++ b/logd/LogTimes.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "FlushCommand.h" #include "LogBuffer.h" #include "LogTimes.h" @@ -107,6 +109,8 @@ void LogTimeEntry::threadStop(void *obj) { } void *LogTimeEntry::threadStart(void *obj) { + prctl(PR_SET_NAME, "logd.reader.per"); + LogTimeEntry *me = reinterpret_cast(obj); pthread_cleanup_push(threadStop, obj); -- cgit v1.1