From 2c2ef91400a825774ae6f2b3a85271c50d795674 Mon Sep 17 00:00:00 2001 From: Vincen Date: Mon, 19 Sep 2022 12:46:13 +0800 Subject: [PATCH 1/5] get domain whitelist Signed-off-by: Vincen --- frameworks/libhilog/include/hilog_cmd.h | 16 ++++ frameworks/libhilog/ioctl/include/log_ioctl.h | 4 + frameworks/libhilog/ioctl/log_ioctl.cpp | 70 +++++++++++++++++ frameworks/libhilog/utils/include/log_utils.h | 5 ++ services/hilogd/include/log_domains.h | 4 + services/hilogd/include/service_controller.h | 5 +- services/hilogd/log_domains.cpp | 8 +- services/hilogd/main.cpp | 1 + services/hilogd/service_controller.cpp | 76 +++++++++++++++++++ services/hilogtool/include/log_display.h | 1 + services/hilogtool/log_display.cpp | 20 +++++ services/hilogtool/main.cpp | 16 ++++ 12 files changed, 222 insertions(+), 4 deletions(-) diff --git a/frameworks/libhilog/include/hilog_cmd.h b/frameworks/libhilog/include/hilog_cmd.h index 1043e1b..03b61e7 100644 --- a/frameworks/libhilog/include/hilog_cmd.h +++ b/frameworks/libhilog/include/hilog_cmd.h @@ -26,6 +26,7 @@ #define MAX_FILE_NAME_LEN (64) #define MAX_STREAM_NAME_LEN (16) #define MAX_PROC_NAME_LEN (32) +#define MAX_DOMAIN_NAME_LEN (32) constexpr int LevelBase = static_cast(LOG_DEBUG); constexpr int LevelNum = static_cast(LOG_LEVEL_MAX) - LevelBase; @@ -55,6 +56,8 @@ enum class IoctlCmd { LOG_REMOVE_RSP, KMSG_ENABLE_RQST, KMSG_ENABLE_RSP, + DOMAIN_WHITELIST_RQST, + DOMAIN_WHITELIST_RSP, // Process error response with same logic RSP_ERROR, CMD_COUNT @@ -258,4 +261,17 @@ struct KmsgEnableRqst { struct KmsgEnableRsp { char placeholder; } __attribute__((__packed__)); + +struct DomainDetail { + uint32_t domain; + char domainName[MAX_DOMAIN_NAME_LEN]; +} __attribute__((__packed__)); + +struct WhitelistRqst { +} __attribute__((__packed__)); + +struct WhitelistRsp { + uint16_t domainNum; + DomainDetail* ddetail; +} __attribute__((__packed__)); #endif /* HILOG_CMD_H */ \ No newline at end of file diff --git a/frameworks/libhilog/ioctl/include/log_ioctl.h b/frameworks/libhilog/ioctl/include/log_ioctl.h index 8dc53ff..de9a79a 100644 --- a/frameworks/libhilog/ioctl/include/log_ioctl.h +++ b/frameworks/libhilog/ioctl/include/log_ioctl.h @@ -38,6 +38,7 @@ public: int Request(const T1& rqst, std::function handle); int RequestOutput(const OutputRqst& rqst, std::function handle); int RequestStatsQuery(const StatsQueryRqst& rqst, std::function handle); + int RequestWhitelist(const WhitelistRqst& rqst, std::function handle); private: SeqPacketSocketClient socket; @@ -61,6 +62,9 @@ private: int ReceiveDomainStats(StatsQueryRsp &rsp); int ReceiveLogTypeDomainStats(StatsQueryRsp &rsp); void DeleteLogStatsInfo(StatsQueryRsp &rsp); + int ReceiveWhitelist(WhitelistRsp &rsp); + void DeleteWhitelistInfo(WhitelistRsp &rsp); + int ReceiveAndProcessWhitelistRsp(std::function handle); }; template diff --git a/frameworks/libhilog/ioctl/log_ioctl.cpp b/frameworks/libhilog/ioctl/log_ioctl.cpp index 9994597..5e01a17 100644 --- a/frameworks/libhilog/ioctl/log_ioctl.cpp +++ b/frameworks/libhilog/ioctl/log_ioctl.cpp @@ -298,6 +298,43 @@ void LogIoctl::DeleteLogStatsInfo(StatsQueryRsp &rsp) } } +int LogIoctl::ReceiveWhitelist(WhitelistRsp &rsp) +{ + if (rsp.domainNum == 0) { + return RET_FAIL; + } + int msgSize = rsp.domainNum * sizeof(DomainDetail); + if (msgSize == 0) { + return RET_SUCCESS; + } + char* tmp = new (std::nothrow) char[msgSize]; + if (tmp == nullptr) { + rsp.ddetail = nullptr; + return RET_FAIL; + } + if (memset_s(tmp, msgSize, 0, msgSize) != 0) { + delete []tmp; + tmp = nullptr; + return RET_FAIL; + } + if (GetRsp(tmp, msgSize) != RET_SUCCESS) { + rsp.ddetail = nullptr; + delete []tmp; + tmp = nullptr; + return RET_FAIL; + } + rsp.ddetail = reinterpret_cast(tmp); + return RET_SUCCESS; +} + +void LogIoctl::DeleteWhitelistInfo(WhitelistRsp &rsp) +{ + if (rsp.ddetail == nullptr) { + return; + } + delete []rsp.ddetail; + rsp.ddetail = nullptr; +} int LogIoctl::RequestOutput(const OutputRqst& rqst, std::function handle) { // 0. Send reqeust message and process the response header @@ -379,5 +416,38 @@ int LogIoctl::ReceiveAndProcessStatsQueryRsp(std::function handle) +{ + // 0. Send reqeust message and process the response header + int ret = RequestMsgHead(rqst); + if (ret != RET_SUCCESS) { + return ret; + } + // 1. process the response message + return ReceiveAndProcessWhitelistRsp(handle); +} + +int LogIoctl::ReceiveAndProcessWhitelistRsp(std::function handle) +{ + int ret; + WhitelistRsp rsp = { 0 }; + do { + ret = GetRsp(reinterpret_cast(&rsp), sizeof(rsp)); + if (RET_SUCCESS != ret) { + break; + } + rsp.ddetail = nullptr; + ret = ReceiveWhitelist(rsp); + if (RET_SUCCESS != ret) { + break; + } + } while (0); + if (ret == RET_SUCCESS) { + ret = handle(rsp); + } + DeleteWhitelistInfo(rsp); + return ret; +} } // namespace HiviewDFX } // namespace OHOS \ No newline at end of file diff --git a/frameworks/libhilog/utils/include/log_utils.h b/frameworks/libhilog/utils/include/log_utils.h index acd6746..f833f8d 100644 --- a/frameworks/libhilog/utils/include/log_utils.h +++ b/frameworks/libhilog/utils/include/log_utils.h @@ -60,6 +60,11 @@ public: { return (str_map.find(key) != str_map.end()); } + + const std::unordered_map& GetMap() const + { + return str_map; + } private: const std::unordered_map str_map; diff --git a/services/hilogd/include/log_domains.h b/services/hilogd/include/log_domains.h index 680e294..5675948 100644 --- a/services/hilogd/include/log_domains.h +++ b/services/hilogd/include/log_domains.h @@ -15,11 +15,15 @@ #ifndef LOG_DOMAINS_H #define LOG_DOMAINS_H + +#include +#include #include namespace OHOS { namespace HiviewDFX { bool IsValidDomain(LogType type, uint32_t domain); +const std::unordered_map& GetDomainList(); } // namespace HiviewDFX } // namespace OHOS #endif /* LOG_DOMAINS_H */ \ No newline at end of file diff --git a/services/hilogd/include/service_controller.h b/services/hilogd/include/service_controller.h index 41e14f0..39f95c5 100644 --- a/services/hilogd/include/service_controller.h +++ b/services/hilogd/include/service_controller.h @@ -82,9 +82,12 @@ private: void HandleDomainFlowCtrlRqst(const DomainFlowCtrlRqst& rqst); void HandleLogRemoveRqst(const LogRemoveRqst& rqst); void HandleLogKmsgEnableRqst(const KmsgEnableRqst& rqst); - + void HandleWhitelistRqst(const WhitelistRqst& rqst); void NotifyForNewData(); bool IsValidCmd(const CmdList& list, IoctlCmd cmd); + void SendOverallWhitelist(std::unordered_map& dlist); + void SendDomainDetail(std::unordered_map& dlist); + std::unique_ptr m_communicationSocket; HilogBuffer& m_hilogBuffer; diff --git a/services/hilogd/log_domains.cpp b/services/hilogd/log_domains.cpp index 6e0a047..ed3c3c7 100644 --- a/services/hilogd/log_domains.cpp +++ b/services/hilogd/log_domains.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ -#include -#include - #include "log_domains.h" namespace OHOS { @@ -85,5 +82,10 @@ bool IsValidDomain(LogType type, uint32_t domain) return false; } } + +const std::unordered_map& GetDomainList() +{ + return g_DomainList.GetMap(); +} } // namespace HiviewDFX } // namespace OHOS \ No newline at end of file diff --git a/services/hilogd/main.cpp b/services/hilogd/main.cpp index 1086401..9bd7f5d 100644 --- a/services/hilogd/main.cpp +++ b/services/hilogd/main.cpp @@ -231,6 +231,7 @@ int HilogdEntry() IoctlCmd::DOMAIN_FLOWCTRL_RQST, IoctlCmd::LOG_REMOVE_RQST, IoctlCmd::KMSG_ENABLE_RQST, + IoctlCmd::DOMAIN_WHITELIST_RQST, }; CmdExecutor controlExecutor(hilogBuffer, controlCmdList, ("hilogd.control")); controlExecutor.MainLoop(CONTROL_SOCKET_NAME); diff --git a/services/hilogd/service_controller.cpp b/services/hilogd/service_controller.cpp index 4637fc9..ddd816d 100644 --- a/services/hilogd/service_controller.cpp +++ b/services/hilogd/service_controller.cpp @@ -39,6 +39,7 @@ #include "log_buffer.h" #include "log_utils.h" #include "log_kmsg.h" +#include "log_domains.h" #include "service_controller.h" @@ -147,6 +148,44 @@ int ServiceController::WriteQueryResponse(OptCRef pData) return m_communicationSocket->WriteV(vec, vec_num); } +void ServiceController::SendOverallWhitelist(std::unordered_map& dlist) +{ + WhitelistRsp rsp; + rsp.domainNum = dlist.size(); + rsp.ddetail = nullptr; + m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(WhitelistRsp)); +} + +void ServiceController::SendDomainDetail(std::unordered_map& dlist) +{ + int domainNum = dlist.size(); + int msgSize = domainNum * sizeof(DomainDetail); + if (msgSize == 0) { + return; + } + char* tmp = new (std::nothrow) char[msgSize]; + if (tmp == nullptr) { + return; + } + if (memset_s(tmp, msgSize, 0, msgSize) != 0) { + delete []tmp; + tmp = nullptr; + return; + } + DomainDetail *ddetail = reinterpret_cast(tmp); + int i = 0; + for (auto it : dlist) { + ddetail[i].domain = it.first; + if (strncpy_s(ddetail[i].domainName, MAX_DOMAIN_NAME_LEN, it.second.c_str(), it.second.length()) != 0) { + return; + } + i++; + } + m_communicationSocket->Write(tmp, msgSize); + delete []tmp; + tmp = nullptr; +} + static void StatsEntry2StatsRsp(const StatsEntry &entry, StatsRsp &rsp) { // can't use std::copy, because StatsRsp is a packet struct @@ -773,6 +812,37 @@ void ServiceController::HandleLogKmsgEnableRqst(const KmsgEnableRqst& rqst) (void)m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(rsp)); } +void ServiceController::HandleWhitelistRqst(const WhitelistRqst& rqst) +{ + std::unordered_map dlist = GetDomainList(); + WhitelistRsp rsp = { 0 }; + WriteRspHeader(IoctlCmd::DOMAIN_WHITELIST_RSP, sizeof(rsp)); + SendOverallWhitelist(dlist); + SendDomainDetail(dlist); + + /* + int domainNum = dlist.size(); + int msgSize = domainNum * sizeof(DomainDetail); + char* tmp = nullptr; + tmp = new char[msgSize]; + WhitelistRsp rsp = { 0 }; + rsp.domainNum = domainNum; + rsp.ddetail = reinterpret_cast(tmp); + int i = 0; + for (auto it : dlist) { + rsp.ddetail[i].domain = it.first; + if (strncpy_s(rsp.ddetail[i].domainName, MAX_DOMAIN_NAME_LEN, it.second.c_str(), it.second.length()) != 0) { + return; + } + i++; + } + rsp.ddetail = reinterpret_cast(tmp); + + (void)m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(rsp)); + */ + +} + bool ServiceController::IsValidCmd(const CmdList& list, IoctlCmd cmd) { auto it = find(list.begin(), list.end(), cmd); @@ -861,6 +931,12 @@ void ServiceController::CommunicationLoop(std::atomic& stopLoop, const Cmd }); break; } + case IoctlCmd::DOMAIN_WHITELIST_RQST: { + RequestHandler(hdr, [this](const WhitelistRqst& rqst) { + HandleWhitelistRqst(rqst); + }); + break; + } default: { std::cerr << " Unknown message. Skipped!" << endl; break; diff --git a/services/hilogtool/include/log_display.h b/services/hilogtool/include/log_display.h index 08e8847..9805ba2 100644 --- a/services/hilogtool/include/log_display.h +++ b/services/hilogtool/include/log_display.h @@ -22,6 +22,7 @@ namespace OHOS { namespace HiviewDFX { using namespace std; void HilogShowLogStatsInfo(const StatsQueryRsp& rsp); +void HilogDomainWhitelist(const WhitelistRsp& rsp); } // namespace HiviewDFX } // namespace OHOS #endif diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 97a068a..da310a0 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -36,6 +36,7 @@ static constexpr int DOMAIN_TITLE_W = 10; static constexpr int DOMAIN_W = (DOMAIN_TITLE_W - 2); static constexpr int PID_W = 7; static constexpr int PNAME_W = 32; +static constexpr int DNAME_W = 32; static constexpr int TAG_W = 32; static constexpr int FREQ_W = 10; static constexpr int TIME_W = 20; @@ -73,6 +74,12 @@ static void PrintDomainTitle() cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; } +static void PrintWhitelistTitle() +{ + cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; + cout << setw(DNAME_W) << "DOMAIN_NAME" << colCmd; +} + static void PrintPidTitle() { cout << setw(LOGTYPE_W) << "LOGTYPE" << colCmd; @@ -302,5 +309,18 @@ void HilogShowLogStatsInfo(const StatsQueryRsp& rsp) cout << setw(STATS_W) << setfill('-') << "-" << endl; HilogShowProcStatsInfo(rsp); } + +void HilogDomainWhitelist(const WhitelistRsp& rsp) +{ + cout << "Domain Whitelist:" << endl; + PrintWhitelistTitle(); + cout << endl; + uint16_t i = 0; + for (i = 0; i < rsp.domainNum; i++) { + DomainDetail &dd = rsp.ddetail[i]; + cout << std::hex << "0x" << setw(DOMAIN_W) << dd.domain << colCmd; + cout << setw(DNAME_W) << dd.domainName << colCmd << std::endl; + } +} } // namespace HiviewDFX } // namespace OHOS \ No newline at end of file diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index bcbbb93..834f545 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -289,6 +289,7 @@ enum class ControlCmd { CMD_KMSG_FEATURE_SET, CMD_FLOWCONTROL_FEATURE_SET, CMD_LOGLEVEL_SET, + CMD_DOMAIN_WHITELIST }; struct HilogArgs { @@ -569,6 +570,20 @@ static int HelpHandler(HilogArgs& context, const char *arg) return RET_SUCCESS; } +static int DomainWhitelistHandler(HilogArgs& context, const char *arg) +{ + WhitelistRqst rqst; + LogIoctl ioctl(IoctlCmd::DOMAIN_WHITELIST_RQST, IoctlCmd::DOMAIN_WHITELIST_RSP); + int ret = ioctl.RequestWhitelist(rqst, [&rqst](const WhitelistRsp& rsp) { + HilogDomainWhitelist(rsp); + return RET_SUCCESS; + }); + if (ret != RET_SUCCESS) { + cout << "Get domain whitelist failed" << endl; + } + return ret; +} + static int JobIdHandler(HilogArgs& context, const char *arg) { if (IsNumericStr(arg) == false) { @@ -930,6 +945,7 @@ static OptEntry optEntries[] = { {'g', nullptr, ControlCmd::CMD_BUFFER_SIZE_QUERY, BufferSizeGetHandler, false, 1}, {'G', "buffer-size", ControlCmd::CMD_BUFFER_SIZE_SET, BufferSizeSetHandler, true, 1}, {'h', "help", ControlCmd::CMD_HELP, HelpHandler, false, 1}, + {'i', nullptr, ControlCmd::CMD_DOMAIN_WHITELIST, DomainWhitelistHandler, false, 1}, {'j', "jobid", ControlCmd::NOT_CMD, JobIdHandler, true, 1}, {'k', "kmsg", ControlCmd::CMD_KMSG_FEATURE_SET, KmsgFeatureSetHandler, true, 1}, {'l', "length", ControlCmd::NOT_CMD, FileLengthHandler, true, 1}, -- Gitee From ce3f9751c9b8c64cc0902c96311547eed1a13a3b Mon Sep 17 00:00:00 2001 From: Vincen Date: Thu, 29 Sep 2022 15:41:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?get=20domian=20whitelist=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vincen --- frameworks/libhilog/include/hilog_cmd.h | 7 +++- frameworks/libhilog/ioctl/include/log_ioctl.h | 9 ++--- frameworks/libhilog/ioctl/log_ioctl.cpp | 33 ++++++++++++--- frameworks/libhilog/utils/include/log_utils.h | 1 + services/hilogd/include/log_domains.h | 1 - services/hilogd/include/service_controller.h | 6 +-- services/hilogd/service_controller.cpp | 40 +++++-------------- services/hilogtool/include/log_display.h | 2 +- services/hilogtool/log_display.cpp | 10 ++++- services/hilogtool/main.cpp | 8 ++-- 10 files changed, 63 insertions(+), 54 deletions(-) diff --git a/frameworks/libhilog/include/hilog_cmd.h b/frameworks/libhilog/include/hilog_cmd.h index 03b61e7..e747fd3 100644 --- a/frameworks/libhilog/include/hilog_cmd.h +++ b/frameworks/libhilog/include/hilog_cmd.h @@ -267,11 +267,14 @@ struct DomainDetail { char domainName[MAX_DOMAIN_NAME_LEN]; } __attribute__((__packed__)); -struct WhitelistRqst { +struct DomainWhiteListRqst { + uint16_t domainNum; + DomainDetail* ddetail; } __attribute__((__packed__)); -struct WhitelistRsp { +struct DomainWhiteListRsp { uint16_t domainNum; DomainDetail* ddetail; } __attribute__((__packed__)); + #endif /* HILOG_CMD_H */ \ No newline at end of file diff --git a/frameworks/libhilog/ioctl/include/log_ioctl.h b/frameworks/libhilog/ioctl/include/log_ioctl.h index de9a79a..a4df0ab 100644 --- a/frameworks/libhilog/ioctl/include/log_ioctl.h +++ b/frameworks/libhilog/ioctl/include/log_ioctl.h @@ -38,8 +38,7 @@ public: int Request(const T1& rqst, std::function handle); int RequestOutput(const OutputRqst& rqst, std::function handle); int RequestStatsQuery(const StatsQueryRqst& rqst, std::function handle); - int RequestWhitelist(const WhitelistRqst& rqst, std::function handle); - + int RequestWhitelist(const DomainWhiteListRqst& rqst, std::function handle); private: SeqPacketSocketClient socket; int socketInit = -1; @@ -62,9 +61,9 @@ private: int ReceiveDomainStats(StatsQueryRsp &rsp); int ReceiveLogTypeDomainStats(StatsQueryRsp &rsp); void DeleteLogStatsInfo(StatsQueryRsp &rsp); - int ReceiveWhitelist(WhitelistRsp &rsp); - void DeleteWhitelistInfo(WhitelistRsp &rsp); - int ReceiveAndProcessWhitelistRsp(std::function handle); + int ReceiveWhitelist(DomainWhiteListRsp &rsp); + void DeleteWhitelistInfo(DomainWhiteListRsp &rsp); + int ReceiveAndProcessWhitelistRsp(std::function handle); }; template diff --git a/frameworks/libhilog/ioctl/log_ioctl.cpp b/frameworks/libhilog/ioctl/log_ioctl.cpp index 5e01a17..ce000d3 100644 --- a/frameworks/libhilog/ioctl/log_ioctl.cpp +++ b/frameworks/libhilog/ioctl/log_ioctl.cpp @@ -298,7 +298,7 @@ void LogIoctl::DeleteLogStatsInfo(StatsQueryRsp &rsp) } } -int LogIoctl::ReceiveWhitelist(WhitelistRsp &rsp) +int LogIoctl::ReceiveWhitelist(DomainWhiteListRsp &rsp) { if (rsp.domainNum == 0) { return RET_FAIL; @@ -327,7 +327,7 @@ int LogIoctl::ReceiveWhitelist(WhitelistRsp &rsp) return RET_SUCCESS; } -void LogIoctl::DeleteWhitelistInfo(WhitelistRsp &rsp) +void LogIoctl::DeleteWhitelistInfo(DomainWhiteListRsp &rsp) { if (rsp.ddetail == nullptr) { return; @@ -335,15 +335,38 @@ void LogIoctl::DeleteWhitelistInfo(WhitelistRsp &rsp) delete []rsp.ddetail; rsp.ddetail = nullptr; } -int LogIoctl::RequestOutput(const OutputRqst& rqst, std::function handle) + +int LogIoctl::RequestWhitelist(const DomainWhiteListRqst& rqst, std::function handle) { // 0. Send reqeust message and process the response header - int ret = RequestMsgHead(rqst); + int ret = RequestMsgHead(rqst); if (ret != RET_SUCCESS) { return ret; } // 1. process the response message - return ReceiveAndProcessOutputRsp(handle); + return ReceiveAndProcessWhitelistRsp(handle); +} + +int LogIoctl::ReceiveAndProcessWhitelistRsp(std::function handle) +{ + int ret; + DomainWhiteListRsp rsp = { 0 }; + do { + ret = GetRsp(reinterpret_cast(&rsp), sizeof(rsp)); + if (RET_SUCCESS != ret) { + break; + } + rsp.ddetail = nullptr; + ret = ReceiveWhitelist(rsp); + if (RET_SUCCESS != ret) { + break; + } + } while (0); + if (ret == RET_SUCCESS) { + ret = handle(rsp); + } + DeleteWhitelistInfo(rsp); + return ret; } int LogIoctl::ReceiveAndProcessOutputRsp(std::function handle) diff --git a/frameworks/libhilog/utils/include/log_utils.h b/frameworks/libhilog/utils/include/log_utils.h index f833f8d..fa2ff2b 100644 --- a/frameworks/libhilog/utils/include/log_utils.h +++ b/frameworks/libhilog/utils/include/log_utils.h @@ -65,6 +65,7 @@ public: { return str_map; } + private: const std::unordered_map str_map; diff --git a/services/hilogd/include/log_domains.h b/services/hilogd/include/log_domains.h index 5675948..e7721eb 100644 --- a/services/hilogd/include/log_domains.h +++ b/services/hilogd/include/log_domains.h @@ -17,7 +17,6 @@ #define LOG_DOMAINS_H #include -#include #include namespace OHOS { diff --git a/services/hilogd/include/service_controller.h b/services/hilogd/include/service_controller.h index 39f95c5..03f845a 100644 --- a/services/hilogd/include/service_controller.h +++ b/services/hilogd/include/service_controller.h @@ -82,11 +82,11 @@ private: void HandleDomainFlowCtrlRqst(const DomainFlowCtrlRqst& rqst); void HandleLogRemoveRqst(const LogRemoveRqst& rqst); void HandleLogKmsgEnableRqst(const KmsgEnableRqst& rqst); - void HandleWhitelistRqst(const WhitelistRqst& rqst); + void HandleWhitelistRqst(const DomainWhiteListRqst& rqst); void NotifyForNewData(); bool IsValidCmd(const CmdList& list, IoctlCmd cmd); - void SendOverallWhitelist(std::unordered_map& dlist); - void SendDomainDetail(std::unordered_map& dlist); + void SendOverallWhiteList(const std::unordered_map& dlist); + void SendDomainDetail(const std::unordered_map& dlist); std::unique_ptr m_communicationSocket; diff --git a/services/hilogd/service_controller.cpp b/services/hilogd/service_controller.cpp index ddd816d..6cf9b5c 100644 --- a/services/hilogd/service_controller.cpp +++ b/services/hilogd/service_controller.cpp @@ -148,15 +148,15 @@ int ServiceController::WriteQueryResponse(OptCRef pData) return m_communicationSocket->WriteV(vec, vec_num); } -void ServiceController::SendOverallWhitelist(std::unordered_map& dlist) +void ServiceController::SendOverallWhiteList(const std::unordered_map& dlist) { - WhitelistRsp rsp; + DomainWhiteListRsp rsp; rsp.domainNum = dlist.size(); rsp.ddetail = nullptr; - m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(WhitelistRsp)); + m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(DomainWhiteListRsp)); } -void ServiceController::SendDomainDetail(std::unordered_map& dlist) +void ServiceController::SendDomainDetail(const std::unordered_map& dlist) { int domainNum = dlist.size(); int msgSize = domainNum * sizeof(DomainDetail); @@ -812,35 +812,13 @@ void ServiceController::HandleLogKmsgEnableRqst(const KmsgEnableRqst& rqst) (void)m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(rsp)); } -void ServiceController::HandleWhitelistRqst(const WhitelistRqst& rqst) +void ServiceController::HandleWhitelistRqst(const DomainWhiteListRqst& rqst) { - std::unordered_map dlist = GetDomainList(); - WhitelistRsp rsp = { 0 }; + const std::unordered_map dlist = GetDomainList(); + DomainWhiteListRsp rsp = { 0 }; WriteRspHeader(IoctlCmd::DOMAIN_WHITELIST_RSP, sizeof(rsp)); - SendOverallWhitelist(dlist); + SendOverallWhiteList(dlist); SendDomainDetail(dlist); - - /* - int domainNum = dlist.size(); - int msgSize = domainNum * sizeof(DomainDetail); - char* tmp = nullptr; - tmp = new char[msgSize]; - WhitelistRsp rsp = { 0 }; - rsp.domainNum = domainNum; - rsp.ddetail = reinterpret_cast(tmp); - int i = 0; - for (auto it : dlist) { - rsp.ddetail[i].domain = it.first; - if (strncpy_s(rsp.ddetail[i].domainName, MAX_DOMAIN_NAME_LEN, it.second.c_str(), it.second.length()) != 0) { - return; - } - i++; - } - rsp.ddetail = reinterpret_cast(tmp); - - (void)m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(rsp)); - */ - } bool ServiceController::IsValidCmd(const CmdList& list, IoctlCmd cmd) @@ -932,7 +910,7 @@ void ServiceController::CommunicationLoop(std::atomic& stopLoop, const Cmd break; } case IoctlCmd::DOMAIN_WHITELIST_RQST: { - RequestHandler(hdr, [this](const WhitelistRqst& rqst) { + RequestHandler(hdr, [this](const DomainWhiteListRqst& rqst) { HandleWhitelistRqst(rqst); }); break; diff --git a/services/hilogtool/include/log_display.h b/services/hilogtool/include/log_display.h index 9805ba2..bb9f6ba 100644 --- a/services/hilogtool/include/log_display.h +++ b/services/hilogtool/include/log_display.h @@ -22,7 +22,7 @@ namespace OHOS { namespace HiviewDFX { using namespace std; void HilogShowLogStatsInfo(const StatsQueryRsp& rsp); -void HilogDomainWhitelist(const WhitelistRsp& rsp); +void HilogDomainWhiteList(const DomainWhiteListRsp& rsp); } // namespace HiviewDFX } // namespace OHOS #endif diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index da310a0..53d369d 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -310,10 +310,16 @@ void HilogShowLogStatsInfo(const StatsQueryRsp& rsp) HilogShowProcStatsInfo(rsp); } -void HilogDomainWhitelist(const WhitelistRsp& rsp) +static void PrintWhiteListTitle() +{ + cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; + cout << setw(DNAME_W) << "DOMAIN_NAME" << colCmd; +} + +void HilogDomainWhiteList(const DomainWhiteListRsp& rsp) { cout << "Domain Whitelist:" << endl; - PrintWhitelistTitle(); + PrintWhiteListTitle(); cout << endl; uint16_t i = 0; for (i = 0; i < rsp.domainNum; i++) { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index 834f545..e54a1ed 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -572,10 +572,10 @@ static int HelpHandler(HilogArgs& context, const char *arg) static int DomainWhitelistHandler(HilogArgs& context, const char *arg) { - WhitelistRqst rqst; + DomainWhiteListRqst rqst; LogIoctl ioctl(IoctlCmd::DOMAIN_WHITELIST_RQST, IoctlCmd::DOMAIN_WHITELIST_RSP); - int ret = ioctl.RequestWhitelist(rqst, [&rqst](const WhitelistRsp& rsp) { - HilogDomainWhitelist(rsp); + int ret = ioctl.RequestWhitelist(rqst, [&rqst](const DomainWhiteListRsp& rsp) { + HilogDomainWhiteList(rsp); return RET_SUCCESS; }); if (ret != RET_SUCCESS) { @@ -945,7 +945,7 @@ static OptEntry optEntries[] = { {'g', nullptr, ControlCmd::CMD_BUFFER_SIZE_QUERY, BufferSizeGetHandler, false, 1}, {'G', "buffer-size", ControlCmd::CMD_BUFFER_SIZE_SET, BufferSizeSetHandler, true, 1}, {'h', "help", ControlCmd::CMD_HELP, HelpHandler, false, 1}, - {'i', nullptr, ControlCmd::CMD_DOMAIN_WHITELIST, DomainWhitelistHandler, false, 1}, + {'d', nullptr, ControlCmd::CMD_DOMAIN_WHITELIST, DomainWhitelistHandler, false, 1}, {'j', "jobid", ControlCmd::NOT_CMD, JobIdHandler, true, 1}, {'k', "kmsg", ControlCmd::CMD_KMSG_FEATURE_SET, KmsgFeatureSetHandler, true, 1}, {'l', "length", ControlCmd::NOT_CMD, FileLengthHandler, true, 1}, -- Gitee From 8fee9c345c93dd8b3d4b56392cf701b1272004b8 Mon Sep 17 00:00:00 2001 From: Vincen Date: Thu, 29 Sep 2022 15:55:02 +0800 Subject: [PATCH 3/5] fix log_ioctl.cpp requestoutput Signed-off-by: Vincen --- frameworks/libhilog/ioctl/log_ioctl.cpp | 36 +++++-------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/frameworks/libhilog/ioctl/log_ioctl.cpp b/frameworks/libhilog/ioctl/log_ioctl.cpp index ce000d3..3fe6037 100644 --- a/frameworks/libhilog/ioctl/log_ioctl.cpp +++ b/frameworks/libhilog/ioctl/log_ioctl.cpp @@ -336,37 +336,15 @@ void LogIoctl::DeleteWhitelistInfo(DomainWhiteListRsp &rsp) rsp.ddetail = nullptr; } -int LogIoctl::RequestWhitelist(const DomainWhiteListRqst& rqst, std::function handle) +int LogIoctl::RequestOutput(const OutputRqst& rqst, std::function handle) { // 0. Send reqeust message and process the response header - int ret = RequestMsgHead(rqst); + int ret = RequestMsgHead(rqst); if (ret != RET_SUCCESS) { return ret; } // 1. process the response message - return ReceiveAndProcessWhitelistRsp(handle); -} - -int LogIoctl::ReceiveAndProcessWhitelistRsp(std::function handle) -{ - int ret; - DomainWhiteListRsp rsp = { 0 }; - do { - ret = GetRsp(reinterpret_cast(&rsp), sizeof(rsp)); - if (RET_SUCCESS != ret) { - break; - } - rsp.ddetail = nullptr; - ret = ReceiveWhitelist(rsp); - if (RET_SUCCESS != ret) { - break; - } - } while (0); - if (ret == RET_SUCCESS) { - ret = handle(rsp); - } - DeleteWhitelistInfo(rsp); - return ret; + return ReceiveAndProcessOutputRsp(handle); } int LogIoctl::ReceiveAndProcessOutputRsp(std::function handle) @@ -440,10 +418,10 @@ int LogIoctl::ReceiveAndProcessStatsQueryRsp(std::function handle) +int LogIoctl::RequestWhitelist(const DomainWhiteListRqst& rqst, std::function handle) { // 0. Send reqeust message and process the response header - int ret = RequestMsgHead(rqst); + int ret = RequestMsgHead(rqst); if (ret != RET_SUCCESS) { return ret; } @@ -451,10 +429,10 @@ int LogIoctl::RequestWhitelist(const WhitelistRqst& rqst, std::function handle) +int LogIoctl::ReceiveAndProcessWhitelistRsp(std::function handle) { int ret; - WhitelistRsp rsp = { 0 }; + DomainWhiteListRsp rsp = { 0 }; do { ret = GetRsp(reinterpret_cast(&rsp), sizeof(rsp)); if (RET_SUCCESS != ret) { -- Gitee From e734e970488b1b191667c60e6391c20d74a3c458 Mon Sep 17 00:00:00 2001 From: Vincen Date: Fri, 30 Sep 2022 11:10:55 +0800 Subject: [PATCH 4/5] fix printwhitelisttitle repeat in log_display Signed-off-by: Vincen --- services/hilogtool/log_display.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 53d369d..efbc929 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -74,7 +74,7 @@ static void PrintDomainTitle() cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; } -static void PrintWhitelistTitle() +static void PrintWhiteListTitle() { cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; cout << setw(DNAME_W) << "DOMAIN_NAME" << colCmd; @@ -310,12 +310,6 @@ void HilogShowLogStatsInfo(const StatsQueryRsp& rsp) HilogShowProcStatsInfo(rsp); } -static void PrintWhiteListTitle() -{ - cout << setw(DOMAIN_TITLE_W) << "DOMAIN" << colCmd; - cout << setw(DNAME_W) << "DOMAIN_NAME" << colCmd; -} - void HilogDomainWhiteList(const DomainWhiteListRsp& rsp) { cout << "Domain Whitelist:" << endl; -- Gitee From 27e0b217f6b5df705895756828afa864ca0a6c0c Mon Sep 17 00:00:00 2001 From: Vincen Date: Tue, 11 Oct 2022 14:30:47 +0800 Subject: [PATCH 5/5] fix log_damains include Signed-off-by: Vincen --- services/hilogd/include/log_domains.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/hilogd/include/log_domains.h b/services/hilogd/include/log_domains.h index e7721eb..5675948 100644 --- a/services/hilogd/include/log_domains.h +++ b/services/hilogd/include/log_domains.h @@ -17,6 +17,7 @@ #define LOG_DOMAINS_H #include +#include #include namespace OHOS { -- Gitee