logd: Cleanup

(cherry pick from commit 7718778793)

- Android Coding Standard for Constructors
- Side effects NONE

Change-Id: I2cda9dd73f3ac3ab58f394015cb810820093d47b
This commit is contained in:
Mark Salyzyn 2015-05-12 15:21:31 -07:00
parent 79c3815ca1
commit 66091f11f4
12 changed files with 111 additions and 119 deletions

View file

@ -33,9 +33,9 @@
#include "LogCommand.h" #include "LogCommand.h"
CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/, CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
LogListener * /*swl*/) LogListener * /*swl*/) :
: FrameworkListener(getLogSocket()) FrameworkListener(getLogSocket()),
, mBuf(*buf) { mBuf(*buf) {
// registerCmd(new ShutdownCmd(buf, writer, swl)); // registerCmd(new ShutdownCmd(buf, writer, swl));
registerCmd(new ClearCmd(buf)); registerCmd(new ClearCmd(buf));
registerCmd(new GetBufSizeCmd(buf)); registerCmd(new GetBufSizeCmd(buf));
@ -48,12 +48,12 @@ CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
} }
CommandListener::ShutdownCmd::ShutdownCmd(LogBuffer *buf, LogReader *reader, CommandListener::ShutdownCmd::ShutdownCmd(LogBuffer *buf, LogReader *reader,
LogListener *swl) LogListener *swl) :
: LogCommand("shutdown") LogCommand("shutdown"),
, mBuf(*buf) mBuf(*buf),
, mReader(*reader) mReader(*reader),
, mSwl(*swl) mSwl(*swl) {
{ } }
int CommandListener::ShutdownCmd::runCommand(SocketClient * /*cli*/, int CommandListener::ShutdownCmd::runCommand(SocketClient * /*cli*/,
int /*argc*/, int /*argc*/,
@ -63,10 +63,10 @@ int CommandListener::ShutdownCmd::runCommand(SocketClient * /*cli*/,
exit(0); exit(0);
} }
CommandListener::ClearCmd::ClearCmd(LogBuffer *buf) CommandListener::ClearCmd::ClearCmd(LogBuffer *buf) :
: LogCommand("clear") LogCommand("clear"),
, mBuf(*buf) mBuf(*buf) {
{ } }
static void setname() { static void setname() {
static bool name_set; static bool name_set;
@ -100,10 +100,10 @@ int CommandListener::ClearCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::GetBufSizeCmd::GetBufSizeCmd(LogBuffer *buf) CommandListener::GetBufSizeCmd::GetBufSizeCmd(LogBuffer *buf) :
: LogCommand("getLogSize") LogCommand("getLogSize"),
, mBuf(*buf) mBuf(*buf) {
{ } }
int CommandListener::GetBufSizeCmd::runCommand(SocketClient *cli, int CommandListener::GetBufSizeCmd::runCommand(SocketClient *cli,
int argc, char **argv) { int argc, char **argv) {
@ -126,10 +126,10 @@ int CommandListener::GetBufSizeCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::SetBufSizeCmd::SetBufSizeCmd(LogBuffer *buf) CommandListener::SetBufSizeCmd::SetBufSizeCmd(LogBuffer *buf) :
: LogCommand("setLogSize") LogCommand("setLogSize"),
, mBuf(*buf) mBuf(*buf) {
{ } }
int CommandListener::SetBufSizeCmd::runCommand(SocketClient *cli, int CommandListener::SetBufSizeCmd::runCommand(SocketClient *cli,
int argc, char **argv) { int argc, char **argv) {
@ -160,10 +160,10 @@ int CommandListener::SetBufSizeCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::GetBufSizeUsedCmd::GetBufSizeUsedCmd(LogBuffer *buf) CommandListener::GetBufSizeUsedCmd::GetBufSizeUsedCmd(LogBuffer *buf) :
: LogCommand("getLogSizeUsed") LogCommand("getLogSizeUsed"),
, mBuf(*buf) mBuf(*buf) {
{ } }
int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient *cli, int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient *cli,
int argc, char **argv) { int argc, char **argv) {
@ -186,10 +186,10 @@ int CommandListener::GetBufSizeUsedCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::GetStatisticsCmd::GetStatisticsCmd(LogBuffer *buf) CommandListener::GetStatisticsCmd::GetStatisticsCmd(LogBuffer *buf) :
: LogCommand("getStatistics") LogCommand("getStatistics"),
, mBuf(*buf) mBuf(*buf) {
{ } }
static void package_string(char **strp) { static void package_string(char **strp) {
const char *a = *strp; const char *a = *strp;
@ -243,10 +243,10 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::GetPruneListCmd::GetPruneListCmd(LogBuffer *buf) CommandListener::GetPruneListCmd::GetPruneListCmd(LogBuffer *buf) :
: LogCommand("getPruneList") LogCommand("getPruneList"),
, mBuf(*buf) mBuf(*buf) {
{ } }
int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli, int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli,
int /*argc*/, char ** /*argv*/) { int /*argc*/, char ** /*argv*/) {
@ -263,10 +263,10 @@ int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::SetPruneListCmd::SetPruneListCmd(LogBuffer *buf) CommandListener::SetPruneListCmd::SetPruneListCmd(LogBuffer *buf) :
: LogCommand("setPruneList") LogCommand("setPruneList"),
, mBuf(*buf) mBuf(*buf) {
{ } }
int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli,
int argc, char **argv) { int argc, char **argv) {
@ -301,9 +301,8 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
CommandListener::ReinitCmd::ReinitCmd() CommandListener::ReinitCmd::ReinitCmd() : LogCommand("reinit") {
: LogCommand("reinit") }
{ }
int CommandListener::ReinitCmd::runCommand(SocketClient *cli, int CommandListener::ReinitCmd::runCommand(SocketClient *cli,
int /*argc*/, char ** /*argv*/) { int /*argc*/, char ** /*argv*/) {

View file

@ -27,14 +27,14 @@ FlushCommand::FlushCommand(LogReader &reader,
unsigned long tail, unsigned long tail,
unsigned int logMask, unsigned int logMask,
pid_t pid, pid_t pid,
uint64_t start) uint64_t start) :
: mReader(reader) mReader(reader),
, mNonBlock(nonBlock) mNonBlock(nonBlock),
, mTail(tail) mTail(tail),
, mLogMask(logMask) mLogMask(logMask),
, mPid(pid) mPid(pid),
, mStart(start) mStart(start) {
{ } }
// runSocketCommand is called once for every open client on the // runSocketCommand is called once for every open client on the
// log reader socket. Here we manage and associated the reader // log reader socket. Here we manage and associated the reader

View file

@ -37,12 +37,12 @@
'0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) % 10, \ '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) % 10, \
'>' '>'
LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg) LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg) :
: SocketListener(getLogSocket(), false) SocketListener(getLogSocket(), false),
, logbuf(buf) logbuf(buf),
, reader(reader) reader(reader),
, fdDmesg(fdDmesg) fdDmesg(fdDmesg),
, initialized(false) { initialized(false) {
static const char auditd_message[] = { KMSG_PRIORITY(LOG_INFO), static const char auditd_message[] = { KMSG_PRIORITY(LOG_INFO),
'l', 'o', 'g', 'd', '.', 'a', 'u', 'd', 'i', 't', 'd', ':', 'l', 'o', 'g', 'd', '.', 'a', 'u', 'd', 'i', 't', 'd', ':',
' ', 's', 't', 'a', 'r', 't', '\n' }; ' ', 's', 't', 'a', 'r', 't', '\n' };

View file

@ -126,8 +126,7 @@ void LogBuffer::init() {
} }
} }
LogBuffer::LogBuffer(LastLogTimes *times) LogBuffer::LogBuffer(LastLogTimes *times) : mTimes(*times) {
: mTimes(*times) {
pthread_mutex_init(&mLogElementsLock, NULL); pthread_mutex_init(&mLogElementsLock, NULL);
init(); init();

View file

@ -34,14 +34,14 @@ atomic_int_fast64_t LogBufferElement::sequence;
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) mLogId(log_id),
, mUid(uid) mUid(uid),
, mPid(pid) mPid(pid),
, mTid(tid) mTid(tid),
, mMsgLen(len) mMsgLen(len),
, mSequence(sequence.fetch_add(1, memory_order_relaxed)) mSequence(sequence.fetch_add(1, memory_order_relaxed)),
, mRealTime(realtime) { mRealTime(realtime) {
mMsg = new char[len]; mMsg = new char[len];
memcpy(mMsg, msg, len); memcpy(mMsg, msg, len);
} }

View file

@ -23,8 +23,7 @@
#include "LogCommand.h" #include "LogCommand.h"
LogCommand::LogCommand(const char *cmd) LogCommand::LogCommand(const char *cmd) : FrameworkCommand(cmd) {
: FrameworkCommand(cmd) {
} }
// gets a list of supplementary group IDs associated with // gets a list of supplementary group IDs associated with

View file

@ -38,16 +38,16 @@ static const char priority_message[] = { KMSG_PRIORITY(LOG_INFO), '\0' };
log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC); log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC);
LogKlog::LogKlog(LogBuffer *buf, LogReader *reader, int fdWrite, int fdRead, bool auditd) LogKlog::LogKlog(LogBuffer *buf, LogReader *reader, int fdWrite, int fdRead, bool auditd) :
: SocketListener(fdRead, false) SocketListener(fdRead, false),
, logbuf(buf) logbuf(buf),
, reader(reader) reader(reader),
, signature(CLOCK_MONOTONIC) signature(CLOCK_MONOTONIC),
, fdWrite(fdWrite) fdWrite(fdWrite),
, fdRead(fdRead) fdRead(fdRead),
, initialized(false) initialized(false),
, enableLogging(true) enableLogging(true),
, auditd(auditd) { auditd(auditd) {
static const char klogd_message[] = "%slogd.klogd: %" PRIu64 "\n"; static const char klogd_message[] = "%slogd.klogd: %" PRIu64 "\n";
char buffer[sizeof(priority_message) + sizeof(klogd_message) + 20 - 4]; char buffer[sizeof(priority_message) + sizeof(klogd_message) + 20 - 4];
snprintf(buffer, sizeof(buffer), klogd_message, priority_message, snprintf(buffer, sizeof(buffer), klogd_message, priority_message,

View file

@ -28,11 +28,11 @@
#include "LogListener.h" #include "LogListener.h"
LogListener::LogListener(LogBuffer *buf, LogReader *reader) LogListener::LogListener(LogBuffer *buf, LogReader *reader) :
: SocketListener(getLogSocket(), false) SocketListener(getLogSocket(), false),
, logbuf(buf) logbuf(buf),
, reader(reader) reader(reader) {
{ } }
bool LogListener::onDataAvailable(SocketClient *cli) { bool LogListener::onDataAvailable(SocketClient *cli) {
static bool name_set; static bool name_set;

View file

@ -24,10 +24,10 @@
#include "LogReader.h" #include "LogReader.h"
#include "FlushCommand.h" #include "FlushCommand.h"
LogReader::LogReader(LogBuffer *logbuf) LogReader::LogReader(LogBuffer *logbuf) :
: SocketListener(getLogSocket(), true) SocketListener(getLogSocket(), true),
, mLogbuf(*logbuf) mLogbuf(*logbuf) {
{ } }
// When we are notified a new log entry is available, inform // When we are notified a new log entry is available, inform
// all of our listening sockets. // all of our listening sockets.
@ -116,14 +116,14 @@ bool LogReader::onDataAvailable(SocketClient *cli) {
uint64_t last; uint64_t last;
public: public:
LogFindStart(unsigned logMask, pid_t pid, log_time &start, uint64_t &sequence) LogFindStart(unsigned logMask, pid_t pid, log_time &start, uint64_t &sequence) :
: mPid(pid) mPid(pid),
, mLogMask(logMask) mLogMask(logMask),
, startTimeSet(false) startTimeSet(false),
, start(start) start(start),
, sequence(sequence) sequence(sequence),
, last(sequence) last(sequence) {
{ } }
static int callback(const LogBufferElement *element, void *obj) { static int callback(const LogBufferElement *element, void *obj) {
LogFindStart *me = reinterpret_cast<LogFindStart *>(obj); LogFindStart *me = reinterpret_cast<LogFindStart *>(obj);

View file

@ -26,8 +26,7 @@
#include "LogStatistics.h" #include "LogStatistics.h"
LogStatistics::LogStatistics() LogStatistics::LogStatistics() : enable(false) {
: enable(false) {
log_id_for_each(id) { log_id_for_each(id) {
mSizes[id] = 0; mSizes[id] = 0;
mElements[id] = 0; mElements[id] = 0;

View file

@ -26,24 +26,23 @@ pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER;
LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client, LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
bool nonBlock, unsigned long tail, bool nonBlock, unsigned long tail,
unsigned int logMask, pid_t pid, unsigned int logMask, pid_t pid,
uint64_t start) uint64_t start) :
: mRefCount(1) mRefCount(1),
, mRelease(false) mRelease(false),
, mError(false) mError(false),
, threadRunning(false) threadRunning(false),
, mReader(reader) mReader(reader),
, mLogMask(logMask) mLogMask(logMask),
, mPid(pid) mPid(pid),
, mCount(0) mCount(0),
, mTail(tail) mTail(tail),
, mIndex(0) mIndex(0),
, mClient(client) mClient(client),
, mStart(start) mStart(start),
, mNonBlock(nonBlock) mNonBlock(nonBlock),
, mEnd(LogBufferElement::getCurrentSequence()) mEnd(LogBufferElement::getCurrentSequence()) {
{ pthread_cond_init(&threadTriggeredCondition, NULL);
pthread_cond_init(&threadTriggeredCondition, NULL); cleanSkip_Locked();
cleanSkip_Locked();
} }
void LogTimeEntry::startReader_Locked(void) { void LogTimeEntry::startReader_Locked(void) {

View file

@ -22,10 +22,8 @@
// White and Black list // White and Black list
Prune::Prune(uid_t uid, pid_t pid) Prune::Prune(uid_t uid, pid_t pid) : mUid(uid), mPid(pid) {
: mUid(uid) }
, mPid(pid)
{ }
int Prune::cmp(uid_t uid, pid_t pid) const { int Prune::cmp(uid_t uid, pid_t pid) const {
if ((mUid == uid_all) || (mUid == uid)) { if ((mUid == uid_all) || (mUid == uid)) {
@ -51,8 +49,7 @@ void Prune::format(char **strp) {
} }
} }
PruneList::PruneList() PruneList::PruneList() : mWorstUidEnabled(true) {
: mWorstUidEnabled(true) {
mNaughty.clear(); mNaughty.clear();
mNice.clear(); mNice.clear();
} }