Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit feb5bd6f authored by David Anderson's avatar David Anderson Committed by Automerger Merge Worker
Browse files

Merge "init: Add diagnostics for signalfd epoll failures." am: 5c007a51 am: a0cc2ee6

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2012248

Change-Id: Ib5bc3a6b60c96ce1303eafbf4b221c64a303ce69
parents 5ba7e76a a0cc2ee6
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -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;
+6 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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();
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -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);