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

Commit a0854670 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: RpcServer privatize acceptOne

This doesn't configure RpcServer w/ a way to be shutdown, and we don't
really need it, so simplifying things.

Bug: 185167543
Test: N/A
Change-Id: I7648ff04f6096f215a90caf3b9f21060eca882ac
parent 4ec3c43c
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ void RpcServer::join() {
    }

    while (mShutdownTrigger->triggerablePollRead(mServer)) {
        (void)acceptOneNoCheck();
        (void)acceptOne();
    }

    {
@@ -150,12 +150,6 @@ void RpcServer::join() {
}

bool RpcServer::acceptOne() {
    LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
    LOG_ALWAYS_FATAL_IF(!hasServer(), "RpcServer must be setup to acceptOne.");
    return acceptOneNoCheck();
}

bool RpcServer::acceptOneNoCheck() {
    unique_fd clientFd(
            TEMP_FAILURE_RETRY(accept4(mServer.get(), nullptr, nullptr /*length*/, SOCK_CLOEXEC)));

+1 −7
Original line number Diff line number Diff line
@@ -134,12 +134,6 @@ public:
     */
    [[nodiscard]] bool shutdown();

    /**
     * Accept one connection on this server. You must have at least one client
     * session before calling this.
     */
    [[nodiscard]] bool acceptOne();

    /**
     * For debugging!
     */
@@ -158,7 +152,7 @@ private:

    void establishConnection(sp<RpcServer>&& session, base::unique_fd clientFd);
    bool setupSocketServer(const RpcSocketAddress& address);
    [[nodiscard]] bool acceptOneNoCheck();
    [[nodiscard]] bool acceptOne();

    bool mAgreedExperimental = false;
    size_t mMaxThreads = 1;
+7 −3
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
    server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
    CHECK(server->setupUnixDomainServer(kSock.c_str()));

    std::thread serverThread([=] { (void)server->acceptOne(); });
    std::thread serverThread([=] { (void)server->join(); });

    sockaddr_un addr{
            .sun_family = AF_UNIX,
@@ -76,8 +76,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
                     connect(clientFd.get(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr))))
            << strerror(errno);

    serverThread.join();

    // TODO(b/182938024): fuzz multiple sessions, instead of just one

#if 0
@@ -90,6 +88,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

    clientFd.reset();

    // TODO(185167543): currently this is okay because we only shutdown the one
    // thread, but once we can shutdown other sessions, we'll need to change
    // this behavior in order to make sure all of the input is actually read.
    while (!server->shutdown()) usleep(100);
    serverThread.join();

    // TODO(b/185167543): better way to force a server to shutdown
    while (!server->listSessions().empty() && server->numUninitializedSessions()) {
        usleep(1);