Merge "logd: fix various clang-tidy issues" am: 4739f752e1
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1342013 Change-Id: I891a655abbdf9697024f51c22eeb18900f935cae
This commit is contained in:
commit
7a5ae6dd88
|
@ -61,7 +61,7 @@ LogBufferElement::LogBufferElement(const LogBufferElement& elem)
|
|||
}
|
||||
}
|
||||
|
||||
LogBufferElement::LogBufferElement(LogBufferElement&& elem)
|
||||
LogBufferElement::LogBufferElement(LogBufferElement&& elem) noexcept
|
||||
: uid_(elem.uid_),
|
||||
pid_(elem.pid_),
|
||||
tid_(elem.tid_),
|
||||
|
@ -134,7 +134,7 @@ char* android::tidToName(pid_t tid) {
|
|||
char* retval = nullptr;
|
||||
char buffer[256];
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%u/comm", tid);
|
||||
int fd = open(buffer, O_RDONLY);
|
||||
int fd = open(buffer, O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
ssize_t ret = read(fd, buffer, sizeof(buffer));
|
||||
if (ret >= (ssize_t)sizeof(buffer)) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class __attribute__((packed)) LogBufferElement {
|
|||
LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
|
||||
uint64_t sequence, const char* msg, uint16_t len);
|
||||
LogBufferElement(const LogBufferElement& elem);
|
||||
LogBufferElement(LogBufferElement&& elem);
|
||||
LogBufferElement(LogBufferElement&& elem) noexcept;
|
||||
~LogBufferElement();
|
||||
|
||||
uint32_t GetTag() const;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
class LogListener {
|
||||
public:
|
||||
LogListener(LogBuffer* buf);
|
||||
explicit LogListener(LogBuffer* buf);
|
||||
bool StartListener();
|
||||
|
||||
private:
|
||||
|
|
|
@ -89,7 +89,7 @@ bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid) {
|
|||
//
|
||||
for (int retry = 3; !(ret = foundGid && foundUid && foundLog) && retry;
|
||||
--retry) {
|
||||
FILE* file = fopen(filename, "r");
|
||||
FILE* file = fopen(filename, "re");
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
|
|||
if (cp) {
|
||||
logMask = 0;
|
||||
cp += sizeof(_logIds) - 1;
|
||||
while (*cp && *cp != '\0') {
|
||||
while (*cp != '\0') {
|
||||
int val = 0;
|
||||
while (isdigit(*cp)) {
|
||||
val = val * 10 + *cp - '0';
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include "LogBuffer.h"
|
||||
#include "LogReaderList.h"
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
LogReaderThread::LogReaderThread(LogBuffer* log_buffer, LogReaderList* reader_list,
|
||||
std::unique_ptr<LogWriter> writer, bool non_block,
|
||||
unsigned long tail, LogMask log_mask, pid_t pid,
|
||||
|
|
|
@ -88,7 +88,7 @@ char* pidToName(pid_t pid) {
|
|||
} else {
|
||||
char buffer[512];
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%u/cmdline", pid);
|
||||
int fd = open(buffer, O_RDONLY);
|
||||
int fd = open(buffer, O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
ssize_t ret = read(fd, buffer, sizeof(buffer));
|
||||
if (ret > 0) {
|
||||
|
@ -944,7 +944,7 @@ namespace android {
|
|||
uid_t pidToUid(pid_t pid) {
|
||||
char buffer[512];
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%u/status", pid);
|
||||
FILE* fp = fopen(buffer, "r");
|
||||
FILE* fp = fopen(buffer, "re");
|
||||
if (fp) {
|
||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||
int uid = AID_LOGD;
|
||||
|
|
|
@ -128,9 +128,9 @@ class LogHashtable {
|
|||
if (++index < (ssize_t)len) {
|
||||
size_t num = len - index - 1;
|
||||
if (num) {
|
||||
memmove(&out_keys[index + 1], &out_keys[index], num * sizeof(out_keys[0]));
|
||||
memmove(&out_keys[index + 1], &out_keys[index], num * sizeof(const TKey*));
|
||||
memmove(&out_entries[index + 1], &out_entries[index],
|
||||
num * sizeof(out_entries[0]));
|
||||
num * sizeof(const TEntry*));
|
||||
}
|
||||
out_keys[index] = &key;
|
||||
out_entries[index] = &entry;
|
||||
|
@ -477,15 +477,15 @@ class LogStatistics {
|
|||
tagNameTable.sizeOf() +
|
||||
(pidTable.size() * sizeof(pidTable_t::iterator)) +
|
||||
(tagTable.size() * sizeof(tagTable_t::iterator));
|
||||
for (auto it : pidTable) {
|
||||
for (const auto& it : pidTable) {
|
||||
const char* name = it.second.name();
|
||||
if (name) size += strlen(name) + 1;
|
||||
}
|
||||
for (auto it : tidTable) {
|
||||
for (const auto& it : tidTable) {
|
||||
const char* name = it.second.name();
|
||||
if (name) size += strlen(name) + 1;
|
||||
}
|
||||
for (auto it : tagNameTable) {
|
||||
for (const auto& it : tagNameTable) {
|
||||
size += sizeof(std::string);
|
||||
size_t len = it.first.size();
|
||||
// Account for short string optimization: if the string's length is <= 22 bytes for 64
|
||||
|
@ -505,7 +505,7 @@ class LogStatistics {
|
|||
}
|
||||
|
||||
public:
|
||||
LogStatistics(bool enable_statistics);
|
||||
explicit LogStatistics(bool enable_statistics);
|
||||
|
||||
void AddTotal(log_id_t log_id, uint16_t size) EXCLUDES(lock_);
|
||||
void Add(const LogStatisticsElement& entry) EXCLUDES(lock_);
|
||||
|
|
|
@ -60,7 +60,7 @@ void SerializedFlushToState::CreateLogPosition(log_id_t log_id) {
|
|||
}
|
||||
log_position.read_offset = read_offset;
|
||||
|
||||
log_positions_[log_id].emplace(std::move(log_position));
|
||||
log_positions_[log_id].emplace(log_position);
|
||||
}
|
||||
|
||||
void SerializedFlushToState::AddMinHeapEntry(log_id_t log_id) {
|
||||
|
@ -149,7 +149,7 @@ void SerializedFlushToState::Prune(log_id_t log_id,
|
|||
min_heap_.pop();
|
||||
}
|
||||
for (auto&& element : old_elements) {
|
||||
min_heap_.emplace(std::move(element));
|
||||
min_heap_.emplace(element);
|
||||
}
|
||||
|
||||
// Finally set logs_needed_from_next_position_, so CheckForNewLogs() will re-create the
|
||||
|
|
|
@ -208,6 +208,7 @@ bool SerializedLogBuffer::Prune(log_id_t log_id, size_t bytes_to_free, uid_t uid
|
|||
}
|
||||
|
||||
// Otherwise we are stuck due to a reader, so mitigate it.
|
||||
CHECK(oldest != nullptr);
|
||||
KickReader(oldest, log_id, bytes_to_free);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "SerializedLogEntry.h"
|
||||
#include "rwlock.h"
|
||||
|
||||
class SerializedLogBuffer : public LogBuffer {
|
||||
class SerializedLogBuffer final : public LogBuffer {
|
||||
public:
|
||||
SerializedLogBuffer(LogReaderList* reader_list, LogTags* tags, LogStatistics* stats);
|
||||
~SerializedLogBuffer();
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
class SerializedLogChunk {
|
||||
public:
|
||||
SerializedLogChunk(size_t size) : contents_(size) {}
|
||||
explicit SerializedLogChunk(size_t size) : contents_(size) {}
|
||||
~SerializedLogChunk();
|
||||
|
||||
void Compress();
|
||||
|
|
|
@ -31,7 +31,7 @@ class SimpleLogBuffer : public LogBuffer {
|
|||
public:
|
||||
SimpleLogBuffer(LogReaderList* reader_list, LogTags* tags, LogStatistics* stats);
|
||||
~SimpleLogBuffer();
|
||||
void Init() override;
|
||||
void Init() override final;
|
||||
|
||||
int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char* msg,
|
||||
uint16_t len) override;
|
||||
|
@ -42,7 +42,7 @@ class SimpleLogBuffer : public LogBuffer {
|
|||
|
||||
bool Clear(log_id_t id, uid_t uid) override;
|
||||
unsigned long GetSize(log_id_t id) override;
|
||||
int SetSize(log_id_t id, unsigned long size) override;
|
||||
int SetSize(log_id_t id, unsigned long size) override final;
|
||||
|
||||
uint64_t sequence() const override { return sequence_.load(std::memory_order_relaxed); }
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class SHARED_CAPABILITY("mutex") RwLock {
|
|||
|
||||
class SCOPED_CAPABILITY SharedLock {
|
||||
public:
|
||||
SharedLock(RwLock& lock) ACQUIRE_SHARED(lock) : lock_(lock) { lock_.lock_shared(); }
|
||||
explicit SharedLock(RwLock& lock) ACQUIRE_SHARED(lock) : lock_(lock) { lock_.lock_shared(); }
|
||||
~SharedLock() RELEASE() { lock_.unlock(); }
|
||||
|
||||
void lock_shared() ACQUIRE_SHARED() { lock_.lock_shared(); }
|
||||
|
|
Loading…
Reference in New Issue