Merge "init: Add diagnostics for signalfd epoll failures."

This commit is contained in:
David Anderson 2022-03-08 08:02:39 +00:00 committed by Gerrit Code Review
commit 5c007a51dd
4 changed files with 27 additions and 7 deletions

View File

@ -23,6 +23,8 @@
#include <functional>
#include <map>
#include <android-base/logging.h>
namespace android {
namespace init {
@ -42,8 +44,11 @@ Result<void> Epoll::RegisterHandler(int fd, Handler handler, uint32_t events) {
if (!events) {
return Error() << "Must specify events";
}
auto sp = std::make_shared<decltype(handler)>(std::move(handler));
auto [it, inserted] = epoll_handlers_.emplace(fd, std::move(sp));
Info info;
info.events = events;
info.handler = std::make_shared<decltype(handler)>(std::move(handler));
auto [it, inserted] = epoll_handlers_.emplace(fd, std::move(info));
if (!inserted) {
return Error() << "Cannot specify two epoll handlers for a given FD";
}
@ -84,8 +89,14 @@ Result<std::vector<std::shared_ptr<Epoll::Handler>>> Epoll::Wait(
}
std::vector<std::shared_ptr<Handler>> pending_functions;
for (int i = 0; i < num_events; ++i) {
auto sp = *reinterpret_cast<std::shared_ptr<Handler>*>(ev[i].data.ptr);
pending_functions.emplace_back(std::move(sp));
auto& info = *reinterpret_cast<Info*>(ev[i].data.ptr);
if ((info.events & (EPOLLIN | EPOLLPRI)) == (EPOLLIN | EPOLLPRI) &&
(ev[i].events & EPOLLIN) != ev[i].events) {
// This handler wants to know about exception events, and just got one.
// Log something informational.
LOG(ERROR) << "Received unexpected epoll event set: " << ev[i].events;
}
pending_functions.emplace_back(info.handler);
}
return pending_functions;

View File

@ -46,8 +46,13 @@ class Epoll {
std::optional<std::chrono::milliseconds> timeout);
private:
struct Info {
std::shared_ptr<Handler> handler;
uint32_t events;
};
android::base::unique_fd epoll_fd_;
std::map<int, std::shared_ptr<Handler>> epoll_handlers_;
std::map<int, Info> epoll_handlers_;
};
} // namespace init

View File

@ -646,7 +646,8 @@ static void InstallSignalFdHandler(Epoll* epoll) {
PLOG(FATAL) << "failed to create signalfd";
}
if (auto result = epoll->RegisterHandler(signal_fd, HandleSignalFd); !result.ok()) {
constexpr int flags = EPOLLIN | EPOLLPRI;
if (auto result = epoll->RegisterHandler(signal_fd, HandleSignalFd, flags); !result.ok()) {
LOG(FATAL) << result.error();
}
}

View File

@ -95,7 +95,10 @@ static pid_t ReapOneProcess() {
LOG(INFO) << name << " received signal " << siginfo.si_status << wait_string;
}
if (!service) return pid;
if (!service) {
LOG(INFO) << name << " did not have an associated service entry and will not be reaped";
return pid;
}
service->Reap(siginfo);