From 492ad5d742ae10aa85b7a32849eab02701ea7afd Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Wed, 12 Feb 2025 12:00:59 +0800 Subject: [PATCH] print epoll_ctl error info when fd not found Issue: https://gitee.com/openharmony/commonlibrary_c_utils/issues/IBLQY7?from=project-issue Signed-off-by: chenkeyu --- base/src/event_demultiplexer.cpp | 10 +++++++--- base/src/event_demultiplexer.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/base/src/event_demultiplexer.cpp b/base/src/event_demultiplexer.cpp index d35b811..ec656f1 100644 --- a/base/src/event_demultiplexer.cpp +++ b/base/src/event_demultiplexer.cpp @@ -33,7 +33,8 @@ static const int EPOLL_ERROR_BADF = 9; static const int EPOLL_ERROR_EINVAL = 22; EventDemultiplexer::EventDemultiplexer() - : epollFd_(epoll_create1(EPOLL_CLOEXEC)), maxEvents_(EPOLL_MAX_EVENS_INIT), mutex_(), eventHandlers_() + : epollFd_(epoll_create1(EPOLL_CLOEXEC)), maxEvents_(EPOLL_MAX_EVENS_INIT), mutex_(), eventHandlers_(), + epollCtlErrInfo_(0, 0, 0) { } @@ -93,8 +94,9 @@ uint32_t EventDemultiplexer::Update(int operation, EventHandler* handler) event.data.fd = handler->GetHandle(); if (epoll_ctl(epollFd_, operation, handler->GetHandle(), &event) != 0) { - UTILS_LOGD("epoll_ctl %{public}d operation %{public}d on handle %{public}d failed", + UTILS_LOGE("epoll_ctl %{public}d operation %{public}d on handle %{public}d failed", epollFd_, operation, handler->GetHandle()); + epollCtlErrInfo_ = std::make_tuple(operation, errno, handler->GetHandle()); return TIMER_ERR_DEAL_FAILED; } return TIMER_ERR_OK; @@ -133,7 +135,9 @@ int EventDemultiplexer::Polling(int timeout /* ms */) taskQue.emplace_back(itor->second); eventQue.emplace_back(events); } else { - UTILS_LOGE("fd not found in eventHandlers_, fd=%{public}d, events=%{public}d", targetFd, events); + auto [operation, errnoNum, fd] = epollCtlErrInfo_; + UTILS_LOGE("fd not found, fd: %{public}d, events: %{public}d, epoll_ctl: %{public}d, %{public}d," + "%{public}d", targetFd, events, operation, errnoNum, fd); } } } diff --git a/base/src/event_demultiplexer.h b/base/src/event_demultiplexer.h index 75a3d7b..bc54d13 100644 --- a/base/src/event_demultiplexer.h +++ b/base/src/event_demultiplexer.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace OHOS { namespace Utils { @@ -49,6 +50,7 @@ private: int maxEvents_; std::recursive_mutex mutex_; std::map> eventHandlers_; // guard by mutex_ + std::tuple epollCtlErrInfo_; }; } -- Gitee