使用宏判断处理异常分支

Signed-off-by:wenlong12 <wenlong12@huawei.com>

Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
wenlong12 2023-07-20 17:31:19 +08:00
parent 6a30683e4a
commit cf2886772f
42 changed files with 203 additions and 203 deletions

View File

@ -409,7 +409,7 @@ bool CheckApplicationPermission(int pid, const std::string& processName)
} else {
bundleName = processName;
}
CHECK_TRUE(bundleName.empty(), false, "Pid or process name is illegal!");
CHECK_TRUE(!bundleName.empty(), false, "Pid or process name is illegal!");
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
CHECK_NOTNULL(sam, false, "GetSystemAbilityManager failed!");
@ -417,7 +417,7 @@ bool CheckApplicationPermission(int pid, const std::string& processName)
CHECK_NOTNULL(remoteObject, false, "Get BundleMgr SA failed!");
sptr<BundleMgrProxy> proxy = iface_cast<BundleMgrProxy>(remoteObject);
int uid = proxy->GetUidByDebugBundleName(bundleName, Constants::ANY_USERID);
CHECK_TRUE(uid < 0, false, "Get %s uid = %d", bundleName.c_str(), uid);
CHECK_TRUE(uid >= 0, false, "Get %s uid = %d", bundleName.c_str(), uid);
return true;
}
@ -442,10 +442,10 @@ bool ReadFile(const std::string &filePath, const std::vector<std::string>& valid
std::string realFilePathStr(realFilePath);
free(realFilePath);
CHECK_TRUE(!VerifyPath(realFilePathStr, validPaths), false, "Fail to VerifyPath: %s", realFilePathStr.c_str());
CHECK_TRUE(VerifyPath(realFilePathStr, validPaths), false, "Fail to VerifyPath: %s", realFilePathStr.c_str());
std::ifstream fileStream(realFilePathStr, std::ios::in);
CHECK_TRUE(!fileStream.is_open(), false, "Fail to open file %s", realFilePathStr.c_str());
CHECK_TRUE(fileStream.is_open(), false, "Fail to open file %s", realFilePathStr.c_str());
std::istreambuf_iterator<char> firstIt = { fileStream };
std::string content(firstIt, {});

View File

@ -93,7 +93,7 @@ bool ScheduleTaskManager::ScheduleTask(const std::string& name,
task->nextRunTime = currentTime + initialDelay;
std::lock_guard<std::mutex> guard(taskMutex_);
CHECK_TRUE(taskMap_.count(name) > 0, false, "task name %s already exists!", name.c_str());
CHECK_TRUE(!(taskMap_.count(name) > 0), false, "task name %s already exists!", name.c_str());
taskMap_[name] = task;
timeMap_.insert(std::make_pair(task->nextRunTime, task));

View File

@ -41,7 +41,7 @@ bool CommandPoller::OnConnect()
bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContext& context) const
{
HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
CHECK_TRUE(cmd.buffer_sizes().size() == 0 || cmd.plugin_configs().size() == 0, false, "%s:cmd invalid!", __func__);
CHECK_TRUE(cmd.buffer_sizes().size() != 0 && cmd.plugin_configs().size() != 0, false, "%s:cmd invalid!", __func__);
uint32_t bufferSize = cmd.buffer_sizes(0);
ProfilerPluginConfig config = cmd.plugin_configs(0);
@ -51,7 +51,7 @@ bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContex
auto pluginManager = pluginManager_.lock(); // promote to shared_ptr
CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
CHECK_TRUE(!pluginManager->LoadPlugin(config.name()), false, "%s:fail 1", __func__);
CHECK_TRUE(pluginManager->LoadPlugin(config.name()), false, "%s:fail 1", __func__);
int smbFd = -1;
int eventFd = -1;
@ -63,9 +63,9 @@ bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContex
HILOG_DEBUG(LOG_CORE, "%s:smbFd = %d, eventFd = %d", __func__, smbFd, eventFd);
HILOG_DEBUG(LOG_CORE, "%s:eventFd flags = %X", __func__, flags);
}
CHECK_TRUE(!pluginManager->CreateWriter(config.name(), bufferSize, smbFd, eventFd), false,
CHECK_TRUE(pluginManager->CreateWriter(config.name(), bufferSize, smbFd, eventFd), false,
"%s:createWriter failed!", __func__);
CHECK_TRUE(!pluginManager->CreatePluginSession(configVec), false,
CHECK_TRUE(pluginManager->CreatePluginSession(configVec), false,
"%s:createPluginSession failed!", __func__);
HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true;
@ -74,17 +74,17 @@ bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContex
bool CommandPoller::OnDestroySessionCmd(const DestroySessionCmd& cmd) const
{
HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
CHECK_TRUE(cmd.plugin_ids().size() == 0, false, "%s:cmd invalid!", __func__);
CHECK_TRUE(cmd.plugin_ids().size() > 0, false, "%s:cmd invalid!", __func__);
uint32_t pluginId = cmd.plugin_ids(0);
std::vector<uint32_t> pluginIdVec;
pluginIdVec.push_back(pluginId);
auto pluginManager = pluginManager_.lock(); // promote to shared_ptr
CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
CHECK_TRUE(!pluginManager->DestroyPluginSession(pluginIdVec), false,
CHECK_TRUE(pluginManager->DestroyPluginSession(pluginIdVec), false,
"%s:destroyPluginSession failed!", __func__);
CHECK_TRUE(!pluginManager->ResetWriter(pluginId), false, "%s:resetWriter failed!", __func__);
CHECK_TRUE(!pluginManager->UnloadPlugin(pluginId), false, "%s:unloadPlugin failed!", __func__);
CHECK_TRUE(pluginManager->ResetWriter(pluginId), false, "%s:resetWriter failed!", __func__);
CHECK_TRUE(pluginManager->UnloadPlugin(pluginId), false, "%s:unloadPlugin failed!", __func__);
HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true;
}
@ -92,7 +92,7 @@ bool CommandPoller::OnDestroySessionCmd(const DestroySessionCmd& cmd) const
bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd, PluginResult& result) const
{
HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
CHECK_TRUE(cmd.plugin_ids().size() == 0 || cmd.plugin_configs().size() == 0, false,
CHECK_TRUE(cmd.plugin_ids().size() > 0 && cmd.plugin_configs().size() > 0, false,
"%s:cmd invalid!", __func__);
std::vector<uint32_t> pluginIds;
pluginIds.push_back(cmd.plugin_ids(0));
@ -101,7 +101,7 @@ bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd, PluginResult&
auto pluginManager = pluginManager_.lock(); // promote to shared_ptr
CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
CHECK_TRUE(!pluginManager->StartPluginSession(pluginIds, configVec, result), false,
CHECK_TRUE(pluginManager->StartPluginSession(pluginIds, configVec, result), false,
"%s:start Session failed!", __func__);
HILOG_DEBUG(LOG_CORE, "%s:OK", __func__);
return true;
@ -110,13 +110,13 @@ bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd, PluginResult&
bool CommandPoller::OnStopSessionCmd(const StopSessionCmd& cmd) const
{
HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
CHECK_TRUE(cmd.plugin_ids().size() == 0, false, "%s:cmd invalid!", __func__);
CHECK_TRUE(cmd.plugin_ids().size() > 0, false, "%s:cmd invalid!", __func__);
std::vector<uint32_t> pluginIds;
pluginIds.push_back(cmd.plugin_ids(0));
auto pluginManager = pluginManager_.lock(); // promote to shared_ptr
CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
CHECK_TRUE(!pluginManager->StopPluginSession(pluginIds), false, "%s:stop Session failed!", __func__);
CHECK_TRUE(pluginManager->StopPluginSession(pluginIds), false, "%s:stop Session failed!", __func__);
HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true;
}
@ -124,13 +124,13 @@ bool CommandPoller::OnStopSessionCmd(const StopSessionCmd& cmd) const
bool CommandPoller::OnReportBasicDataCmd(const RefreshSessionCmd& cmd) const
{
HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
CHECK_TRUE(cmd.plugin_ids().size() == 0, false, "%s:cmd invalid!", __func__);
CHECK_TRUE(cmd.plugin_ids().size() > 0, false, "%s:cmd invalid!", __func__);
std::vector<uint32_t> pluginIds;
pluginIds.push_back(cmd.plugin_ids(0));
auto pluginManager = pluginManager_.lock(); // promote to shared_ptr
CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
CHECK_TRUE(!pluginManager->ReportPluginBasicData(pluginIds), false, "%s:report basic data failed!", __func__);
CHECK_TRUE(pluginManager->ReportPluginBasicData(pluginIds), false, "%s:report basic data failed!", __func__);
HILOG_INFO(LOG_CORE, "%s:ok", __func__);
return true;
}

View File

@ -141,7 +141,7 @@ bool PluginManager::RegisterPlugin(const PluginModulePtr& plugin, const std::str
bool PluginManager::RemovePlugin(const std::string& pluginPath)
{
CHECK_TRUE(pluginPathAndNameMap_.count(pluginPath) == 0, false,
CHECK_TRUE(pluginPathAndNameMap_.count(pluginPath) > 0, false,
"%s:not find plugin: %s", __func__, pluginPath.c_str());
std::string pluginName = pluginPathAndNameMap_[pluginPath];
@ -205,7 +205,7 @@ bool PluginManager::LoadPlugin(const std::string& pluginName)
{
HILOG_DEBUG(LOG_CORE, "%s:size = %zu", __func__, pluginIds_.size());
auto it = pluginIds_.find(pluginName);
CHECK_TRUE(it == pluginIds_.end(), false, "%s:plugin not exist", __func__);
CHECK_TRUE(it != pluginIds_.end(), false, "%s:plugin not exist", __func__);
uint32_t index = it->second;
if (!pluginModules_[index]->Load()) {
@ -353,9 +353,9 @@ bool PluginManager::ReportPluginBasicData(const std::vector<uint32_t>& pluginIds
{
HILOG_INFO(LOG_CORE, "%s:ready!", __func__);
for (uint32_t id : pluginIds) {
CHECK_TRUE(pluginModules_.find(id) == pluginModules_.end(), false, "%s:plugin not find", __func__);
CHECK_TRUE(pluginModules_.find(id) != pluginModules_.end(), false, "%s:plugin not find", __func__);
// notify plugin to report basic data
CHECK_TRUE(!pluginModules_[id]->ReportBasicData(), false, "%s:report basic data failed", __func__);
CHECK_TRUE(pluginModules_[id]->ReportBasicData(), false, "%s:report basic data failed", __func__);
}
return true;
}

View File

@ -38,7 +38,7 @@ bool PluginModule::Load()
HILOG_DEBUG(LOG_CORE, "%s:already open", __func__);
return false;
}
CHECK_TRUE((path_.length() >= PATH_MAX) || (realpath(path_.c_str(), realPath) == nullptr), false,
CHECK_TRUE((path_.length() < PATH_MAX) && (realpath(path_.c_str(), realPath) != nullptr), false,
"%s:so filename invalid, errno=%d", __func__, errno);
std::string rpath = realPath; // for SC warning

View File

@ -422,12 +422,12 @@ bool ArkTSPlugin::DecodeMessage(WebSocketFrame& wsFrame)
}
wsFrame.payload = std::make_unique<char[]>(wsFrame.payloadLen + 1);
if (wsFrame.mask == 1) {
CHECK_TRUE(!Recv(client_, wsFrame.maskingKey, SOCKET_MASK_LEN, 0), false,
CHECK_TRUE(Recv(client_, wsFrame.maskingKey, SOCKET_MASK_LEN, 0), false,
"DecodeMessage: Recv maskingKey failed");
wsFrame.maskingKey[SOCKET_MASK_LEN] = '\0';
char buf[wsFrame.payloadLen + 1];
CHECK_TRUE(!Recv(client_, buf, wsFrame.payloadLen, 0), false, "DecodeMessage: Recv message with mask failed");
CHECK_TRUE(Recv(client_, buf, wsFrame.payloadLen, 0), false, "DecodeMessage: Recv message with mask failed");
buf[wsFrame.payloadLen] = '\0';
for (uint64_t i = 0; i < wsFrame.payloadLen; i++) {
@ -448,7 +448,7 @@ bool ArkTSPlugin::Recv(int32_t client, char* buf, size_t totalLen, int32_t flags
size_t recvLen = 0;
while (recvLen < totalLen) {
ssize_t len = recv(client, buf + recvLen, totalLen - recvLen, flags);
CHECK_TRUE(len <= 0, false, "Recv payload in while failed, websocket disconnect");
CHECK_TRUE(len > 0, false, "Recv payload in while failed, websocket disconnect");
recvLen += static_cast<size_t>(len);
}
buf[totalLen] = '\0';

View File

@ -71,7 +71,7 @@ int CpuDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
buffer_ = malloc(READ_BUFFER_SIZE);
CHECK_NOTNULL(buffer_, RET_FAIL, "%s:malloc buffer_ failed!", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, RET_FAIL,
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL,
"%s:parseFromArray failed!", __func__);
if (protoConfig_.pid() > 0) {
@ -348,7 +348,7 @@ void CpuDataPlugin::SetCpuFrequency(CpuCoreUsageInfo& cpuCore, int32_t coreNum)
bool CpuDataPlugin::GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, CpuTimeData& cpuTimeData)
{
// 获取到的数据不包含user, nice, system, idle, iowait, irq, softirq, steal八个数值时返回
CHECK_TRUE(cpuUsageVec.size() != SYSTEM_UNSPECIFIED, false,
CHECK_TRUE(cpuUsageVec.size() == SYSTEM_UNSPECIFIED, false,
"%s:failed to get system cpu usage, size=%zu", __func__, cpuUsageVec.size());
int64_t user = 0;
@ -493,7 +493,7 @@ bool CpuDataPlugin::addTidBySort(int32_t tid)
{
auto tidsEnd = tidVec_.end();
auto it = std::lower_bound(tidVec_.begin(), tidsEnd, tid);
CHECK_TRUE(it != tidsEnd && *it == tid, false, "addTidBySort failed");
CHECK_TRUE(!(it != tidsEnd && *it == tid), false, "addTidBySort failed");
it = tidVec_.insert(it, std::move(tid));
return true;
}
@ -510,7 +510,7 @@ DIR* CpuDataPlugin::OpenDestDir(std::string& dirPath)
int32_t CpuDataPlugin::GetValidTid(DIR* dirp)
{
CHECK_TRUE(!dirp, 0, "dirp is nullptr");
CHECK_TRUE(dirp, 0, "dirp is nullptr");
while (struct dirent* dirEnt = readdir(dirp)) {
if (dirEnt->d_type != DT_DIR) {
continue;

View File

@ -49,7 +49,7 @@ int DiskioDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
buffer_ = malloc(READ_BUFFER_SIZE);
CHECK_NOTNULL(buffer_, RET_FAIL, "%s:malloc buffer_ failed!", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, RET_FAIL,
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL,
"%s:parseFromArray failed!", __func__);
if (protoConfig_.report_io_stats()) {
@ -100,7 +100,7 @@ int32_t DiskioDataPlugin::ReadFile(std::string& fileName)
int fd = -1;
ssize_t bytesRead = 0;
char realPath[PATH_MAX + 1] = {0};
CHECK_TRUE((fileName.length() >= PATH_MAX) || (realpath(fileName.c_str(), realPath) == nullptr), RET_FAIL,
CHECK_TRUE((fileName.length() < PATH_MAX) && (realpath(fileName.c_str(), realPath) != nullptr), RET_FAIL,
"%s:path is invalid: %s, errno=%d", __func__, fileName.c_str(), errno);
fd = open(realPath, O_RDONLY | O_CLOEXEC);
if (fd == -1) {

View File

@ -46,7 +46,7 @@ uint64_t IoStats::GetSystime()
{
uint64_t systime = 1;
std::ifstream input(SYSTIME_PATH, std::ios::in);
CHECK_TRUE(input.fail(), systime, "%s:open %s failed, errno = %d", __func__, SYSTIME_PATH, errno);
CHECK_TRUE(!input.fail(), systime, "%s:open %s failed, errno = %d", __func__, SYSTIME_PATH, errno);
do {
if (!input.good()) {
return systime;
@ -82,7 +82,7 @@ bool IoStats::GetIoData()
bool IoStats::ParseCpuStats()
{
std::ifstream input(CPU_PATH, std::ios::in);
CHECK_TRUE(input.fail(), false, "%s: open %s failed, errno = %d", __func__, CPU_PATH, errno);
CHECK_TRUE(!input.fail(), false, "%s: open %s failed, errno = %d", __func__, CPU_PATH, errno);
do {
if (!input.good()) {
return false;
@ -140,7 +140,7 @@ bool IoStats::GetCpuStats(std::string& line)
bool IoStats::ParseIoStats()
{
std::ifstream input(DISKSTATS_PATH, std::ios::in);
CHECK_TRUE(input.fail(), false, "%s:%d open failed, errno = %d", __func__, __LINE__, errno);
CHECK_TRUE(!input.fail(), false, "%s:%d open failed, errno = %d", __func__, __LINE__, errno);
do {
if (!input.good()) {
return false;
@ -261,7 +261,7 @@ bool IoStats::PutPluginStatsData(StatsData* pluginStats)
uint32_t IoStats::PutCpuStatsData(StatsData* pluginStats)
{
std::unique_lock<std::mutex> lock(mutex_);
CHECK_TRUE(cpuDatas_.empty(), 0, "cpuDatas_ is empty");
CHECK_TRUE(!cpuDatas_.empty(), 0, "cpuDatas_ is empty");
uint32_t count = 0;
while (cpuDatas_.size() > 0) {
@ -305,7 +305,7 @@ double IoStats::KeepTowDigits(const uint64_t& data, uint64_t div)
uint32_t IoStats::PutIoStatsData(StatsData* pluginStats)
{
std::unique_lock<std::mutex> lock(mutex_);
CHECK_TRUE(ioDatas_.empty(), 0, "ioDatas_ is empty");
CHECK_TRUE(!ioDatas_.empty(), 0, "ioDatas_ is empty");
uint32_t count = 0;
while (ioDatas_.size() > 0) {

View File

@ -49,7 +49,7 @@ std::string FileUtils::ReadFile(int fd)
std::string FileUtils::ReadFile(const std::string& path)
{
char realPath[PATH_MAX + 1] = {0};
CHECK_TRUE((path.length() >= PATH_MAX) || (realpath(path.c_str(), realPath) == nullptr), "",
CHECK_TRUE((path.length() < PATH_MAX) && (realpath(path.c_str(), realPath) != nullptr), "",
"%s:path is invalid: %s, errno=%d", __func__, path.c_str(), errno);
int fd = open(realPath, O_RDONLY);
if (fd == -1) {
@ -85,10 +85,10 @@ int FileUtils::WriteFile(const std::string& path, const std::string& content, in
if (pos != std::string::npos) {
std::string dirName = path.substr(0, pos+1);
std::string fileName = path.substr(pos+1, path.length()-pos-1);
CHECK_TRUE(std::regex_search(dirName, dirNameRegex) || std::regex_search(fileName, fileNameRegex), -1,
CHECK_TRUE(!(std::regex_search(dirName, dirNameRegex) || std::regex_search(fileName, fileNameRegex)), -1,
"%s:path is invalid: %s, errno=%d", __func__, path.c_str(), errno);
} else {
CHECK_TRUE(std::regex_search(path, fileNameRegex), -1,
CHECK_TRUE(!std::regex_search(path, fileNameRegex), -1,
"%s:path is invalid: %s, errno=%d", __func__, path.c_str(), errno);
}

View File

@ -342,7 +342,7 @@ bool FlowController::ParseEventDataOnNomalMode(int cpuid, long dataSize)
bool FlowController::ParseEventDataOnDelayMode()
{
CHECK_TRUE(fseek(rawDataFile_.get(), 0, SEEK_SET) != 0, false, "fseek failed!");
CHECK_TRUE(fseek(rawDataFile_.get(), 0, SEEK_SET) == 0, false, "fseek failed!");
while (!feof(rawDataFile_.get())) {
uint8_t cpuId = 0;
long dataBytes = 0;

View File

@ -55,7 +55,7 @@ bool FtraceFieldParser::ReadData(const uint8_t start[], const uint8_t end[], voi
return false;
}
CHECK_TRUE(memcpy_s(out, size, start, size) != EOK, false, "copy %zu byte to memory FAILED!", size);
CHECK_TRUE(memcpy_s(out, size, start, size) == EOK, false, "copy %zu byte to memory FAILED!", size);
return true;
}
@ -89,7 +89,7 @@ std::string FtraceFieldParser::ParseStrField(const FieldFormat& format, uint8_t
break;
case FIELD_TYPE_STRINGPTR:
strSize = std::min(static_cast<size_t>(format.size), sizeof(strPtr));
CHECK_TRUE(memcpy_s(&strPtr, sizeof(strPtr), start, strSize) != EOK, "",
CHECK_TRUE(memcpy_s(&strPtr, sizeof(strPtr), start, strSize) == EOK, "",
"parse STRINGPTR at %" PRIx64 " with %zu size FAILED!", strPtr, strSize);
retval = PrintkFormatsParser::GetInstance().GetSymbol(strPtr);
break;

View File

@ -146,7 +146,7 @@ bool FtraceFsOps::ClearTraceBuffer()
char realPath[PATH_MAX + 1] = {0};
std::string path = ftraceRoot_ + "/trace";
CHECK_TRUE((path.length() >= PATH_MAX) || (realpath(path.c_str(), realPath) == nullptr), false,
CHECK_TRUE((path.length() < PATH_MAX) && (realpath(path.c_str(), realPath) != nullptr), false,
"%s:path is invalid: %s, errno=%d", __func__, path.c_str(), errno);
int fd = open(realPath, O_TRUNC);
CHECK_TRUE(fd >= 0, false, "open %s failed!", realPath);

View File

@ -399,7 +399,7 @@ bool FtraceParser::ParseFieldType(const std::string& type, FieldFormat& field)
// for flex array with __data_loc mark, likes: __data_loc char[] name; __data_loc __u8[] buf;
if (std::regex_match(typeName, flexDataLocArrayRegex_)) {
CHECK_TRUE(field.size != sizeof(uint32_t), false, "__data_loc %s, size: %hu", typeName.c_str(), field.size);
CHECK_TRUE(field.size == sizeof(uint32_t), false, "__data_loc %s, size: %hu", typeName.c_str(), field.size);
field.filedType = FIELD_TYPE_DATALOC;
return true;
}

View File

@ -70,12 +70,12 @@ long ResultTransporter::Write(ResultPtr&& packet)
size_t size = packet->ByteSizeLong();
buffer_.resize(size);
CHECK_TRUE(buffer_.size() != size, -1,
CHECK_TRUE(buffer_.size() == size, -1,
"%s: buffer resize failed, size: %zu, buffer size: %zu, errno: %d(%s)",
__func__, size, buffer_.size(), errno, strerror(errno));
int ret = packet->SerializeToArray(buffer_.data(), buffer_.size());
CHECK_TRUE(ret <= 0, ret, "%s: SerializeToArray failed with %d, size: %zu", __func__, ret, size);
CHECK_TRUE(ret > 0, ret, "%s: SerializeToArray failed with %d, size: %zu", __func__, ret, size);
writer_->write(writer_, buffer_.data(), buffer_.size());
return buffer_.size();

View File

@ -64,7 +64,7 @@ HidumpPlugin::~HidumpPlugin()
int HidumpPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
HILOG_INFO(LOG_CORE, "HidumpPlugin:Start ----> !");
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, -1, "HidumpPlugin: ParseFromArray failed");
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, -1, "HidumpPlugin: ParseFromArray failed");
fp_ = std::unique_ptr<FILE, int (*)(FILE*)>(CustomPopen(g_fpsFormat, "r"), CustomPclose);
if (fp_.get() == nullptr) {
@ -173,7 +173,7 @@ bool HidumpPlugin::ParseHidumpInfo(HidumpInfo& dataProto, char *buf)
FILE* HidumpPlugin::CustomPopen(const char* command, const char* type)
{
CHECK_TRUE(command == nullptr || type == nullptr, nullptr, "HidumpPlugin:%s param invalid", __func__);
CHECK_TRUE(command != nullptr && type != nullptr, nullptr, "HidumpPlugin:%s param invalid", __func__);
int fd[PIPE_LEN];
pipe(fd);

View File

@ -58,13 +58,13 @@ static int32_t HiebpfSessionStart(const uint8_t* configData, uint32_t configSize
return RET_ERR;
}
HiebpfConfig config;
CHECK_TRUE(config.ParseFromArray(configData, configSize) <= 0, RET_ERR, "Parameter parsing failed");
CHECK_TRUE(config.ParseFromArray(configData, configSize) > 0, RET_ERR, "Parameter parsing failed");
size_t defaultSize = sizeof(g_pluginModule.outFileName);
CHECK_TRUE(sizeof(config.outfile_name().c_str()) > defaultSize - 1, RET_ERR,
CHECK_TRUE(sizeof(config.outfile_name().c_str()) <= defaultSize - 1, RET_ERR,
"The out file path more than %zu bytes", defaultSize);
int32_t ret = strncpy_s(g_pluginModule.outFileName, defaultSize, config.outfile_name().c_str(), defaultSize - 1);
CHECK_TRUE(ret != EOK, RET_ERR, "strncpy_s error! outfile is %s", config.outfile_name().c_str());
CHECK_TRUE(ret == EOK, RET_ERR, "strncpy_s error! outfile is %s", config.outfile_name().c_str());
std::string cmd = config.cmd_line();
cmd += " --start true --output_file " + config.outfile_name();
RunCmd(cmd);

View File

@ -29,7 +29,7 @@ FileCache::~FileCache()
bool FileCache::Open(const std::string& file)
{
char realPath[PATH_MAX] = {0};
CHECK_TRUE(path_.empty() || (path_.length() >= PATH_MAX) || (realpath(path_.c_str(), realPath) == nullptr), false,
CHECK_TRUE(!(path_.empty() || (path_.length() >= PATH_MAX) || (realpath(path_.c_str(), realPath) == nullptr)), false,
"%s:path is invalid: %s, errno=%d", __func__, path_.c_str(), errno);
std::string targetFile = std::string(realPath) + std::string("/") + file;
fp_ = fopen(targetFile.c_str(), "wb+");

View File

@ -71,10 +71,10 @@ HilogPlugin::~HilogPlugin()
int HilogPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, -1, "HilogPlugin: ParseFromArray failed");
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, -1, "HilogPlugin: ParseFromArray failed");
if (protoConfig_.need_clear()) {
fullCmd_ = ClearHilog();
CHECK_TRUE(fullCmd_.empty(), -1, "HilogPlugin: fullCmd_ is empty");
CHECK_TRUE(!fullCmd_.empty(), -1, "HilogPlugin: fullCmd_ is empty");
std::vector<std::string> cmdArg;
COMMON::SplitString(fullCmd_, " ", cmdArg);
cmdArg.emplace(cmdArg.begin(), BIN_COMMAND);
@ -85,7 +85,7 @@ int HilogPlugin::Start(const uint8_t* configData, uint32_t configSize)
CHECK_NOTNULL(fp, -1, "%s:clear hilog error", __func__);
COMMON::CustomPclose(fp, pipeFds, childPid);
}
CHECK_TRUE(!InitHilogCmd(), -1, "HilogPlugin: Init HilogCmd failed");
CHECK_TRUE(InitHilogCmd(), -1, "HilogPlugin: Init HilogCmd failed");
fp_ = std::unique_ptr<FILE, int (*)(FILE*)>(CustomPopen(fullCmd_.c_str(), "r"), CustomPclose);
CHECK_NOTNULL(fp_.get(), -1, "HilogPlugin: open(%s) Failed, errno(%d)", fullCmd_.c_str(), errno);
@ -471,7 +471,7 @@ int HilogPlugin::GetDateTime(char* psDateTime, uint32_t size)
FILE* HilogPlugin::CustomPopen(const char* command, const char* type)
{
CHECK_TRUE(command == nullptr || type == nullptr, nullptr, "HilogPlugin:%s param invalid", __func__);
CHECK_TRUE(command != nullptr && type != nullptr, nullptr, "HilogPlugin:%s param invalid", __func__);
int fd[PIPE_LEN];
pipe(fd);

View File

@ -66,7 +66,7 @@ bool ParseConfigToCmd(const HiperfPluginConfig& config, std::vector<std::string>
prepareCmd += " -o " + config.outfile_name();
size_t fileSize = sizeof(g_pluginModule.outFileName);
int ret = strncpy_s(g_pluginModule.outFileName, fileSize, config.outfile_name().c_str(), fileSize - 1);
CHECK_TRUE(ret != EOK, false, "strncpy_s error! outfile is %s", config.outfile_name().c_str());
CHECK_TRUE(ret == EOK, false, "strncpy_s error! outfile is %s", config.outfile_name().c_str());
}
if (!config.record_args().empty()) {
prepareCmd += " " + config.record_args();

View File

@ -53,12 +53,12 @@ int HisyseventPlugin::Start(const uint8_t* configData, uint32_t configSize)
HILOG_INFO(LOG_CORE, "BEGN %s: ready!", __func__);
CHECK_NOTNULL(configData, -1, "NOTE %s: param invalid", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, -1,
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, -1,
"NOTE HisyseventPlugin: ParseFromArray failed");
HILOG_DEBUG(LOG_CORE, "NOTE configData ParseFromArray sucessed,sourse data:%s", protoConfig_.msg().c_str());
CHECK_TRUE(!InitHisyseventCmd(), -1, "HisyseventPlugin: Init HisyseventCmd failed");
CHECK_TRUE(InitHisyseventCmd(), -1, "HisyseventPlugin: Init HisyseventCmd failed");
fp_ = std::unique_ptr<FILE, std::function<int (FILE*)>>(
COMMON::CustomPopen(fullCmd_, "r", pipeFds_, childPid_, true), [this](FILE* fp) -> int {
@ -158,7 +158,7 @@ inline bool HisyseventPlugin::InitHisyseventCmd()
inline bool HisyseventPlugin::ParseSyseventLineInfo(const char* data, size_t len, HisyseventInfo& dataProto)
{
CHECK_TRUE(data == nullptr || len < MIN_STRING_LEN, false, "NOTE %s: param invalid", __func__);
CHECK_TRUE(data != nullptr && len >= MIN_STRING_LEN, false, "NOTE %s: param invalid", __func__);
if (google::protobuf::internal::IsStructurallyValidUTF8(data, strlen(data) - 1)) {
auto* info = dataProto.add_info();

View File

@ -90,7 +90,7 @@ int MemoryDataPlugin::InitMemVmemFd()
if (protoConfig_.report_sysmem_mem_info()) {
char fileName[PATH_MAX + 1] = {0};
char realPath[PATH_MAX + 1] = {0};
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/meminfo", testpath_) < 0, RET_FAIL,
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/meminfo", testpath_) >= 0, RET_FAIL,
"%s:snprintf_s error", __func__);
if (realpath(fileName, realPath) == nullptr) {
const int bufSize = 256;
@ -112,7 +112,7 @@ int MemoryDataPlugin::InitMemVmemFd()
if (protoConfig_.report_sysmem_vmem_info()) {
char fileName[PATH_MAX + 1] = {0};
char realPath[PATH_MAX + 1] = {0};
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/vmstat", testpath_) < 0, RET_FAIL,
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/vmstat", testpath_) >= 0, RET_FAIL,
"%s:snprintf_s error", __func__);
if (realpath(fileName, realPath) == nullptr) {
const int bufSize = 256;
@ -138,14 +138,14 @@ int MemoryDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
CHECK_NOTNULL(buffer_, RET_FAIL, "%s:buffer_ == null", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, RET_FAIL,
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL,
"%s:parseFromArray failed!", __func__);
CHECK_TRUE(InitMemVmemFd() != RET_SUCC, RET_FAIL, "InitMemVmemFd fail");
CHECK_TRUE(InitMemVmemFd() == RET_SUCC, RET_FAIL, "InitMemVmemFd fail");
if (protoConfig_.sys_meminfo_counters().size() > 0) {
for (int i = 0; i < protoConfig_.sys_meminfo_counters().size(); i++) {
CHECK_TRUE((size_t)protoConfig_.sys_meminfo_counters(i) >= meminfoStrList_.size(), RET_FAIL,
CHECK_TRUE((size_t)protoConfig_.sys_meminfo_counters(i) < meminfoStrList_.size(), RET_FAIL,
"%s:sys meminfo counter index invalid!", __func__);
if (meminfoStrList_[protoConfig_.sys_meminfo_counters(i)]) {
meminfoCounters_.emplace(meminfoStrList_[protoConfig_.sys_meminfo_counters(i)],
@ -156,7 +156,7 @@ int MemoryDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
if (protoConfig_.sys_vmeminfo_counters().size() > 0) {
for (int i = 0; i < protoConfig_.sys_vmeminfo_counters().size(); i++) {
CHECK_TRUE((size_t)protoConfig_.sys_vmeminfo_counters(i) >= vmstatStrList_.size(), RET_FAIL,
CHECK_TRUE((size_t)protoConfig_.sys_vmeminfo_counters(i) < vmstatStrList_.size(), RET_FAIL,
"%s:vmstat counter index invalid!", __func__);
if (vmstatStrList_[protoConfig_.sys_vmeminfo_counters(i)]) {
vmstatCounters_.emplace(vmstatStrList_[protoConfig_.sys_vmeminfo_counters(i)],
@ -338,7 +338,7 @@ bool MemoryDataPlugin::GetMemInfoByMemoryService(uint32_t pid, ProcessMemoryInfo
std::unique_ptr<uint8_t[]> buffer {new (std::nothrow) uint8_t[BUF_MAX_LEN]};
std::unique_ptr<FILE, int (*)(FILE*)> fp(popen(fullCmd.c_str(), "r"), pclose);
CHECK_TRUE(!fp, false, "%s:popen error", __func__);
CHECK_TRUE(fp, false, "%s:popen error", __func__);
size_t ret = fread(buffer.get(), 1, BUF_MAX_LEN, fp.get());
if (ret == 0) {
@ -454,7 +454,7 @@ int32_t MemoryDataPlugin::ReadFile(int fd)
std::string MemoryDataPlugin::ReadFile(const std::string& path)
{
char realPath[PATH_MAX] = {0};
CHECK_TRUE((path.length() >= PATH_MAX) || (realpath(path.c_str(), realPath) == nullptr), "",
CHECK_TRUE((path.length() < PATH_MAX) && (realpath(path.c_str(), realPath) != nullptr), "",
"%s:path is invalid: %s, errno=%d", __func__, path.c_str(), errno);
int fd = open(realPath, O_RDONLY);
if (fd == -1) {
@ -549,7 +549,7 @@ int32_t MemoryDataPlugin::ReadProcPidFile(int32_t pid, const char* pFileName)
char realPath[PATH_MAX + 1] = {0};
int fd = -1;
ssize_t bytesRead = 0;
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/%d/%s", testpath_, pid, pFileName) < 0,
CHECK_TRUE(snprintf_s(fileName, sizeof(fileName), sizeof(fileName) - 1, "%s/%d/%s", testpath_, pid, pFileName) >= 0,
RET_FAIL, "%s:snprintf_s error", __func__);
if (realpath(fileName, realPath) == nullptr) {
const int bufSize = 256;

View File

@ -81,7 +81,7 @@ bool SmapsStats::ReadVmemareasFile(const std::string& path, ProcessMemoryInfo& p
uint64_t prevEnd = 0;
int prevHeap = 0;
std::ifstream input(path, std::ios::in);
CHECK_TRUE(input.fail(), false, "%s:open %s failed, errno = %d", __func__, path.c_str(), errno);
CHECK_TRUE(!input.fail(), false, "%s:open %s failed, errno = %d", __func__, path.c_str(), errno);
do {
if (!input.good()) {
return false;
@ -252,10 +252,10 @@ bool SmapsStats::SetMapAddrInfo(std::string& line, MapPiecesInfo& head)
const char* pStr = line.c_str();
char* end = nullptr;
head.startAddr = strtoull(pStr, &end, HEX_BASE);
CHECK_TRUE(end == pStr || *end != '-', false, "SetMapAddrInfo fail");
CHECK_TRUE(!(end == pStr || *end != '-'), false, "SetMapAddrInfo fail");
pStr = end + 1;
head.endAddr = strtoull(pStr, &end, HEX_BASE);
CHECK_TRUE(end == pStr, false, "end == pStr");
CHECK_TRUE(end != pStr, false, "end == pStr");
return true;
}
@ -265,7 +265,7 @@ bool SmapsStats::ParseMapHead(std::string& line, MapPiecesInfo& head, SmapsHeadI
for (int i = 0; i < FIFTH_FIELD; i++) {
std::string word = newline;
size_t wordsz = word.find(" ");
CHECK_TRUE(wordsz == std::string::npos, false, "wordsz == std::string::npos");
CHECK_TRUE(wordsz != std::string::npos, false, "wordsz == std::string::npos");
word = newline.substr(0, wordsz);
if (i == 0) {
size_t pos = word.find("-");

View File

@ -272,7 +272,7 @@ int CallStack::AccessMem([[maybe_unused]] unw_addr_space_t as, unw_word_t addr,
HLOG_ASSERT(writeOperation == 0);
/* Check overflow. */
CHECK_TRUE(addr + sizeof(unw_word_t) < addr, -UNW_EUNSPEC,
CHECK_TRUE(!(addr + sizeof(unw_word_t) < addr), -UNW_EUNSPEC,
"address overfolw at 0x%" UNW_WORD_PFLAG " increase 0x%zu", addr, sizeof(unw_word_t));
if (addr < unwindInfoPtr->callStack.stackPoint_ or
@ -306,12 +306,12 @@ int CallStack::AccessReg([[maybe_unused]] unw_addr_space_t as, unw_regnum_t regn
HLOGE("access_reg not expected %d", regnum);
}
/* Don't support write, I suspect we don't need it. */
CHECK_TRUE(writeOperation, -UNW_EINVAL, "access_reg %d", regnum);
CHECK_TRUE(!writeOperation, -UNW_EINVAL, "access_reg %d", regnum);
if (unwindInfoPtr->callStack.regsNum_ == 0) {
return -UNW_EUNSPEC;
}
CHECK_TRUE(!RegisterGetValue(val, unwindInfoPtr->callStack.regs_, perfRegIndex, unwindInfoPtr->callStack.regsNum_),
CHECK_TRUE(RegisterGetValue(val, unwindInfoPtr->callStack.regs_, perfRegIndex, unwindInfoPtr->callStack.regsNum_),
-UNW_EUNSPEC, "can't read reg %zu", perfRegIndex);
*valuePoint = (unw_word_t)val;
HLOGV("reg %d:%s, val 0x%" UNW_WORD_PFLAG "", regnum, RegisterGetName(perfRegIndex).c_str(),
@ -394,8 +394,8 @@ void CallStack::UnwindStep(unw_cursor_t &c, std::vector<CallFrame> &callStack, s
bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regNum) const
{
if (regNum > 0) {
CHECK_TRUE(!RegisterGetSPValue(sp, arch_, regs, regNum), false, "unable get sp");
CHECK_TRUE(!RegisterGetIPValue(ip, arch_, regs, regNum), false, "unable get ip");
CHECK_TRUE(RegisterGetSPValue(sp, arch_, regs, regNum), false, "unable get sp");
CHECK_TRUE(RegisterGetIPValue(ip, arch_, regs, regNum), false, "unable get ip");
if (ip != 0) {
return true;
}
@ -418,7 +418,7 @@ bool CallStack::DoUnwind(const VirtualThread &thread, std::vector<CallFrame> &ca
unw_cursor_t c;
if (unwindAddrSpaceMap_.count(thread.tid_) == 0) {
addr_space = unw_create_addr_space(&accessors_, 0);
CHECK_TRUE(!addr_space, false, "Can't create unwind vaddress space.");
CHECK_TRUE(addr_space, false, "Can't create unwind vaddress space.");
unwindAddrSpaceMap_.emplace(thread.tid_, addr_space);
unw_set_caching_policy(addr_space, UNW_CACHE_GLOBAL);
unw_flush_cache(addr_space, 0, 0);

View File

@ -63,24 +63,24 @@ std::unique_ptr<ElfFile> ElfFile::MakeUnique(const std::string &filename)
{
std::unique_ptr<ElfFile> file {new (std::nothrow) ElfFile(filename)};
CHECK_NOTNULL(file, nullptr, "Error in ElfFile::MakeUnique(): ElfFile::ElfFile() failed");
CHECK_TRUE(!file->IsOpened(), nullptr, "Error in ElfFile::MakeUnique(): elf file not opended");
CHECK_TRUE(!file->ParseFile(), nullptr, "parse elf file failed");
CHECK_TRUE(file->IsOpened(), nullptr, "Error in ElfFile::MakeUnique(): elf file not opended");
CHECK_TRUE(file->ParseFile(), nullptr, "parse elf file failed");
return file;
}
bool ElfFile::ParseFile()
{
CHECK_TRUE(!ParseElfHeader(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseElfHeader() failed");
CHECK_TRUE(!ParsePrgHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParsePrgHeaders() failed");
CHECK_TRUE(!ParseSecNamesStr(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecNamesStr() failed");
CHECK_TRUE(!ParseSecHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecHeaders() failed");
CHECK_TRUE(ParseElfHeader(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseElfHeader() failed");
CHECK_TRUE(ParsePrgHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParsePrgHeaders() failed");
CHECK_TRUE(ParseSecNamesStr(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecNamesStr() failed");
CHECK_TRUE(ParseSecHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecHeaders() failed");
return true;
}
bool ElfFile::ParseElfHeader()
{
size_t ret = lseek(fd_, 0, SEEK_SET);
CHECK_TRUE(ret != 0, false, "lseek ret %zu", ret);
CHECK_TRUE(ret == 0, false, "lseek ret %zu", ret);
HLOG_ASSERT(ret == 0);
unsigned char ehdrBuf[ehdr64Size] {0};
ret = ReadFile(ehdrBuf, ehdr64Size);
@ -254,13 +254,13 @@ bool ElfFile::ParseSymTable(const SectionHeader *shdr)
bool ElfFile::ParseSymNamesStr()
{
const std::string secName {".strtab"};
CHECK_TRUE(shdrs_.find(secName) == shdrs_.end(), false,
CHECK_TRUE(shdrs_.find(secName) != shdrs_.end(), false,
"Error in ElfFile::ParseSymNamesStr(): section %s does not exist", secName.c_str());
const auto &shdr = shdrs_[secName];
uint64_t secOffset = shdr->fileOffset_;
uint64_t secSize = shdr->secSize_;
int64_t ret = lseek(fd_, secOffset, SEEK_SET);
CHECK_TRUE(ret < 0, false, "Error in ElfFile::ParsesymNamesStr(): lseek failed");
CHECK_TRUE(ret >= 0, false, "Error in ElfFile::ParsesymNamesStr(): lseek failed");
char *secBuf = new (std::nothrow) char[secSize];
CHECK_NOTNULL(secBuf, false, "Error in ElfFile::ParsesymNamesStr(): new failed");
if (memset_s(secBuf, secSize, '\0', secSize) != EOK) {
@ -282,7 +282,7 @@ bool ElfFile::ParseSymNamesStr()
bool ElfFile::ParseDynSymTable()
{
const std::string secName {".dynsym"};
CHECK_TRUE(shdrs_.find(secName) == shdrs_.end(), false,
CHECK_TRUE(shdrs_.find(secName) != shdrs_.end(), false,
"Error in ELF::ElfFile::ParseSymTable(): section %s does not exist", secName.c_str());
const auto &shdr = shdrs_[secName];
uint64_t secOffset = shdr->fileOffset_;

View File

@ -41,8 +41,8 @@ bool ElfHeader::Init(unsigned char * const ehdrBuf, const std::size_t bufSize)
{
std::string magicStr {ehdrBuf, ehdrBuf + SELFMAG};
std::string elfMagic {ELFMAG};
CHECK_TRUE(magicStr.compare(elfMagic) != 0, false, "elf magic not found");
CHECK_TRUE(memcpy_s(ehdrIdent_, EI_NIDENT, ehdrBuf, EI_NIDENT) != EOK, false, "init ehdrIdent_ failed");
CHECK_TRUE(magicStr.compare(elfMagic) == 0, false, "elf magic not found");
CHECK_TRUE(memcpy_s(ehdrIdent_, EI_NIDENT, ehdrBuf, EI_NIDENT) == EOK, false, "init ehdrIdent_ failed");
if (ehdrBuf[EI_CLASS] == ELFCLASS32 and ParseElf32Header(ehdrBuf, bufSize)) {
return true;
}
@ -121,7 +121,7 @@ bool ElfHeader::ParseElf32Header(unsigned char * const ehdrBuf, const std::size_
bool ElfHeader::ParseElf64Header(unsigned char * const ehdrBuf, const std::size_t bufSize)
{
CHECK_TRUE(bufSize < ehdr64Size, false, "bad elf64 header buffer");
CHECK_TRUE(bufSize >= ehdr64Size, false, "bad elf64 header buffer");
size_t curIndex {EI_NIDENT};
uint16_t *u2Buf = reinterpret_cast<uint16_t *>(ehdrBuf + curIndex);
type_ = u2Buf[0];

View File

@ -25,7 +25,7 @@ std::unique_ptr<ElfSymbol> ElfSymbol::MakeUnique(char * const symBuf, const std:
{
std::unique_ptr<ElfSymbol> sym {new (std::nothrow) ElfSymbol()};
CHECK_NOTNULL(sym, nullptr, "Error in ElfSymbol::MakeUnique(): ElfSymbol::ElfSymbol() failed");
CHECK_TRUE(!sym->Init(symBuf, bufSize), nullptr, "ElfSymbol::Init(symBuf, bufSize) failed");
CHECK_TRUE(sym->Init(symBuf, bufSize), nullptr, "ElfSymbol::Init(symBuf, bufSize) failed");
return sym;
}

View File

@ -140,7 +140,7 @@ bool HookManager::UnregisterAgentPlugin(const std::string& pluginPath)
request.set_plugin_id(agentIndex_);
UnregisterPluginResponse response;
if (commandPoller_->UnregisterPlugin(request, response)) {
CHECK_TRUE(response.status() != ResponseStatus::OK, false, "UnregisterPlugin FAIL 1");
CHECK_TRUE(response.status() == ResponseStatus::OK, false, "UnregisterPlugin FAIL 1");
} else {
HILOG_DEBUG(LOG_CORE, "UnregisterPlugin FAIL 2");
return false;
@ -186,10 +186,10 @@ bool HookManager::CreatePluginSession(const std::vector<ProfilerPluginConfig>& c
smbName_ = "hooknativesmb";
// save config
std::string cfgData = config[0].config_data();
CHECK_TRUE(hookConfig_.ParseFromArray(reinterpret_cast<const uint8_t*>(cfgData.c_str()), cfgData.size()) <= 0,
CHECK_TRUE(hookConfig_.ParseFromArray(reinterpret_cast<const uint8_t*>(cfgData.c_str()), cfgData.size()) > 0,
false, "%s: ParseFromArray failed", __func__);
CHECK_TRUE(getuid() != 0 && !COMMON::CheckApplicationPermission(hookConfig_.pid(), hookConfig_.process_name()),
CHECK_TRUE(getuid() == 0 || COMMON::CheckApplicationPermission(hookConfig_.pid(), hookConfig_.process_name()),
false, "Application debug permisson denied!");
pid_ = hookConfig_.pid();
@ -276,10 +276,10 @@ void HookManager::ReadShareMemory()
while (true) {
auto rawStack = std::make_shared<StackDataRepeater::RawStack>();
bool ret = shareMemoryBlock_->TakeData([&](const int8_t data[], uint32_t size) -> bool {
CHECK_TRUE(size < sizeof(BaseStackRawData), false, "stack data invalid!");
CHECK_TRUE(size >= sizeof(BaseStackRawData), false, "stack data invalid!");
rawStack->baseStackData = std::make_unique<uint8_t[]>(size);
CHECK_TRUE(memcpy_s(rawStack->baseStackData.get(), size, data, size) != EOK, false,
CHECK_TRUE(memcpy_s(rawStack->baseStackData.get(), size, data, size) == EOK, false,
"memcpy_s raw data failed!");
rawStack->stackConext = reinterpret_cast<BaseStackRawData*>(rawStack->baseStackData.get());

View File

@ -72,7 +72,7 @@ bool HookService::ProtocolProc(SocketContext &context, uint32_t pnum, const int8
HILOG_ERROR(LOG_CORE, "ProtocolProc receive peerConfig:%d not expected", peerConfig);
return false;
}
CHECK_TRUE(getuid() != 0 && !COMMON::CheckApplicationPermission(pid_, ""), false,
CHECK_TRUE(getuid() == 0 || COMMON::CheckApplicationPermission(pid_, ""), false,
"Application debug permisson denied!");
HILOG_DEBUG(LOG_CORE, "ProtocolProc, receive message from hook client, and send hook config to process %d", pid_);
context.SendHookConfig(reinterpret_cast<uint8_t *>(&clientConfig_), sizeof(clientConfig_));

View File

@ -90,7 +90,7 @@ bool SymbolsFile::UpdateBuildIdIfMatch(std::string buildId)
std::string SymbolsFile::SearchReadableFile(const std::vector<std::string> &searchPaths,
const std::string &filePath) const
{
CHECK_TRUE(filePath.empty(), filePath, "nothing to found");
CHECK_TRUE(!filePath.empty(), filePath, "nothing to found");
for (auto searchPath : searchPaths) {
if (searchPath.back() != PATH_SEPARATOR) {
searchPath += PATH_SEPARATOR;
@ -172,7 +172,7 @@ public:
{
symbolsLoaded_ = true;
std::string findPath = FindSymbolFile(symbolsFileSearchPaths_, symbolFilePath);
CHECK_TRUE(findPath.empty(), false, "elf found failed (belong to %s)", filePath_.c_str());
CHECK_TRUE(!findPath.empty(), false, "elf found failed (belong to %s)", filePath_.c_str());
if (LoadElfSymbols(findPath)) {
return true;
} else {
@ -320,7 +320,7 @@ protected:
debugInfoLoaded_ = true;
}
std::string elfPath = FindSymbolFile(symbolsFileSearchPaths_, symbolFilePath);
CHECK_TRUE(elfPath.empty(), false, "elf found failed (belong to %s)", filePath_.c_str());
CHECK_TRUE(!elfPath.empty(), false, "elf found failed (belong to %s)", filePath_.c_str());
std::unique_ptr<ElfFile> elfFile = LoadElfFile(elfPath);
if (elfFile == nullptr) {
HLOGD("elf load failed");
@ -602,7 +602,7 @@ private:
elfFile->GetStrPtr(elfFile->ehdr_->shdrStrTabIdx_, shdr->nameIndex_);
const unsigned char *data = elfFile->GetSectionData(shdr->secIndex_);
CHECK_TRUE(sh_name == nullptr || data == nullptr, false, "sh_name or data get failed.");
CHECK_TRUE(sh_name != nullptr && data != nullptr, false, "sh_name or data get failed.");
HLOGV("shdr name '%s' vaddr 0x%" PRIx64 " offset 0x%" PRIx64 " size 0x%" PRIx64
" type 0x%" PRIx64 "(%s) index %u link 0x%u entry 0x%" PRIx64 "",

View File

@ -65,7 +65,7 @@ bool HookSocketClient::Connect(const std::string addrname)
bool HookSocketClient::ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size)
{
CHECK_TRUE(size != sizeof(ClientConfig), true, "HookSocketClient::config config size not match = %u\n", size);
CHECK_TRUE(size == sizeof(ClientConfig), true, "HookSocketClient::config config size not match = %u\n", size);
*config_ = *reinterpret_cast<ClientConfig *>(const_cast<int8_t*>(buf));
config_->maxStackDepth = config_->maxStackDepth > MAX_UNWIND_DEPTH ? MAX_UNWIND_DEPTH : config_->maxStackDepth;
std::string configStr = config_->ToString();

View File

@ -51,7 +51,7 @@ int ProcessDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
CHECK_NOTNULL(buffer_, RET_FAIL, "%s:buffer_ == null", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, RET_FAIL,
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, RET_FAIL,
"%s:parseFromArray failed!", __func__);
HILOG_INFO(LOG_CORE, "%s:start success!", __func__);
@ -375,7 +375,7 @@ bool ProcessDataPlugin::ReadBootTime(int pid, CpuInfo* protoc, uint64_t& bootTim
{
std::string path = path_ + "stat";
std::ifstream input(path, std::ios::in);
CHECK_TRUE(input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
CHECK_TRUE(!input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
do {
if (!input.good()) {
return false;
@ -423,7 +423,7 @@ bool ProcessDataPlugin::ReadCpuUsage(int pid, CpuInfo* protoc, uint64_t& cpuTime
{
std::string path = path_ + std::to_string(pid) + "/stat";
std::ifstream input(path, std::ios::in);
CHECK_TRUE(input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
CHECK_TRUE(!input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
do {
if (!input.good()) {
return false;
@ -562,7 +562,7 @@ bool ProcessDataPlugin::WritePssData(int pid, PssInfo* protoc)
std::ifstream input(path, std::ios::in);
// Not capturing ENOENT (file does not exist) errors, it is common for node smaps_rollup files to be unreadable.
CHECK_TRUE(input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
CHECK_TRUE(!input.fail(), false, "%s open %s failed, errno = %d", __func__, path.c_str(), errno);
// set ifstream to O_NONBLOCK mode
CHECK_NOTNULL(input.rdbuf(), false, "%s:input rdbuf is nullptr", __func__);

View File

@ -26,7 +26,7 @@ StreamPlugin::~StreamPlugin() {}
int StreamPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
// 反序列化
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) <= 0, -1, "%s:parseFromArray failed!", __func__);
CHECK_TRUE(protoConfig_.ParseFromArray(configData, configSize) > 0, -1, "%s:parseFromArray failed!", __func__);
// 启动线程写数据
std::unique_lock<std::mutex> locker(mutex_);
running_ = true;

View File

@ -33,7 +33,7 @@ bool ProfilerCapabilityManager::AddCapability(const ProfilerPluginCapability& ca
{
std::lock_guard<std::mutex> guard(mutex_);
for (auto it = pluginCapabilities_.begin(); it != pluginCapabilities_.end(); it++) {
CHECK_TRUE(it->name() == capability.name(), false,
CHECK_TRUE(it->name() != capability.name(), false,
"capability.name conflict with %zu", (it - pluginCapabilities_.begin()));
}
pluginCapabilities_.push_back(capability);

View File

@ -353,7 +353,7 @@ Status ProfilerService::CreateSession(ServerContext* context,
bool ProfilerService::AddSessionContext(uint32_t sessionId, const SessionContextPtr& sessionCtx)
{
std::unique_lock<std::mutex> lock(sessionContextMutex_);
CHECK_TRUE(sessionContext_.count(sessionId) > 0, false, "sessionId already exists!");
CHECK_TRUE(sessionContext_.count(sessionId) == 0, false, "sessionId already exists!");
sessionContext_[sessionId] = sessionCtx;
return true;
}
@ -683,7 +683,7 @@ protected:
bool ProfilerService::StartService(const std::string& listenUri)
{
CHECK_TRUE(listenUri == "", false, "listenUri empty!");
CHECK_TRUE(!listenUri.empty(), false, "listenUri empty!");
ServerBuilder builder;
builder.AddListeningPort(listenUri, grpc::InsecureServerCredentials());

View File

@ -83,10 +83,10 @@ std::unique_ptr<BPFController> BPFController::MakeUnique(const BPFConfig& config
CHECK_NOTNULL(bpfctlr, nullptr, "failed to instantiate BPFController");
HHLOGI(true, "BPFController instantiated");
CHECK_TRUE(bpfctlr->VerifyConfigurations() != 0, nullptr, "failed to verify config");
CHECK_TRUE(bpfctlr->VerifyConfigurations() == 0, nullptr, "failed to verify config");
HHLOGI(true, "BPFConfig verified");
CHECK_TRUE(bpfctlr->SetUpBPF() != 0, nullptr, "failed to set up BPF");
CHECK_TRUE(bpfctlr->SetUpBPF() == 0, nullptr, "failed to set up BPF");
HHLOGI(true, "BPF setup done");
return bpfctlr;
@ -94,40 +94,40 @@ std::unique_ptr<BPFController> BPFController::MakeUnique(const BPFConfig& config
static inline int VerifyDumpEvents(const __u32 nr)
{
CHECK_TRUE(nr > BPFController::DUMP_EVENTS_LIMIT, -1, "dump events exceeds limit");
CHECK_TRUE(nr <= BPFController::DUMP_EVENTS_LIMIT, -1, "dump events exceeds limit");
return 0;
}
static inline int VerifyTraceDuration(const __u32 duration)
{
CHECK_TRUE(duration > BPFController::TRACE_DURATION_LIMIT, -1, "trace duration exceeds limit");
CHECK_TRUE(duration <= BPFController::TRACE_DURATION_LIMIT, -1, "trace duration exceeds limit");
return 0;
}
static inline int VerifyMaxStackDepth(const __u32 depth)
{
CHECK_TRUE(depth > MAX_STACK_LIMIT, -1, "max stack depth exceeds limit");
CHECK_TRUE(depth <= MAX_STACK_LIMIT, -1, "max stack depth exceeds limit");
return 0;
}
int BPFController::VerifySelectEventGroups(const std::set<HiebpfEventGroup> &selectEventGroups)
{
CHECK_TRUE(selectEventGroups.empty(), -1, "VerifySelectEventGroups() failed: event group list is empty");
CHECK_TRUE(!selectEventGroups.empty(), -1, "VerifySelectEventGroups() failed: event group list is empty");
selectEventGroups_ = selectEventGroups;
return 0;
}
int BPFController::VerifyConfigurations()
{
CHECK_TRUE(VerifySelectEventGroups(config_.selectEventGroups_) != 0, -1, "VerifySelectEventGroups fail");
CHECK_TRUE(VerifySelectEventGroups(config_.selectEventGroups_) == 0, -1, "VerifySelectEventGroups fail");
HHLOGI(true, "VerifySelectEventGroups() done");
CHECK_TRUE(VerifyDumpEvents(config_.dumpEvents_) != 0, -1,
CHECK_TRUE(VerifyDumpEvents(config_.dumpEvents_) == 0, -1,
"VerifyDumpEvents() failed: dump events = %u", config_.dumpEvents_);
HHLOGI(true, "VerifyDumpEents() done");
CHECK_TRUE(VerifyTraceDuration(config_.traceDuration_) != 0, -1,
CHECK_TRUE(VerifyTraceDuration(config_.traceDuration_) == 0, -1,
"VerifyTraceDuration() failed: duration = %u", config_.traceDuration_);
HHLOGI(true, "VerifyTraceDuration() done");
CHECK_TRUE(VerifyMaxStackDepth(config_.maxStackDepth_) != 0, -1,
CHECK_TRUE(VerifyMaxStackDepth(config_.maxStackDepth_) == 0, -1,
"VerifyMaxStackDepth() failed: max stack depth = %u", config_.maxStackDepth_);
HHLOGI(true, "VerifyMaxStackDepth() done");
return 0;
@ -135,7 +135,7 @@ int BPFController::VerifyConfigurations()
int BPFController::SetUpBPF()
{
CHECK_TRUE(ConfigLIBBPFLogger() != 0, -1, "failed to configure LIBBPF logger");
CHECK_TRUE(ConfigLIBBPFLogger() == 0, -1, "failed to configure LIBBPF logger");
HHLOGI(true, "ConfigLIBBPFLogger() done");
// set up libbpf deubug level
@ -146,7 +146,7 @@ int BPFController::SetUpBPF()
skel_ = hiebpf_bpf__open();
int err = libbpf_get_error(skel_);
CHECK_TRUE(err, err, "failed to open BPF skeleton: %s", strerror(-err));
CHECK_TRUE(!err, err, "failed to open BPF skeleton: %s", strerror(-err));
HHLOGI(true, "BPF skeleton opened");
if (config_.unwindStack_) {
ips_ = new(std::nothrow) __u64[config_.maxStackDepth_];
@ -155,12 +155,12 @@ int BPFController::SetUpBPF()
HHLOGI(true, "allocate ips buffer done");
dataFile_ = HiebpfDataFile::MakeShared(config_.cmd_, config_.outputFile_);
CHECK_NOTNULL(dataFile_, -1, "failed to make hiebpf data file");
CHECK_TRUE(FilterProgByEvents() != 0, -1, "failed to load BPF objects");
CHECK_TRUE(FilterProgByEvents() == 0, -1, "failed to load BPF objects");
HHLOGI(true, "make HiebpfDataFile done");
skel_->rodata->g_stack_limit = config_.maxStackDepth_;
err = hiebpf_bpf__load(skel_);
CHECK_TRUE(err, err, "failed to load BPF skeleton: %s", strerror(-err));
CHECK_TRUE(ConfigureBPF() != 0, -1, "failed to configure BPF");
CHECK_TRUE(!err, err, "failed to load BPF skeleton: %s", strerror(-err));
CHECK_TRUE(ConfigureBPF() == 0, -1, "failed to configure BPF");
HHLOGI(true, "BPF configuration done");
return 0;
@ -247,11 +247,11 @@ static int InitTracerPid(const int fd, bool excludeTracer)
* to exclude the tracer itself
*/
pid = static_cast<int32_t>(getpid());
CHECK_TRUE(pid < 0, -1, "failed to get current pid");
CHECK_TRUE(pid >= 0, -1, "failed to get current pid");
}
constexpr __u32 pididx {TRACER_PID_INDEX};
int err = bpf_map_update_elem(fd, &pididx, &pid, BPF_ANY);
CHECK_TRUE(err, -1, "failed to update tracer pid %d in config_var_map", pid);
CHECK_TRUE(!err, -1, "failed to update tracer pid %d in config_var_map", pid);
return 0;
}
@ -263,7 +263,7 @@ static inline int InitBPFLogLevel(const int fd, const __u32 level)
}
constexpr __u32 levelidx {BPF_LOG_LEVEL_INDEX};
int err = bpf_map_update_elem(fd, &levelidx, &level, BPF_ANY);
CHECK_TRUE(err, -1, "failed to set bpf log level in config_var_map");
CHECK_TRUE(!err, -1, "failed to set bpf log level in config_var_map");
return 0;
}
@ -275,22 +275,22 @@ static inline int InitUnwindFlag(const int fd, bool unwind)
uflag = 1;
}
int err = bpf_map_update_elem(fd, &uflagidx, &uflag, BPF_ANY);
CHECK_TRUE(err, -1, "failed to set unwind stack flag in config_var_map");
CHECK_TRUE(!err, -1, "failed to set unwind stack flag in config_var_map");
return 0;
}
int BPFController::InitBPFVariables() const
{
int fd = bpf_map__fd(skel_->maps.config_var_map);
CHECK_TRUE(fd < 0, -1, "failed to get fd of config_var_map");
CHECK_TRUE(fd >= 0, -1, "failed to get fd of config_var_map");
HHLOGI(true, "InitBPFVariables() done");
CHECK_TRUE(InitTracerPid(fd, config_.excludeTracer_) != 0, -1,
CHECK_TRUE(InitTracerPid(fd, config_.excludeTracer_) == 0, -1,
"failed to init tracer pid in config_var_map");
HHLOGI(true, "InitTracerPid() done");
CHECK_TRUE(InitBPFLogLevel(fd, config_.BPFLogLevel_) != 0, -1,
CHECK_TRUE(InitBPFLogLevel(fd, config_.BPFLogLevel_) == 0, -1,
"failed to init BPF log level in config_var_map");
HHLOGI(true, "InitBPFLogLevel() done");
CHECK_TRUE(InitUnwindFlag(fd, config_.unwindStack_) != 0, -1,
CHECK_TRUE(InitUnwindFlag(fd, config_.unwindStack_) == 0, -1,
"failed to init unwind stack flag in config_var_map");
HHLOGI(true, "InitUnwindFlag() done");
return 0;
@ -299,7 +299,7 @@ int BPFController::InitBPFVariables() const
int BPFController::FillTargetPidMap() const
{
int fd = bpf_map__fd(skel_->maps.target_pid_map);
CHECK_TRUE(fd < 0, -1, "failed to get fd of target_pid_map");
CHECK_TRUE(fd >= 0, -1, "failed to get fd of target_pid_map");
int index {0};
uint32_t val {1}; // target_pid_Map[0] = 1 means tracing all processes
int err {0};
@ -308,7 +308,7 @@ int BPFController::FillTargetPidMap() const
if (numPids == 0) {
// no target pid specified, trace all processes
err = bpf_map_update_elem(fd, &index, &val, BPF_ANY);
CHECK_TRUE(err, -1, "failed to set target pid = %u", val);
CHECK_TRUE(!err, -1, "failed to set target pid = %u", val);
return 0;
}
if (numPids > MAX_TARGET_PIDS) {
@ -320,7 +320,7 @@ int BPFController::FillTargetPidMap() const
HHLOGD(true, "target pid = %d", val);
std::cout << "target pid = " << val << std::endl;
err = bpf_map_update_elem(fd, &index, &val, BPF_ANY);
CHECK_TRUE(err, -1, "failed to set target pid = %d", val);
CHECK_TRUE(!err, -1, "failed to set target pid = %d", val);
}
return 0;
}
@ -361,14 +361,14 @@ int BPFController::ConfigReceivers()
BPFController::HandleEvent,
this, nullptr);
int err = libbpf_get_error(rb_);
CHECK_TRUE(err, err, "failed to make BPF ring buffer: %s", strerror(-err));
CHECK_TRUE(!err, err, "failed to make BPF ring buffer: %s", strerror(-err));
if (config_.pipelines_ == 0) {
config_.pipelines_ = MIN_PIPELINES_LIMIT;
}
for (__u32 cnt = config_.pipelines_; cnt != 0; --cnt) {
receivers_.push_back(BPFEventReceiver::MakeShared(dataFile_));
}
CHECK_TRUE(receivers_.size() != config_.pipelines_, -1, "failed to make BPF event receivers");
CHECK_TRUE(receivers_.size() == config_.pipelines_, -1, "failed to make BPF event receivers");
last_ = 0;
} else {
rb_ = ring_buffer__new(
@ -376,24 +376,24 @@ int BPFController::ConfigReceivers()
BPFController::DumpEvent,
this, nullptr);
int err = libbpf_get_error(rb_);
CHECK_TRUE(err, err, "failed to make BPF ring buffer: %s", strerror(-err));
CHECK_TRUE(!err, err, "failed to make BPF ring buffer: %s", strerror(-err));
}
return 0;
}
uint64_t BPFController::GetSymOffset(const std::string &path, const std::string &symbol)
{
CHECK_TRUE(access(path.c_str(), F_OK) != 0, 0, "the file does not exist");
CHECK_TRUE(access(path.c_str(), F_OK) == 0, 0, "the file does not exist");
using namespace OHOS::Developtools::Hiebpf;
std::unique_ptr<ElfFile> elfFile = ElfFile::MakeUnique(path);
CHECK_NOTNULL(elfFile, 0, "ELF file open failed");
const std::string dynsym {".dynsym"};
CHECK_TRUE(elfFile->shdrs_.find(dynsym) == elfFile->shdrs_.end(), 0, "section dynsym failed to obtain data");
CHECK_TRUE(elfFile->shdrs_.find(dynsym) != elfFile->shdrs_.end(), 0, "section dynsym failed to obtain data");
const auto &sym = elfFile->shdrs_[dynsym];
const uint8_t *symData = elfFile->GetSectionData(sym->secIndex_);
const std::string dynstr {".dynstr"};
CHECK_TRUE(elfFile->shdrs_.find(dynstr) == elfFile->shdrs_.end(), 0, "section dynstr failed to obtain data");
CHECK_TRUE(elfFile->shdrs_.find(dynstr) != elfFile->shdrs_.end(), 0, "section dynstr failed to obtain data");
const auto &str = elfFile->shdrs_[dynstr];
const uint8_t *strData = elfFile->GetSectionData(str->secIndex_);
@ -402,21 +402,21 @@ uint64_t BPFController::GetSymOffset(const std::string &path, const std::string
uint64_t vaddr = 0;
while (stepLength < sym->secSize_) {
int ret = memcpy_s(&st_name, sizeof(uint32_t), symData + stepLength, sizeof(uint32_t));
CHECK_TRUE(ret != EOK, 0, "failed to memcpy symData");
CHECK_TRUE(ret == EOK, 0, "failed to memcpy symData");
auto name = const_cast<uint8_t*>(strData + st_name);
if (name != nullptr && std::string(reinterpret_cast<char*>(name)).compare(symbol) == 0) {
int32_t valueOffset = sym->secEntrySize_ == sizeof(Elf64_Sym) ? SYM_64_VALUE_OFFSET : SYM_32_VALUE_OFFSET;
int32_t valueSize = valueOffset == SYM_64_VALUE_OFFSET ? sizeof(uint64_t) : sizeof(uint32_t);
ret = memcpy_s(&vaddr, sizeof(uint64_t), symData + stepLength + valueOffset, valueSize);
CHECK_TRUE(ret != EOK, 0, "failed to memcpy symData");
CHECK_TRUE(ret == EOK, 0, "failed to memcpy symData");
break;
}
stepLength += sym->secEntrySize_;
}
CHECK_TRUE(vaddr == 0, 0, "get vaddr failed");
CHECK_TRUE(vaddr != 0, 0, "get vaddr failed");
const std::string text {".text"};
CHECK_TRUE(elfFile->shdrs_.find(text) == elfFile->shdrs_.end(), 0, "section text failed to obtain data");
CHECK_TRUE(elfFile->shdrs_.find(text) != elfFile->shdrs_.end(), 0, "section text failed to obtain data");
const auto &textPtr = elfFile->shdrs_[text];
return vaddr - textPtr->secVaddr_ + textPtr->fileOffset_;
}
@ -424,27 +424,27 @@ uint64_t BPFController::GetSymOffset(const std::string &path, const std::string
int32_t BPFController::ConfigDlopenBPFProg()
{
uint64_t symOffset = GetSymOffset(THIRD_PARTY_MUSL_ADDR, "dlopen");
CHECK_TRUE(symOffset == 0, -1, "get symOffset failed");
CHECK_TRUE(symOffset != 0, -1, "get symOffset failed");
skel_->links.uretprobe_dlopen = bpf_program__attach_uprobe(skel_->progs.uretprobe_dlopen,
true,
-1,
THIRD_PARTY_MUSL_ADDR.c_str(),
symOffset);
CHECK_TRUE(!skel_->links.uretprobe_dlopen, -1, "failed to attach uretprobe_dlopen");
CHECK_TRUE(skel_->links.uretprobe_dlopen, -1, "failed to attach uretprobe_dlopen");
return 0;
}
int BPFController::ConfigureBPF()
{
CHECK_TRUE(InitBPFVariables() != 0, -1, "failed to fill config_var_map");
CHECK_TRUE(InitBPFVariables() == 0, -1, "failed to fill config_var_map");
HHLOGI(true, "InitBPFVariables() done");
CHECK_TRUE(FillTargetPidMap() != 0, -1, "failed to fill target_pid_map");
CHECK_TRUE(FillTargetPidMap() == 0, -1, "failed to fill target_pid_map");
HHLOGI(true, "FillTargetPidMap() done");
CHECK_TRUE(ConfigBPFLogger() != 0, -1, "failed to configure BPF logger");
CHECK_TRUE(ConfigBPFLogger() == 0, -1, "failed to configure BPF logger");
HHLOGI(true, "ConfigBPFLogger() done");
CHECK_TRUE(ConfigReceivers() != 0, -1, "failed to configure BPF ringbuffer");
CHECK_TRUE(ConfigReceivers() == 0, -1, "failed to configure BPF ringbuffer");
HHLOGI(true, "ConfigReceivers() done");
CHECK_TRUE(ConfigDlopenBPFProg() != 0, -1, "failed to configure user BPF prog");
CHECK_TRUE(ConfigDlopenBPFProg() == 0, -1, "failed to configure user BPF prog");
return 0;
}
@ -452,14 +452,14 @@ int BPFController::Start()
{
#if defined(BPF_LOGGER_DEBUG) || defined(BPF_LOGGER_INFO) || defined(BPF_LOGGER_WARN) || \
defined(BPF_LOGGER_ERROR) || defined(BPF_LOGGER_FATAL)
CHECK_TRUE(StartBPFLogReader() != 0, -1, "failed to start BPF log reader");
CHECK_TRUE(StartBPFLogReader() == 0, -1, "failed to start BPF log reader");
#endif
HHLOGI(true, "BPF log reader started");
CHECK_TRUE(StartReceivers() != 0, -1, "failed to start receivers");
CHECK_TRUE(StartReceivers() == 0, -1, "failed to start receivers");
HHLOGI(true, "receivers started");
// activate events
int err = hiebpf_bpf__attach(skel_);
CHECK_TRUE(err, -1, "failed to attach bpf object: %s", strerror(-err));
CHECK_TRUE(!err, -1, "failed to attach bpf object: %s", strerror(-err));
HHLOGI(true, "BPF events activated");
const auto endTime = std::chrono::steady_clock::now() + std::chrono::seconds(config_.traceDuration_);

View File

@ -290,7 +290,7 @@ int BPFEventReceiver::EncodeFSTraceEvent(
item->pid_ = cmplt_event->tgid;
item->tid_ = cmplt_event->pid;
CHECK_TRUE(strncpy_s(item->tracerName_, MAX_TRACER_NAME_LEN,
gTracerTable[FSTRACE].c_str(), gTracerTable[FSTRACE].size()) != EOK,
gTracerTable[FSTRACE].c_str(), gTracerTable[FSTRACE].size()) == EOK,
-1, "failed to copy fstrace tracer name");
item->stime_ = cmplt_event->start_event.stime;
item->ctime_ = cmplt_event->ctime;
@ -299,9 +299,9 @@ int BPFEventReceiver::EncodeFSTraceEvent(
item->type_ = static_cast<uint16_t>(cmplt_event->start_event.type);
CHECK_TRUE(strncpy_s(item->typeName_, MAX_TYPE_NAME_LEN,
gFSTraceTypeTable[item->type_].c_str(),
gFSTraceTypeTable[item->type_].size() != EOK),
gFSTraceTypeTable[item->type_].size() == EOK),
-1, "failed to copy fstrace type name");
CHECK_TRUE(ConvertFSTraceArgsToArray(item->args_, &cmplt_event->start_event) != 0, -1,
CHECK_TRUE(ConvertFSTraceArgsToArray(item->args_, &cmplt_event->start_event) == 0, -1,
"failed to convert fstrace event args");
(void)memcpy_s(item->comm_, MAX_COMM_LEN, cmplt_event->comm, MAX_COMM_LEN);
if (item->nips_ != 0) {
@ -326,7 +326,7 @@ int BPFEventReceiver::EncodePFTraceEvent(
item->pid_ = cmplt_event->tgid;
item->tid_ = cmplt_event->pid;
CHECK_TRUE(strncpy_s(item->tracerName_, MAX_TRACER_NAME_LEN,
gTracerTable[PFTRACE].c_str(), gTracerTable[PFTRACE].size() != EOK),
gTracerTable[PFTRACE].c_str(), gTracerTable[PFTRACE].size() == EOK),
-1, "failed to copy pftrace tracer name");
item->stime_ = cmplt_event->start_event.stime;
item->ctime_ = cmplt_event->ctime;
@ -337,7 +337,7 @@ int BPFEventReceiver::EncodePFTraceEvent(
CHECK_TRUE(strncpy_s(item->typeName_,
MAX_TYPE_NAME_LEN,
gPFTraceTypeTable[item->type_].c_str(),
gPFTraceTypeTable[item->type_].size()) != EOK,
gPFTraceTypeTable[item->type_].size()) == EOK,
-1, "failed to copy pftrace type name");
(void)memcpy_s(item->comm_, MAX_COMM_LEN, cmplt_event->comm, MAX_COMM_LEN);
if (item->nips_ != 0) {
@ -372,7 +372,7 @@ int BPFEventReceiver::EncodeBIOTraceEvent(
CHECK_TRUE(strncpy_s(item->typeName_,
MAX_TYPE_NAME_LEN,
gBIOTraceTypeTable[item->type_].c_str(),
gBIOTraceTypeTable[item->type_].size()) != EOK,
gBIOTraceTypeTable[item->type_].size()) == EOK,
-1, "failed to copy BIOstrace type name");
if (item->nips_ != 0) {
int ret = memcpy_s(reinterpret_cast<__u64*>((reinterpret_cast<char *>(item) +
@ -402,7 +402,7 @@ int BPFEventReceiver::EncodeSTRTraceEvent(
if (item->strLen_ and item->strLen_ <= MAX_FILENAME_LEN) {
char *filename = static_cast<char*>(tlvItem);
filename += sizeof(struct FixedSTRTraceTLVItem);
CHECK_TRUE(strncpy_s(filename, MAX_FILENAME_LEN, cmplt_event->filename, item->strLen_) != EOK, -1,
CHECK_TRUE(strncpy_s(filename, MAX_FILENAME_LEN, cmplt_event->filename, item->strLen_) == EOK, -1,
"failed to copy cmplt_event file name");
if (item->srcTracer_ == BIOTRACE || (item->srcTracer_ == FSTRACE && item->srcType_ == SYS_CLOSE)) {
ReverseStr(filename, filename + item->strLen_ - 2); // 2: last 2 chars

View File

@ -56,28 +56,28 @@ std::unique_ptr<ElfFile> ElfFile::MakeUnique(const std::string &filename)
{
std::unique_ptr<ElfFile> file {new (std::nothrow) ElfFile(filename)};
CHECK_NOTNULL(file, nullptr, "Error in ElfFile::MakeUnique(): ElfFile::ElfFile() failed");
CHECK_TRUE(!file->IsOpened(), nullptr, "Error in ElfFile::MakeUnique(): elf file not opended");
CHECK_TRUE(!file->ParseFile(), nullptr, "parse elf file failed");
CHECK_TRUE(file->IsOpened(), nullptr, "Error in ElfFile::MakeUnique(): elf file not opended");
CHECK_TRUE(file->ParseFile(), nullptr, "parse elf file failed");
return file;
}
bool ElfFile::ParseFile()
{
CHECK_TRUE(!ParseElfHeader(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseElfHeader() failed");
CHECK_TRUE(!ParsePrgHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParsePrgHeaders() failed");
CHECK_TRUE(!ParseSecNamesStr(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecNamesStr() failed");
CHECK_TRUE(!ParseSecHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecHeaders() failed");
CHECK_TRUE(ParseElfHeader(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseElfHeader() failed");
CHECK_TRUE(ParsePrgHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParsePrgHeaders() failed");
CHECK_TRUE(ParseSecNamesStr(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecNamesStr() failed");
CHECK_TRUE(ParseSecHeaders(), false, "Error in ElfFile::MakeUnique(): ElfFile::ParseSecHeaders() failed");
return true;
}
bool ElfFile::ParseElfHeader()
{
ssize_t ret = lseek(fd_, 0, SEEK_SET);
CHECK_TRUE(ret != 0, false, "lseek ret %zu", ret);
CHECK_TRUE(ret == 0, false, "lseek ret %zu", ret);
unsigned char ehdrBuf[ehdr64Size] {0};
size_t readsize = ReadFile(ehdrBuf, ehdr64Size);
CHECK_TRUE(readsize < ehdr64Size, false, "file size not enough, try read %zu, only have %zu", ehdr64Size, readsize);
CHECK_TRUE(readsize >= ehdr64Size, false, "file size not enough, try read %zu, only have %zu", ehdr64Size, readsize);
ehdr_ = ElfHeader::MakeUnique(ehdrBuf, readsize);
return !(ehdr_ == nullptr);
}
@ -231,7 +231,7 @@ std::unique_ptr<ElfHeader> ElfHeader::MakeUnique(unsigned char * const ehdrBuf,
{
std::unique_ptr<ElfHeader> ehdr {new (std::nothrow) ElfHeader()};
CHECK_NOTNULL(ehdr, nullptr, "ElfHeader() failed");
CHECK_TRUE(!ehdr->Init(ehdrBuf, bufSize, nullptr, "ElfHeader::Init(ehdrBuf, bufSize) failed\n");
CHECK_TRUE(ehdr->Init(ehdrBuf, bufSize), nullptr, "ElfHeader::Init(ehdrBuf, bufSize) failed\n");
return ehdr;
}
@ -239,7 +239,7 @@ bool ElfHeader::Init(unsigned char * const ehdrBuf, const std::size_t bufSize)
{
std::string magicStr {ehdrBuf, ehdrBuf + SELFMAG};
std::string elfMagic {ELFMAG};
CHECK_TRUE(magicStr.compare(elfMagic) != 0, false, "elf magic not found");
CHECK_TRUE(magicStr.compare(elfMagic) == 0, false, "elf magic not found");
std::copy(ehdrBuf, ehdrBuf + EI_NIDENT, ehdrIdent_);
if (ehdrBuf[EI_CLASS] == ELFCLASS32 and ParseElf32Header(ehdrBuf, bufSize)) {
@ -315,7 +315,7 @@ bool ElfHeader::ParseElf32Header(unsigned char * const ehdrBuf, const std::size_
bool ElfHeader::ParseElf64Header(unsigned char * const ehdrBuf, const std::size_t bufSize)
{
CHECK_TRUE(bufSize < ehdr64Size, false, "bad elf64 header buffer");
CHECK_TRUE(bufSize >= ehdr64Size, false, "bad elf64 header buffer");
size_t curIndex {EI_NIDENT};
uint16_t *u2Buf = reinterpret_cast<uint16_t *>(ehdrBuf + curIndex);
type_ = u2Buf[0];
@ -395,7 +395,7 @@ std::unique_ptr<SectionHeader> SectionHeader::MakeUnique(char * const shdrBuf, c
if (shdr == nullptr) {
return nullptr;
}
CHECK_TRUE(!shdr->Init(shdrBuf, bufSize, index), nullptr, "SectionHeader::Init(shdrBuf, bufSize, index) failed");
CHECK_TRUE(shdr->Init(shdrBuf, bufSize, index), nullptr, "SectionHeader::Init(shdrBuf, bufSize, index) failed");
return shdr;
}
@ -456,7 +456,7 @@ std::unique_ptr<ProgramHeader> ProgramHeader::MakeUnique(char * const phdrBuf, c
{
std::unique_ptr<ProgramHeader> phdr {new (std::nothrow) ProgramHeader()};
CHECK_NOTNULL(phdr, nullptr, "ProgramHeader() failed");
CHECK_TRUE(!phdr->Init(phdrBuf, bufSize), nullptr, "ProgramHeader::Init(phdrBuf, bufSize) failed");
CHECK_TRUE(phdr->Init(phdrBuf, bufSize), nullptr, "ProgramHeader::Init(phdrBuf, bufSize) failed");
return phdr;
}

View File

@ -38,7 +38,7 @@ bool ElfSymbolInfo::GetSymbolTable(const std::string &fileName, ElfSymbolTable &
}
}
}
CHECK_TRUE(symbolTable.textVaddr_ == (std::numeric_limits<uint64_t>::max)(), false, "get text vaddr failed");
CHECK_TRUE(symbolTable.textVaddr_ != (std::numeric_limits<uint64_t>::max)(), false, "get text vaddr failed");
const std::string symTab {".symtab"};
if (elfFile->shdrs_.find(symTab) != elfFile->shdrs_.end()) {
@ -52,7 +52,7 @@ bool ElfSymbolInfo::GetSymbolTable(const std::string &fileName, ElfSymbolTable &
// get .strtab
const std::string strTab {".strtab"};
CHECK_TRUE(elfFile->shdrs_.find(strTab) == elfFile->shdrs_.end(), false, "get symbol tab failed");
CHECK_TRUE(elfFile->shdrs_.find(strTab) != elfFile->shdrs_.end(), false, "get symbol tab failed");
const auto &strshdr = elfFile->shdrs_[strTab];
data = elfFile->GetSectionData(strshdr->secIndex_);
CHECK_NOTNULL(data, false, "get section data failed");
@ -61,7 +61,7 @@ bool ElfSymbolInfo::GetSymbolTable(const std::string &fileName, ElfSymbolTable &
} else {
// get .dynsym
const std::string dynSym {".dynsym"};
CHECK_TRUE(elfFile->shdrs_.find(dynSym) == elfFile->shdrs_.end(), false, "get symbol tab failed");
CHECK_TRUE(elfFile->shdrs_.find(dynSym) != elfFile->shdrs_.end(), false, "get symbol tab failed");
const auto &shdr = elfFile->shdrs_[dynSym];
const uint8_t *data = elfFile->GetSectionData(shdr->secIndex_);
CHECK_NOTNULL(data, false, "get section data failed");
@ -71,14 +71,14 @@ bool ElfSymbolInfo::GetSymbolTable(const std::string &fileName, ElfSymbolTable &
// get .dynstr
const std::string dynStr {".dynstr"};
CHECK_TRUE(elfFile->shdrs_.find(dynStr) == elfFile->shdrs_.end(), false, "get symbol tab failed");
CHECK_TRUE(elfFile->shdrs_.find(dynStr) != elfFile->shdrs_.end(), false, "get symbol tab failed");
const auto &strshdr = elfFile->shdrs_[dynStr];
data = elfFile->GetSectionData(strshdr->secIndex_);
CHECK_NOTNULL(data, false, "get section data failed");
symbolTable.strTable_.resize(strshdr->secSize_);
std::copy(data, data + strshdr->secSize_, symbolTable.strTable_.data());
}
CHECK_TRUE(symbolTable.strTable_.size() == 0 || symbolTable.symTable_.size() == 0, false,
CHECK_TRUE(symbolTable.strTable_.size() != 0 && symbolTable.symTable_.size() != 0, false,
"get strTable_ or symTable failed");
symbolTable.fileName_ = fileName;

View File

@ -98,11 +98,11 @@ static void HandleIpcMessage(const void *data, size_t size)
static bool SendIpcCommand(OHOS::Developtools::Hiebpf::IpcUnixSocketClient &client,
HiebpfIpcCommand cmd, uint32_t timeout)
{
CHECK_TRUE(!client.SendMessage(&cmd, sizeof(HiebpfIpcCommand)), false, "send request(0x%x) failed\n", cmd);
CHECK_TRUE(client.SendMessage(&cmd, sizeof(HiebpfIpcCommand)), false, "send request(0x%x) failed\n", cmd);
size_t size = OHOS::Developtools::Hiebpf::UNIX_SOCKET_BUFFER_SIZE;
char buf[OHOS::Developtools::Hiebpf::UNIX_SOCKET_BUFFER_SIZE] = {0};
CHECK_TRUE(!client.RecvMessage(buf, size, timeout), false, "recv reply failed\n");
CHECK_TRUE(client.RecvMessage(buf, size, timeout), false, "recv reply failed\n");
if (size == 0) { // timeout
HHLOGE(true, "recv reply timeout(%dms)\n", timeout);
return false;
@ -111,7 +111,7 @@ static bool SendIpcCommand(OHOS::Developtools::Hiebpf::IpcUnixSocketClient &clie
return false;
}
HiebpfIpcCommand reply = *(reinterpret_cast<HiebpfIpcCommand*>(buf));
CHECK_TRUE(reply != HiebpfIpcCommand::RET_OK, false, "recv unknown reply: 0x%x\n", reply);
CHECK_TRUE(reply == HiebpfIpcCommand::RET_OK, false, "recv unknown reply: 0x%x\n", reply);
return true;
}

View File

@ -27,8 +27,8 @@ std::shared_ptr<HiebpfDataFile> HiebpfDataFile::MakeShared(
{
std::shared_ptr<HiebpfDataFile> obj {new(std::nothrow) HiebpfDataFile {cmd, filename, pages}};
CHECK_NOTNULL(obj, nullptr, "failed to make HiebpfDataFile");
CHECK_TRUE(obj->OpenFile() != 0, nullptr, "failed to open hiebpf data file");
CHECK_TRUE(obj->MapFile() != 0, nullptr, "failed to map hiebpf data file into memory");
CHECK_TRUE(obj->OpenFile() == 0, nullptr, "failed to open hiebpf data file");
CHECK_TRUE(obj->MapFile() == 0, nullptr, "failed to map hiebpf data file into memory");
return obj;
}
@ -97,7 +97,7 @@ void HiebpfDataFile::Submit(void *data)
int HiebpfDataFile::MapFile()
{
CHECK_TRUE(ExtendFile(mapPos_, length_) != 0, -1,
CHECK_TRUE(ExtendFile(mapPos_, length_) == 0, -1,
"failed to extend data file from %u with %u bytes", mapPos_, length_);
HHLOGI(true, "done extending the data file");
// map the file
@ -105,10 +105,10 @@ int HiebpfDataFile::MapFile()
nullptr, length_,
PROT_WRITE | PROT_READ, MAP_SHARED | MAP_POPULATE,
fd_, mapPos_);
CHECK_TRUE(mapAddr_ == MAP_FAILED, -1, "mmap() failed: %s", strerror(errno));
CHECK_TRUE(mapAddr_ != MAP_FAILED, -1, "mmap() failed: %s", strerror(errno));
HHLOGI(true, "done mem mapping hiebpf data file");
// hiebpf data file header
CHECK_TRUE(WriteFileHeader() != 0, -1, "failed to write hiebpf data file header");
CHECK_TRUE(WriteFileHeader() == 0, -1, "failed to write hiebpf data file header");
HHLOGI(true, "done writing hiebpf data file header");
return 0;
}
@ -127,14 +127,14 @@ int HiebpfDataFile::RemapFile(const std::size_t size)
extendLength += DEFAULT_MMAP_LENGTH;
}
CHECK_TRUE(ExtendFile(remapPos, extendLength) != 0, -1,
CHECK_TRUE(ExtendFile(remapPos, extendLength) == 0, -1,
"failed to extend file from %u with %u bytes", remapPos, length_);
HHLOGI(true, "done extending the data file");
mapAddr_ = mmap(
nullptr, extendLength,
PROT_WRITE | PROT_READ, MAP_SHARED | MAP_POPULATE,
fd_, remapPos);
CHECK_TRUE(mapAddr_ == MAP_FAILED, -1, "failed to remap data file from %u to %u", mapPos_, remapPos);
CHECK_TRUE(mapAddr_ != MAP_FAILED, -1, "failed to remap data file from %u to %u", mapPos_, remapPos);
HHLOGI(true, "done remapping data file from %u, to %u", mapPos_, remapPos);
mapPos_ = remapPos;
offset_ = remapOff;

View File

@ -33,10 +33,10 @@ IpcUnixSocketServer::~IpcUnixSocketServer()
bool IpcUnixSocketServer::Start(const std::string &pathname)
{
CHECK_TRUE(serverFd_ != -1, false, "Unix Socket Server is running");
CHECK_TRUE(serverFd_ == -1, false, "Unix Socket Server is running");
serverFd_ = socket(AF_UNIX, SOCK_STREAM, 0);
CHECK_TRUE(serverFd_ == -1, false, "create Unix Socket Server failed, %d: %s", errno, strerror(errno));
CHECK_TRUE(serverFd_ != -1, false, "create Unix Socket Server failed, %d: %s", errno, strerror(errno));
unlink(pathname.c_str());
struct sockaddr_un addr = {0};
@ -81,9 +81,9 @@ bool IpcUnixSocketServer::Stop()
bool IpcUnixSocketServer::SendMessage(const void *buf, size_t size)
{
CHECK_TRUE(clientFd_ == -1, false, "no available Unix Socket");
CHECK_TRUE(clientFd_ != -1, false, "no available Unix Socket");
CHECK_TRUE(send(clientFd_, buf, size, 0) == -1, false,
CHECK_TRUE(send(clientFd_, buf, size, 0) != -1, false,
"send failed, Unix Socket(%d) %zu bytes, %d: %s", clientFd_, size, errno, strerror(errno));
return true;
}
@ -137,10 +137,10 @@ IpcUnixSocketClient::~IpcUnixSocketClient()
bool IpcUnixSocketClient::Connect(const std::string &pathname)
{
CHECK_TRUE(sockFd_ != -1, false, "Unix Socket has connected");
CHECK_TRUE(sockFd_ == -1, false, "Unix Socket has connected");
sockFd_ = socket(AF_UNIX, SOCK_STREAM, 0);
CHECK_TRUE(sockFd_ == -1, false, "create Unix Socket Server failed, %d: %s", errno, strerror(errno));
CHECK_TRUE(sockFd_ != -1, false, "create Unix Socket Server failed, %d: %s", errno, strerror(errno));
struct sockaddr_un addr = {0};
addr.sun_family = AF_UNIX;
@ -164,7 +164,7 @@ void IpcUnixSocketClient::Disconnect()
bool IpcUnixSocketClient::SendMessage(const void *buf, size_t size)
{
CHECK_TRUE(sockFd_ == -1, false, "Unix Socket disconnected");
CHECK_TRUE(sockFd_ != -1, false, "Unix Socket disconnected");
if (send(sockFd_, buf, size, 0) != -1) {
return true;
@ -175,7 +175,7 @@ bool IpcUnixSocketClient::SendMessage(const void *buf, size_t size)
bool IpcUnixSocketClient::RecvMessage(void *buf, size_t &size, uint32_t timeout)
{
CHECK_TRUE(sockFd_ == -1, false, "Unix Socket disconnected");
CHECK_TRUE(sockFd_ != -1, false, "Unix Socket disconnected");
struct pollfd pollFd {sockFd_, POLLIN | POLLERR | POLLHUP, 0};
int polled = poll(&pollFd, 1, timeout);