From ffb6edd3dccc9d315cf54cd281e375a2dd2ea04e Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Tue, 1 Mar 2022 16:19:49 +0800 Subject: [PATCH 1/6] fix codex Signed-off-by: lyj_love_code --- frameworks/native/format.cpp | 13 +++++------ frameworks/native/hilog_base.cpp | 10 ++++----- .../native/hilog_input_socket_client.cpp | 9 ++++---- frameworks/native/hilog_printf.cpp | 8 +++---- frameworks/native/include/hilog_common.h | 11 +++++++++- .../include/hilog_input_socket_client.h | 5 +++-- .../native/seq_packet_socket_server.cpp | 4 ++-- frameworks/native/socket.cpp | 2 +- .../napi/src/hilog/src/hilog_napi_base.cpp | 4 ++-- services/hilogd/cmd_executor.cpp | 6 ++--- services/hilogd/flow_control_init.cpp | 8 +++---- services/hilogd/include/log_buffer.h | 6 ++--- services/hilogd/include/log_data.h | 4 +++- services/hilogd/kmsg_parser.cpp | 8 +++---- services/hilogd/log_buffer.cpp | 12 +++++----- services/hilogd/log_compress.cpp | 4 ++-- services/hilogd/log_kmsg.cpp | 2 +- services/hilogd/log_persister.cpp | 9 ++++---- services/hilogd/main.cpp | 10 ++++----- services/hilogd/service_controller.cpp | 2 +- services/hilogtool/log_controller.cpp | 22 +++++++++---------- services/hilogtool/log_display.cpp | 4 ++-- services/hilogtool/main.cpp | 14 ++++++------ 23 files changed, 95 insertions(+), 82 deletions(-) diff --git a/frameworks/native/format.cpp b/frameworks/native/format.cpp index 5126e9f..64854dc 100644 --- a/frameworks/native/format.cpp +++ b/frameworks/native/format.cpp @@ -61,7 +61,6 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, uint32_t showFormat, { time_t now = contentOut.tv_sec; unsigned long nsecTime = contentOut.tv_nsec; - struct tm* ptm = nullptr; size_t timeLen = 0; int ret = 0; nsecTime = (now < 0) ? (NSEC - nsecTime) : nsecTime; @@ -71,24 +70,24 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, uint32_t showFormat, (showFormat & (1 << MONOTONIC_SHOWFORMAT)) ? "%6lld" : "%19lld", (long long)now); timeLen += ((ret > 0) ? ret : 0); } else { - ptm = localtime(&now); - if (ptm == nullptr) { + struct tm tmLocal; + if (localtime_r(&now, &tmLocal) == nullptr) { return 0; } - timeLen = strftime(buffer, bufLen, "%m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); if (showFormat & (1 << YEAR_SHOWFORMAT)) { - timeLen = strftime(buffer, bufLen, "%Y-%m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%Y-%m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); } if (showFormat & (1 << ZONE_SHOWFORMAT)) { - timeLen = strftime(buffer, bufLen, "%z %m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%z %m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); } } if (showFormat & (1 << TIME_NSEC_SHOWFORMAT)) { ret = snprintf_s(buffer + timeLen, bufLen - timeLen, bufLen - timeLen - 1, - ".%09ld", nsecTime); + ".%09lu", nsecTime); timeLen += ((ret > 0) ? ret : 0); } else if (showFormat & (1 << TIME_USEC_SHOWFORMAT)) { ret = snprintf_s(buffer + timeLen, bufLen - timeLen, bufLen - timeLen - 1, diff --git a/frameworks/native/hilog_base.cpp b/frameworks/native/hilog_base.cpp index 3d66f11..081fb1c 100644 --- a/frameworks/native/hilog_base.cpp +++ b/frameworks/native/hilog_base.cpp @@ -100,7 +100,7 @@ static int CheckConnection(SocketHandler& socketHandler) return 0; } -static int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) +static int SendMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, uint16_t fmtLen) { SocketHandler socketHandler; int ret = CheckSocket(socketHandler); @@ -115,7 +115,7 @@ static int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char struct timeval tv = {0}; gettimeofday(&tv, nullptr); header->tv_sec = tv.tv_sec; - header->tv_nsec = tv.tv_usec * 1000; // 1000 : usec convert to nsec + header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; @@ -141,15 +141,15 @@ static int HiLogBasePrintArgs(const LogType type, const LogLevel level, const un vsnprintfp_s(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, HILOG_DEFAULT_PRIVACY, fmt, ap); - int tagLen = strnlen(tag, MAX_TAG_LEN - 1); - int logLen = strnlen(buf, MAX_LOG_LEN - 1); + auto tagLen = strnlen(tag, MAX_TAG_LEN - 1); + auto logLen = strnlen(buf, MAX_LOG_LEN - 1); HilogMsg header = {0}; header.type = type; header.level = level; #ifndef __RECV_MSG_WITH_UCRED_ header.pid = getpid(); #endif - header.tid = gettid(); + header.tid = static_cast(gettid()); header.domain = domain; return SendMessage(&header, tag, tagLen + 1, buf, logLen + 1); diff --git a/frameworks/native/hilog_input_socket_client.cpp b/frameworks/native/hilog_input_socket_client.cpp index a7f57bc..ea62bb4 100644 --- a/frameworks/native/hilog_input_socket_client.cpp +++ b/frameworks/native/hilog_input_socket_client.cpp @@ -22,13 +22,14 @@ namespace OHOS { namespace HiviewDFX { static HilogInputSocketClient g_hilogInputSocketClient; -extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) +extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, + uint16_t fmtLen) { return g_hilogInputSocketClient.WriteLogMessage(header, tag, tagLen, fmt, fmtLen); } -int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, - int fmtLen) +int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, + uint16_t fmtLen) { int ret = CheckSocket(); if (ret < 0) { @@ -38,7 +39,7 @@ int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, i struct timeval tv = {0}; gettimeofday(&tv, nullptr); header->tv_sec = tv.tv_sec; - header->tv_nsec = tv.tv_usec * 1000; // 1000 : usec convert to nsec + header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; diff --git a/frameworks/native/hilog_printf.cpp b/frameworks/native/hilog_printf.cpp index 224b3ca..e6d523d 100644 --- a/frameworks/native/hilog_printf.cpp +++ b/frameworks/native/hilog_printf.cpp @@ -232,7 +232,7 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int /* format log string */ debug = IsDebugOn(); priv = (!debug) && IsPrivateSwitchOn(); - + #ifdef __clang__ /* code specific to clang compiler */ #pragma clang diagnostic push @@ -250,14 +250,14 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int #endif /* fill header info */ - int tagLen = strnlen(tag, MAX_TAG_LEN - 1); - int logLen = strnlen(buf, MAX_LOG_LEN - 1); + auto tagLen = strnlen(tag, MAX_TAG_LEN - 1); + auto logLen = strnlen(buf, MAX_LOG_LEN - 1); header.type = type; header.level = level; #ifndef __RECV_MSG_WITH_UCRED_ header.pid = getpid(); #endif - header.tid = syscall(SYS_gettid); + header.tid = static_cast(syscall(SYS_gettid)); header.domain = domain; /* flow control */ diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index 154702a..d7d3c90 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -17,8 +17,9 @@ #define HILOG_COMMON_H #include -#include #include +#include +#include #define SOCKET_FILE_DIR "/dev/unix/socket/" #define INPUT_SOCKET_NAME "hilogInput" @@ -148,4 +149,12 @@ typedef enum { ERR_LOG_FILE_NUM_INVALID = -34, } ErrorCode; +inline const std::string HilogStrerror(int errnum) +{ + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + strerror_r(errnum, buf, bufSize); + return std::string(buf); +} + #endif /* HILOG_COMMON_H */ diff --git a/frameworks/native/include/hilog_input_socket_client.h b/frameworks/native/include/hilog_input_socket_client.h index bd4c4a2..0bea240 100644 --- a/frameworks/native/include/hilog_input_socket_client.h +++ b/frameworks/native/include/hilog_input_socket_client.h @@ -24,11 +24,12 @@ namespace HiviewDFX { class HilogInputSocketClient : DgramSocketClient { public: HilogInputSocketClient() : DgramSocketClient(INPUT_SOCKET_NAME, SOCK_NONBLOCK | SOCK_CLOEXEC) {}; - int WriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen); + int WriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, uint16_t fmtLen); ~HilogInputSocketClient() = default; }; } // namespace HiviewDFX } // namespace OHOS -extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen); +extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, + uint16_t fmtLen); #endif /* HILOG_INPUT_SOCKET_CLIENT_H */ diff --git a/frameworks/native/seq_packet_socket_server.cpp b/frameworks/native/seq_packet_socket_server.cpp index 8b2ae34..01f66d3 100644 --- a/frameworks/native/seq_packet_socket_server.cpp +++ b/frameworks/native/seq_packet_socket_server.cpp @@ -27,7 +27,7 @@ int SeqPacketSocketServer::StartAcceptingConnection(AcceptingHandler onAccepted) if (listeningStatus < 0) { #ifdef DEBUG std::cerr << "Socket listen failed: " << listeningStatus << "\n"; - std::cerr << strerror(listeningStatus) << "\n"; + std::cerr << HilogStrerror(listeningStatus) << "\n"; #endif return listeningStatus; } @@ -46,7 +46,7 @@ int SeqPacketSocketServer::AcceptingLoop(AcceptingHandler func) int acceptError = errno; #ifdef DEBUG std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr <(len); int midRes = 0; if (data == nullptr) { diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp index e686ac3..e8a991b 100644 --- a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -45,8 +45,8 @@ void ParseLogContent(string& formatStr, vector& params, string& logConte ret += formatStr; return; } - int32_t size = params.size(); - int32_t len = formatStr.size(); + auto size = params.size(); + auto len = formatStr.size(); int32_t pos = 0; int32_t count = 0; bool debug = IsDebugOn(); diff --git a/services/hilogd/cmd_executor.cpp b/services/hilogd/cmd_executor.cpp index 78bfeb9..93a7135 100644 --- a/services/hilogd/cmd_executor.cpp +++ b/services/hilogd/cmd_executor.cpp @@ -58,7 +58,7 @@ void CmdExecutor::MainLoop() int listeningStatus = cmdServer.Listen(MAX_CLIENT_CONNECTIONS); if (listeningStatus < 0) { std::cerr << "Socket listen failed: " << listeningStatus << "\n"; - std::cerr << strerror(listeningStatus) << "\n"; + std::cerr << HilogStrerror(listeningStatus) << "\n"; return; } std::cout << "Server started to listen !\n"; @@ -74,7 +74,7 @@ void CmdExecutor::MainLoop() } else if (pollResult < 0) { int pollError = errno; std::cerr << "Socket polling error: " << pollError << "\n"; - std::cerr << strerror(pollError) << "\n"; + std::cerr << HilogStrerror(pollError) << "\n"; break; } else if (pollResult != 1 || outEvent != POLLIN) { std::cerr << "Wrong poll result data." @@ -92,7 +92,7 @@ void CmdExecutor::MainLoop() } else { int acceptError = errno; std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr << strerror(acceptError) << "\n"; + std::cerr << HilogStrerror(acceptError) << "\n"; break; } } diff --git a/services/hilogd/flow_control_init.cpp b/services/hilogd/flow_control_init.cpp index caf40b9..3d0540c 100644 --- a/services/hilogd/flow_control_init.cpp +++ b/services/hilogd/flow_control_init.cpp @@ -112,8 +112,8 @@ void ParseDomainQuota(std::string &domainStr) return; } peakStr = domainStr.substr(domainNameEnd); - uint32_t domain = std::stoi(domainIdStr, nullptr, 0); - uint32_t peak = std::stoi(peakStr, nullptr, 0); + uint32_t domain = static_cast(std::stoi(domainIdStr, nullptr, 0)); + uint32_t peak = static_cast(std::stoi(peakStr, nullptr, 0)); if (domain <= 0 || peak <= 0) { return; } @@ -167,7 +167,7 @@ int FlowCtrlDomain(HilogMsg* hilogMsg) std::unordered_map::iterator it; uint32_t domain = hilogMsg->domain; uint32_t domainId = (domain & DOMAIN_FILTER) >> DOMAIN_FILTER_SUBSYSTEM; - int logLen = hilogMsg->len - sizeof(HilogMsg) - 1 - 1; /* quota length exclude '\0' of tag and log content */ + auto logLen = hilogMsg->len - sizeof(HilogMsg) - 1 - 1; /* quota length exclude '\0' of tag and log content */ int ret = 0; it = g_domainMap.find(domainId); if (it != g_domainMap.end()) { @@ -185,7 +185,7 @@ int FlowCtrlDomain(HilogMsg* hilogMsg) } else { /* new statistic period */ it->second->startTime = tsNow; it->second->sumLen = logLen; - ret = it->second->dropped; + ret = static_cast(it->second->dropped); it->second->dropped = 0; } } diff --git a/services/hilogd/include/log_buffer.h b/services/hilogd/include/log_buffer.h index 4e676ea..46919c1 100644 --- a/services/hilogd/include/log_buffer.h +++ b/services/hilogd/include/log_buffer.h @@ -43,9 +43,9 @@ public: ReaderId CreateBufReader(std::function onNewDataCallback); void RemoveBufReader(const ReaderId& id); - size_t Delete(uint16_t logType); - size_t GetBuffLen(uint16_t logType); - size_t SetBuffLen(uint16_t logType, uint64_t buffSize); + int32_t Delete(uint16_t logType); + int64_t GetBuffLen(uint16_t logType); + int32_t SetBuffLen(uint16_t logType, uint64_t buffSize); int32_t GetStatisticInfoByLog(uint16_t logType, uint64_t& printLen, uint64_t& cacheLen, int32_t& dropped); int32_t GetStatisticInfoByDomain(uint32_t domain, uint64_t& printLen, uint64_t& cacheLen, int32_t& dropped); int32_t ClearStatisticInfoByLog(uint16_t logType); diff --git a/services/hilogd/include/log_data.h b/services/hilogd/include/log_data.h index 1544646..2d1c649 100644 --- a/services/hilogd/include/log_data.h +++ b/services/hilogd/include/log_data.h @@ -77,7 +77,9 @@ struct HilogData { HilogData(HilogData&& cpy) { - std::memcpy(this, &cpy, sizeof(HilogData)); + if (memcpy_s(this, sizeof(HilogData), &cpy, sizeof(HilogData)) != 0) { + std::cerr << "HilogData memcpy_s call failed.\n"; + } cpy.tag = nullptr; cpy.content = nullptr; } diff --git a/services/hilogd/kmsg_parser.cpp b/services/hilogd/kmsg_parser.cpp index c7f763e..8021c62 100644 --- a/services/hilogd/kmsg_parser.cpp +++ b/services/hilogd/kmsg_parser.cpp @@ -138,7 +138,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km uint32_t mpid = ParsePid(kmsgStr); // If there are some other content wrapped in square brackets "[]", parse it as tag // Otherwise, use default tag "kmsg" - int tagLen = 0; + size_t tagLen = 0; std::string tagStr = ParseTag(kmsgStr); if (!tagStr.empty()) { tagLen = tagStr.size(); @@ -153,8 +153,8 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km } } // Now build HilogMsg and insert it into buffer - int len = kmsgStr.size() + 1; - int msgLen = sizeof(HilogMsg) + tagLen + len + 1; + auto len = kmsgStr.size() + 1; + auto msgLen = sizeof(HilogMsg) + tagLen + len + 1; HilogMsgWrapper msgWrap((std::vector(msgLen, '\0'))); HilogMsg& msg = msgWrap.GetHilogMsg(); msg.len = msgLen; @@ -165,7 +165,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km time_point logtime = BootTime() + microseconds{timestamp}; struct timespec logts = TimepointToTimespec(logtime); msg.tv_sec = logts.tv_sec; - msg.tv_nsec = logts.tv_nsec; + msg.tv_nsec = static_cast(logts.tv_nsec); msg.pid = mpid; msg.tid = mpid; if (strncpy_s(msg.tag, tagLen + 1, mtag.data(), tagLen) != 0) { diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 10eb040..b82d41c 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -26,7 +26,7 @@ using namespace std; const float DROP_RATIO = 0.05; static int g_maxBufferSize = 4194304; -static int g_maxBufferSizeByType[LOG_TYPE_MAX] = {262144, 262144, 262144, 262144, 262144}; +static size_t g_maxBufferSizeByType[LOG_TYPE_MAX] = {262144, 262144, 262144, 262144, 262144}; const int DOMAIN_STRICT_MASK = 0xd000000; const int DOMAIN_FUZZY_MASK = 0xdffff; const int DOMAIN_MODULE_BITS = 8; @@ -58,7 +58,7 @@ size_t HilogBuffer::Insert(const HilogMsg& msg) std::unique_lock lock(hilogBufferMutex); // Delete old entries when full - if (elemSize + sizeByType[msg.type] >= (size_t)g_maxBufferSizeByType[msg.type]) { + if (elemSize + sizeByType[msg.type] >= g_maxBufferSizeByType[msg.type]) { // Drop 5% of maximum log when full std::list::iterator it = msgList.begin(); while (sizeByType[msg.type] > g_maxBufferSizeByType[msg.type] * (1 - DROP_RATIO) && @@ -75,7 +75,7 @@ size_t HilogBuffer::Insert(const HilogMsg& msg) } // Re-confirm if enough elements has been removed - if (sizeByType[msg.type] >= (size_t)g_maxBufferSizeByType[msg.type]) { + if (sizeByType[msg.type] >= g_maxBufferSizeByType[msg.type]) { std::cout << "Failed to clean old logs." << std::endl; } } @@ -142,7 +142,7 @@ void HilogBuffer::UpdateStatistics(const HilogData& logData) } } -size_t HilogBuffer::Delete(uint16_t logType) +int32_t HilogBuffer::Delete(uint16_t logType) { std::list &msgList = (logType == (0b01 << LOG_KMSG)) ? hilogKlogList : hilogDataList; if (logType >= LOG_TYPE_MAX) { @@ -230,7 +230,7 @@ std::shared_ptr HilogBuffer::GetReader(const ReaderId return std::shared_ptr(); } -size_t HilogBuffer::GetBuffLen(uint16_t logType) +int64_t HilogBuffer::GetBuffLen(uint16_t logType) { if (logType >= LOG_TYPE_MAX) { return ERR_LOG_TYPE_INVALID; @@ -239,7 +239,7 @@ size_t HilogBuffer::GetBuffLen(uint16_t logType) return buffSize; } -size_t HilogBuffer::SetBuffLen(uint16_t logType, uint64_t buffSize) +int32_t HilogBuffer::SetBuffLen(uint16_t logType, uint64_t buffSize) { if (logType >= LOG_TYPE_MAX) { return ERR_LOG_TYPE_INVALID; diff --git a/services/hilogd/log_compress.cpp b/services/hilogd/log_compress.cpp index 78ac606..d64d4f5 100644 --- a/services/hilogd/log_compress.cpp +++ b/services/hilogd/log_compress.cpp @@ -44,8 +44,8 @@ int ZlibCompress::Compress(const LogPersisterBuffer &inBuffer, LogPersisterBuffe return -1; } size_t const toRead = CHUNK; - auto src_pos = 0; - auto dst_pos = 0; + size_t src_pos = 0; + size_t dst_pos = 0; size_t read = inBuffer.offset; int flush = 0; cStream.zalloc = Z_NULL; diff --git a/services/hilogd/log_kmsg.cpp b/services/hilogd/log_kmsg.cpp index 2ddd955..b0eee2e 100644 --- a/services/hilogd/log_kmsg.cpp +++ b/services/hilogd/log_kmsg.cpp @@ -57,7 +57,7 @@ int LogKmsg::LinuxReadAllKmsg() const ssize_t maxFailTime = 10; kmsgCtl = GetControlFile("/dev/kmsg"); if (kmsgCtl < 0) { - std::cout << "Cannot open kmsg! Err=" << strerror(errno) << std::endl; + std::cout << "Cannot open kmsg! Err=" << HilogStrerror(errno) << std::endl; return -1; } std::unique_ptr parser = std::make_unique(); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index bcd27da..06f9153 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -66,6 +66,7 @@ std::shared_ptr LogPersister::CreateLogPersister(HilogBuffer &buff LogPersister::LogPersister(HilogBuffer &buffer) : m_hilogBuffer(buffer) { + m_mappedPlainLogFile = nullptr; m_bufReader = m_hilogBuffer.CreateBufReader([this]() { NotifyNewLogAvailable(); }); } @@ -215,7 +216,7 @@ int LogPersister::Deinit() std::cout << "Removing unmapped plain log file: " << m_plainLogFilePath << "\n"; if (remove(m_plainLogFilePath.c_str())) { std::cerr << "File: " << m_plainLogFilePath << " can't be removed. " - << "Errno: " << errno << " " << strerror(errno) << "\n"; + << "Errno: " << errno << " " << HilogStrerror(errno) << "\n"; } DeregisterLogPersister(shared_from_this()); @@ -232,7 +233,7 @@ int LogPersister::PrepareUncompressedFile(const std::string& parentPath, bool re if (!plainTextFile) { std::cerr << __PRETTY_FUNCTION__ << " Open uncompressed log file(" << m_plainLogFilePath << ") failed: " - << strerror(errno) << "\n"; + << HilogStrerror(errno) << "\n"; return ERR_LOG_PERSIST_FILE_OPEN_FAIL; } @@ -245,10 +246,10 @@ int LogPersister::PrepareUncompressedFile(const std::string& parentPath, bool re MAP_SHARED, fileno(plainTextFile), 0); if (fclose(plainTextFile)) { std::cerr << "File: " << plainTextFile << " can't be closed. " - << "Errno: " << errno << " " << strerror(errno) << "\n"; + << "Errno: " << errno << " " << HilogStrerror(errno) << "\n"; } if (m_mappedPlainLogFile == MAP_FAILED) { - std::cerr << __PRETTY_FUNCTION__ << " mmap file failed: " << strerror(errno) << "\n"; + std::cerr << __PRETTY_FUNCTION__ << " mmap file failed: " << HilogStrerror(errno) << "\n"; return RET_FAIL; } if (restore == true) { diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index ec84747..0e516c9 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -144,7 +144,7 @@ int HilogdEntry() if (fd > 0) { g_fd = dup2(fd, fileno(stdout)); } else { - std::cout << "open file error:" << strerror(errno) << std::endl; + std::cout << "open file error:" << HilogStrerror(errno) << std::endl; } } #endif @@ -164,11 +164,11 @@ int HilogdEntry() logCollector.onDataRecv(cred, data); }; #endif - + HilogInputSocketServer incomingLogsServer(onDataReceive); if (incomingLogsServer.Init() < 0) { #ifdef DEBUG - cout << "Failed to init input server socket ! error=" << strerror(errno) << std::endl; + cout << "Failed to init input server socket ! error=" << HilogStrerror(errno) << std::endl; #endif } else { if (chmod(INPUT_SOCKET, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) { @@ -190,7 +190,7 @@ int HilogdEntry() LogKmsg logKmsg(hilogBuffer); logKmsg.ReadAllKmsg(); }); - + auto cgroupWriteTask = std::async(std::launch::async, [&hilogBuffer]() { prctl(PR_SET_NAME, "hilogd.cgroup_set"); string myPid = to_string(getpid()); @@ -198,7 +198,7 @@ int HilogdEntry() WriteStringToFile(myPid, SYSTEM_BG_CPUSET); WriteStringToFile(myPid, SYSTEM_BG_BLKIO); }); - + CmdExecutor cmdExecutor(hilogBuffer); cmdExecutor.MainLoop(); return 0; diff --git a/services/hilogd/service_controller.cpp b/services/hilogd/service_controller.cpp index 673dd74..c7982ab 100644 --- a/services/hilogd/service_controller.cpp +++ b/services/hilogd/service_controller.cpp @@ -286,7 +286,7 @@ void ServiceController::HandleBufferSizeRequest(const PacketBuf& rawData) int64_t buffLen = m_hilogBuffer.GetBuffLen(requestMsg->logType); if (pBuffSizeRst) { pBuffSizeRst->logType = requestMsg->logType; - pBuffSizeRst->buffSize = buffLen; + pBuffSizeRst->buffSize = static_cast(buffLen); pBuffSizeRst->result = (buffLen < 0) ? buffLen : RET_SUCCESS; pBuffSizeRst++; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index cb27e04..4d97f1a 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -93,7 +93,7 @@ uint16_t GetLogType(const string& logTypeStr) uint64_t GetBuffSize(const string& buffSizeStr) { uint64_t index = buffSizeStr.size() - 1; - uint64_t buffSize; + long int buffSize; std::regex reg("[0-9]+[bBkKmMgGtT]?"); if (!std::regex_match(buffSizeStr, reg)) { std::cout << ParseErrorCode(ERR_BUFF_SIZE_INVALID) << std::endl; @@ -112,7 +112,7 @@ uint64_t GetBuffSize(const string& buffSizeStr) } else { buffSize = stol(buffSizeStr.substr(0, index + 1)); } - return buffSize; + return static_cast(buffSize); } uint16_t GetCompressAlg(const std::string& pressAlg) @@ -223,7 +223,7 @@ void LogQueryResponseOp(SeqPacketSocketClient& controller, char* recvBuffer, uin while(1) { std::fill_n(recvBuffer, bufLen, 0); if (controller.RecvMsg(recvBuffer, bufLen) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", strerror(errno)); + fprintf(stderr, "Unexpected EOF %s\n", HilogStrerror(errno).c_str()); exit(1); return; } @@ -419,10 +419,10 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi } if (pLogPersistStartMsg->logType == (0b01 << LOG_KMSG)) { pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? DEFAULT_KMSG_JOBID - : stoi(logPersistParam->jobIdStr); + : static_cast(stoi(logPersistParam->jobIdStr)); } else { pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? DEFAULT_JOBID - : stoi(logPersistParam->jobIdStr); + : static_cast(stoi(logPersistParam->jobIdStr)); } if (pLogPersistStartMsg->jobId <= 0) { cout << ParseErrorCode(ERR_LOG_PERSIST_JOBID_INVALID) << endl; @@ -433,7 +433,7 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi pLogPersistStartMsg->fileSize = (logPersistParam->fileSizeStr == "") ? fileSizeDefault : GetBuffSize( logPersistParam->fileSizeStr); pLogPersistStartMsg->fileNum = (logPersistParam->fileNumStr == "") ? fileNumDefault - : stoi(logPersistParam->fileNumStr); + : static_cast(stoi(logPersistParam->fileNumStr)); if (logPersistParam->fileNameStr.size() > FILE_PATH_MAX_LEN) { cout << ParseErrorCode(ERR_LOG_PERSIST_FILE_NAME_INVALID) << endl; return RET_FAIL; @@ -462,7 +462,7 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi return RET_FAIL; } for (iter = 0; iter < jobIdNum; iter++) { - pLogPersistStopMsg->jobId = stoi(vecJobId[iter]); + pLogPersistStopMsg->jobId = static_cast(stoi(vecJobId[iter])); pLogPersistStopMsg++; } SetMsgHead(&pLogPersistStopReq->msgHeader, msgCmd, sizeof(LogPersistStopMsg) * jobIdNum); @@ -603,14 +603,14 @@ int32_t SetPropertiesOp(SeqPacketSocketClient& controller, uint8_t operationType int MultiQuerySplit(const std::string& src, const char& delim, std::vector& vecSplit) { - int srcSize = src.length(); - int findPos = 0; - int getPos = 0; + auto srcSize = src.length(); + string::size_type findPos = 0; + string::size_type getPos = 0; vecSplit.clear(); while (getPos < srcSize) { findPos = src.find(delim, findPos); - if (-1 == findPos) { + if (string::npos == findPos) { if (getPos < srcSize) { vecSplit.push_back(src.substr(getPos, srcSize - getPos)); return 0; diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 3354e07..4e0a76a 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -68,7 +68,7 @@ unordered_map errorMsg {ERR_KMSG_SWITCH_VALUE_INVALID, "Invalid kmsg switch value, valid:on/off"}, {ERR_LOG_FILE_NUM_INVALID, "Invalid log number, log number should be more than " + to_string(MIN_LOG_FILE_NUM) + " and less than " + to_string(MAX_LOG_FILE_NUM)}, -}; +}; string ParseErrorCode(ErrorCode errorCode) { @@ -476,7 +476,7 @@ void HilogShowLog(uint32_t showFormat, HilogDataMessage* data, const HilogArgs* showBuffer.tag_len = data->tag_len; showBuffer.tv_sec = data->tv_sec; showBuffer.tv_nsec = data->tv_nsec; - int offset = data->tag_len; + auto offset = data->tag_len; const char *dataBegin = data->data + offset; char *dataPos = data->data + offset; while (*dataPos != 0) { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index d35e920..c2e2615 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -115,7 +115,7 @@ static void Helper() ); } -static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) +static uint16_t GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) { uint16_t types = 0; if (exclude) { @@ -138,7 +138,7 @@ static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = f return types; } -static int GetLevels(HilogArgs context, const string& levelsArgs, bool exclude = false) +static uint16_t GetLevels(HilogArgs context, const string& levelsArgs, bool exclude = false) { uint16_t levels = 0; if (exclude) { @@ -230,10 +230,10 @@ int HilogEntry(int argc, char* argv[]) context.regexArgs = optarg; break; case 'a': - context.headLines = atoi(optarg); + context.headLines = static_cast(atoi(optarg)); break; case 'z': - context.tailLines = atoi(optarg); + context.tailLines = static_cast(atoi(optarg)); context.noBlockMode = 1; break; case 't': @@ -595,9 +595,9 @@ int HilogEntry(int argc, char* argv[]) char recvBuffer[RECV_BUF_LEN] = {0}; if (controller.RecvMsg(recvBuffer, RECV_BUF_LEN) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", strerror(errno)); - exit(1); - return 0; + fprintf(stderr, "Unexpected EOF %s\n", HilogStrerror(errno).c_str()); + exit(1); + return 0; } MessageHeader* msgHeader = reinterpret_cast(recvBuffer); -- Gitee From d4b2e9dfb218a36701c78e1347d3a294ef6fed09 Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Tue, 1 Mar 2022 18:02:58 +0800 Subject: [PATCH 2/6] change HilogStrerror to HilogPrintError Signed-off-by: lyj_love_code --- frameworks/native/include/hilog_common.h | 6 +++--- frameworks/native/seq_packet_socket_server.cpp | 8 ++++---- services/hilogd/cmd_executor.cpp | 14 ++++++-------- services/hilogd/log_kmsg.cpp | 3 ++- services/hilogd/log_persister.cpp | 15 ++++++++------- services/hilogd/main.cpp | 6 ++++-- services/hilogtool/log_controller.cpp | 3 ++- services/hilogtool/main.cpp | 3 ++- 8 files changed, 31 insertions(+), 27 deletions(-) diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index d7d3c90..5b387bd 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -17,8 +17,8 @@ #define HILOG_COMMON_H #include +#include #include -#include #include #define SOCKET_FILE_DIR "/dev/unix/socket/" @@ -149,12 +149,12 @@ typedef enum { ERR_LOG_FILE_NUM_INVALID = -34, } ErrorCode; -inline const std::string HilogStrerror(int errnum) +inline void HilogPrintError(int errnum) { constexpr int bufSize = 1024; char buf[bufSize] = { 0 }; strerror_r(errnum, buf, bufSize); - return std::string(buf); + std::cerr << "Errno: " << errnum << ", " << buf << "\n"; } #endif /* HILOG_COMMON_H */ diff --git a/frameworks/native/seq_packet_socket_server.cpp b/frameworks/native/seq_packet_socket_server.cpp index 01f66d3..f37e5aa 100644 --- a/frameworks/native/seq_packet_socket_server.cpp +++ b/frameworks/native/seq_packet_socket_server.cpp @@ -26,8 +26,8 @@ int SeqPacketSocketServer::StartAcceptingConnection(AcceptingHandler onAccepted) int listeningStatus = Listen(maxListenNumber); if (listeningStatus < 0) { #ifdef DEBUG - std::cerr << "Socket listen failed: " << listeningStatus << "\n"; - std::cerr << HilogStrerror(listeningStatus) << "\n"; + std::cerr << "Socket listen failed: "; + HilogPrintError(listeningStatus); #endif return listeningStatus; } @@ -45,8 +45,8 @@ int SeqPacketSocketServer::AcceptingLoop(AcceptingHandler func) } int acceptError = errno; #ifdef DEBUG - std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr << HilogStrerror(acceptError) << "\n"; + std::cerr << "Socket accept failed: "; + HilogPrintError(acceptError); #endif return acceptError; diff --git a/services/hilogd/cmd_executor.cpp b/services/hilogd/cmd_executor.cpp index 93a7135..8fd7bfa 100644 --- a/services/hilogd/cmd_executor.cpp +++ b/services/hilogd/cmd_executor.cpp @@ -57,8 +57,8 @@ void CmdExecutor::MainLoop() std::cout << "Begin to cmd accept !\n"; int listeningStatus = cmdServer.Listen(MAX_CLIENT_CONNECTIONS); if (listeningStatus < 0) { - std::cerr << "Socket listen failed: " << listeningStatus << "\n"; - std::cerr << HilogStrerror(listeningStatus) << "\n"; + std::cerr << "Socket listen failed: "; + HilogPrintError(listeningStatus); return; } std::cout << "Server started to listen !\n"; @@ -72,9 +72,8 @@ void CmdExecutor::MainLoop() CleanFinishedClients(); continue; } else if (pollResult < 0) { - int pollError = errno; - std::cerr << "Socket polling error: " << pollError << "\n"; - std::cerr << HilogStrerror(pollError) << "\n"; + std::cerr << "Socket polling error: "; + HilogPrintError(errno); break; } else if (pollResult != 1 || outEvent != POLLIN) { std::cerr << "Wrong poll result data." @@ -90,9 +89,8 @@ void CmdExecutor::MainLoop() handler->setHandler(acceptedSockedFd); OnAcceptedConnection(std::move(handler)); } else { - int acceptError = errno; - std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr << HilogStrerror(acceptError) << "\n"; + std::cerr << "Socket accept failed: "; + HilogPrintError(errno); break; } } diff --git a/services/hilogd/log_kmsg.cpp b/services/hilogd/log_kmsg.cpp index b0eee2e..a96c4f9 100644 --- a/services/hilogd/log_kmsg.cpp +++ b/services/hilogd/log_kmsg.cpp @@ -57,7 +57,8 @@ int LogKmsg::LinuxReadAllKmsg() const ssize_t maxFailTime = 10; kmsgCtl = GetControlFile("/dev/kmsg"); if (kmsgCtl < 0) { - std::cout << "Cannot open kmsg! Err=" << HilogStrerror(errno) << std::endl; + std::cout << "Cannot open kmsg! "; + HilogPrintError(errno); return -1; } std::unique_ptr parser = std::make_unique(); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index 06f9153..8bd8610 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -215,8 +215,8 @@ int LogPersister::Deinit() munmap(m_mappedPlainLogFile, MAX_PERSISTER_BUFFER_SIZE); std::cout << "Removing unmapped plain log file: " << m_plainLogFilePath << "\n"; if (remove(m_plainLogFilePath.c_str())) { - std::cerr << "File: " << m_plainLogFilePath << " can't be removed. " - << "Errno: " << errno << " " << HilogStrerror(errno) << "\n"; + std::cerr << "File: " << m_plainLogFilePath << " can't be removed. "; + HilogPrintError(errno); } DeregisterLogPersister(shared_from_this()); @@ -232,8 +232,8 @@ int LogPersister::PrepareUncompressedFile(const std::string& parentPath, bool re FILE* plainTextFile = fopen(m_plainLogFilePath.c_str(), restore ? "r+" : "w+"); if (!plainTextFile) { - std::cerr << __PRETTY_FUNCTION__ << " Open uncompressed log file(" << m_plainLogFilePath << ") failed: " - << HilogStrerror(errno) << "\n"; + std::cerr << __PRETTY_FUNCTION__ << " Open uncompressed log file(" << m_plainLogFilePath << ") failed: "; + HilogPrintError(errno); return ERR_LOG_PERSIST_FILE_OPEN_FAIL; } @@ -245,11 +245,12 @@ int LogPersister::PrepareUncompressedFile(const std::string& parentPath, bool re m_mappedPlainLogFile = (LogPersisterBuffer *)mmap(nullptr, sizeof(LogPersisterBuffer), PROT_READ | PROT_WRITE, MAP_SHARED, fileno(plainTextFile), 0); if (fclose(plainTextFile)) { - std::cerr << "File: " << plainTextFile << " can't be closed. " - << "Errno: " << errno << " " << HilogStrerror(errno) << "\n"; + std::cerr << "File: " << plainTextFile << " can't be closed. "; + HilogPrintError(errno); } if (m_mappedPlainLogFile == MAP_FAILED) { - std::cerr << __PRETTY_FUNCTION__ << " mmap file failed: " << HilogStrerror(errno) << "\n"; + std::cerr << __PRETTY_FUNCTION__ << " mmap file failed: "; + HilogPrintError(errno); return RET_FAIL; } if (restore == true) { diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index 0e516c9..513c16f 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -144,7 +144,8 @@ int HilogdEntry() if (fd > 0) { g_fd = dup2(fd, fileno(stdout)); } else { - std::cout << "open file error:" << HilogStrerror(errno) << std::endl; + std::cout << "open file error: "; + HilogPrintError(errno); } } #endif @@ -168,7 +169,8 @@ int HilogdEntry() HilogInputSocketServer incomingLogsServer(onDataReceive); if (incomingLogsServer.Init() < 0) { #ifdef DEBUG - cout << "Failed to init input server socket ! error=" << HilogStrerror(errno) << std::endl; + cout << "Failed to init input server socket ! "; + HilogPrintError(errno); #endif } else { if (chmod(INPUT_SOCKET, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) { diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index 4d97f1a..9addb78 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -223,7 +223,8 @@ void LogQueryResponseOp(SeqPacketSocketClient& controller, char* recvBuffer, uin while(1) { std::fill_n(recvBuffer, bufLen, 0); if (controller.RecvMsg(recvBuffer, bufLen) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", HilogStrerror(errno).c_str()); + fprintf(stderr, "Unexpected EOF "); + HilogPrintError(errno); exit(1); return; } diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index c2e2615..27ef4e1 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -595,7 +595,8 @@ int HilogEntry(int argc, char* argv[]) char recvBuffer[RECV_BUF_LEN] = {0}; if (controller.RecvMsg(recvBuffer, RECV_BUF_LEN) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", HilogStrerror(errno).c_str()); + fprintf(stderr, "Unexpected EOF "); + HilogPrintError(errno); exit(1); return 0; } -- Gitee From b9f2c53934d6c9ba3a1403ada8c32457edda8906 Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Wed, 2 Mar 2022 01:19:33 +0000 Subject: [PATCH 3/6] Before sysparam module supply "get_global_commitid", using a temporary solution to reduce calling count of FindParameter Signed-off-by: yaomanhai --- adapter/properties.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adapter/properties.cpp b/adapter/properties.cpp index 048647f..aa62ef4 100644 --- a/adapter/properties.cpp +++ b/adapter/properties.cpp @@ -100,8 +100,12 @@ public: T getValue() { if (m_handle == -1) { + if (m_commit == 0) { // temparary solution, after sysparam supply get_global_commitid, FIXME + return m_defaultValue; + } auto handle = FindParameter(m_key.c_str()); if (handle == -1) { + m_commit = 0; // temparary solution, after sysparam supply get_global_commitid, FIXME return m_defaultValue; } m_handle = handle; -- Gitee From 229d9d993cd819419459f551c108822ee1f1ae83 Mon Sep 17 00:00:00 2001 From: yudechen Date: Wed, 2 Mar 2022 11:31:06 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=8C=87=E5=AE=9A=E9=83=A8=E4=BB=B6=E5=92=8C?= =?UTF-8?q?=E5=AD=90=E7=B3=BB=E7=BB=9F=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit re #I4VWH5 Signed-off-by: yudechen Change-Id: I256ab14db95d251ac350ecbc3b418af1bda5e121 --- interfaces/native/innerkits/BUILD.gn | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index f8c5b4d..0edb75e 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -64,4 +64,7 @@ ohos_static_library("libhilog_base") { public_configs = [ ":libhilog_base_cfg" ] configs = [ ":libhilog_base_cfg" ] + + subsystem_name = "hiviewdfx" + part_name = "hilog_native" } -- Gitee From 1bb5cc422b9ce2231080ad3efef63b951317fa2a Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Sat, 5 Mar 2022 10:58:30 +0800 Subject: [PATCH 5/6] fix codex Signed-off-by: lyj_love_code --- frameworks/native/hilog_base.cpp | 2 +- frameworks/native/hilog_input_socket_client.cpp | 2 +- interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp | 4 ++-- services/hilogd/kmsg_parser.cpp | 2 +- services/hilogd/log_buffer.cpp | 2 +- services/hilogd/main.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frameworks/native/hilog_base.cpp b/frameworks/native/hilog_base.cpp index 081fb1c..00a0e35 100644 --- a/frameworks/native/hilog_base.cpp +++ b/frameworks/native/hilog_base.cpp @@ -114,7 +114,7 @@ static int SendMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const struct timeval tv = {0}; gettimeofday(&tv, nullptr); - header->tv_sec = tv.tv_sec; + header->tv_sec = static_cast(tv.tv_sec); header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; diff --git a/frameworks/native/hilog_input_socket_client.cpp b/frameworks/native/hilog_input_socket_client.cpp index ea62bb4..19f4355 100644 --- a/frameworks/native/hilog_input_socket_client.cpp +++ b/frameworks/native/hilog_input_socket_client.cpp @@ -38,7 +38,7 @@ int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, u struct timeval tv = {0}; gettimeofday(&tv, nullptr); - header->tv_sec = tv.tv_sec; + header->tv_sec = static_cast(tv.tv_sec); header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp index e8a991b..79e99ee 100644 --- a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -47,8 +47,8 @@ void ParseLogContent(string& formatStr, vector& params, string& logConte } auto size = params.size(); auto len = formatStr.size(); - int32_t pos = 0; - int32_t count = 0; + uint32_t pos = 0; + uint32_t count = 0; bool debug = IsDebugOn(); bool priv = (!debug) && IsPrivateSwitchOn(); diff --git a/services/hilogd/kmsg_parser.cpp b/services/hilogd/kmsg_parser.cpp index 8021c62..bcad6e4 100644 --- a/services/hilogd/kmsg_parser.cpp +++ b/services/hilogd/kmsg_parser.cpp @@ -164,7 +164,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km msg.level = KmsgLevelMap(mLevel); time_point logtime = BootTime() + microseconds{timestamp}; struct timespec logts = TimepointToTimespec(logtime); - msg.tv_sec = logts.tv_sec; + msg.tv_sec = static_cast(logts.tv_sec); msg.tv_nsec = static_cast(logts.tv_nsec); msg.pid = mpid; msg.tid = mpid; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index b82d41c..4b38c1f 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -25,7 +25,7 @@ namespace HiviewDFX { using namespace std; const float DROP_RATIO = 0.05; -static int g_maxBufferSize = 4194304; +static size_t g_maxBufferSize = 4194304; static size_t g_maxBufferSizeByType[LOG_TYPE_MAX] = {262144, 262144, 262144, 262144, 262144}; const int DOMAIN_STRICT_MASK = 0xd000000; const int DOMAIN_FUZZY_MASK = 0xdffff; diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index 513c16f..3dc165f 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -111,7 +111,7 @@ static bool WriteStringToFile(int fd, const std::string& content) return false; } p += n; - remaining -= n; + remaining -= static_cast(n); } return true; } -- Gitee From 2fc75dce76cc6503f5db39820d2d4f7db9f76ba7 Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Mon, 7 Mar 2022 11:09:06 +0800 Subject: [PATCH 6/6] add syscap to bundle.json Signed-off-by: lyj_love_code --- bundle.json | 3 +++ interfaces/bundle.json | 5 ++++- interfaces/native/bundle.json | 3 +++ services/bundle.json | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 693bd3d..c465107 100644 --- a/bundle.json +++ b/bundle.json @@ -12,6 +12,9 @@ "component": { "name": "hilog", "subsystem": "hiviewdfx", + "syscap": [ + "SystemCapability.HiviewDFX.HiLog" + ], "adapted_system_type": [ "standard" ], diff --git a/interfaces/bundle.json b/interfaces/bundle.json index d3a3d29..99643e9 100644 --- a/interfaces/bundle.json +++ b/interfaces/bundle.json @@ -12,6 +12,9 @@ "component": { "name": "hilog_native", "subsystem": "hiviewdfx", + "syscap": [ + "SystemCapability.HiviewDFX.HiLog" + ], "adapted_system_type": [ "standard" ], @@ -60,4 +63,4 @@ "test": [] } } -} +} diff --git a/interfaces/native/bundle.json b/interfaces/native/bundle.json index 5687e9e..414854b 100644 --- a/interfaces/native/bundle.json +++ b/interfaces/native/bundle.json @@ -12,6 +12,9 @@ "component": { "name": "hiviewdfx_hilog_native", "subsystem": "hiviewdfx", + "syscap": [ + "SystemCapability.HiviewDFX.HiLog" + ], "adapted_system_type": [ "standard" ], diff --git a/services/bundle.json b/services/bundle.json index d46f6c9..2a3e161 100644 --- a/services/bundle.json +++ b/services/bundle.json @@ -12,6 +12,9 @@ "component": { "name": "hilog_service", "subsystem": "hiviewdfx", + "syscap": [ + "SystemCapability.HiviewDFX.HiLog" + ], "adapted_system_type": [ "standard" ], -- Gitee