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

Commit 3b80d081 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge changes I9b5b2876,I3b93e0a9 am: 94a9ae33 am: fc87fc21 am: 9c176932 am: 8155b0de

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1697653

Change-Id: I89d8871bec419ee4883bf15622c9d8a9a799365a
parents 9a40d1df 8155b0de
Loading
Loading
Loading
Loading
+0 −4
Original line number Original line Diff line number Diff line
@@ -49,8 +49,6 @@ bool RpcServer::setupUnixDomainServer(const char* path) {
    return setupSocketServer(UnixSocketAddress(path));
    return setupSocketServer(UnixSocketAddress(path));
}
}


#ifdef __BIONIC__

bool RpcServer::setupVsockServer(unsigned int port) {
bool RpcServer::setupVsockServer(unsigned int port) {
    // realizing value w/ this type at compile time to avoid ubsan abort
    // realizing value w/ this type at compile time to avoid ubsan abort
    constexpr unsigned int kAnyCid = VMADDR_CID_ANY;
    constexpr unsigned int kAnyCid = VMADDR_CID_ANY;
@@ -58,8 +56,6 @@ bool RpcServer::setupVsockServer(unsigned int port) {
    return setupSocketServer(VsockSocketAddress(kAnyCid, port));
    return setupSocketServer(VsockSocketAddress(kAnyCid, port));
}
}


#endif // __BIONIC__

bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
    const char* kAddr = "127.0.0.1";
    const char* kAddr = "127.0.0.1";


+36 −30
Original line number Original line Diff line number Diff line
@@ -61,14 +61,10 @@ bool RpcSession::setupUnixDomainClient(const char* path) {
    return setupSocketClient(UnixSocketAddress(path));
    return setupSocketClient(UnixSocketAddress(path));
}
}


#ifdef __BIONIC__

bool RpcSession::setupVsockClient(unsigned int cid, unsigned int port) {
bool RpcSession::setupVsockClient(unsigned int cid, unsigned int port) {
    return setupSocketClient(VsockSocketAddress(cid, port));
    return setupSocketClient(VsockSocketAddress(cid, port));
}
}


#endif // __BIONIC__

bool RpcSession::setupInetClient(const char* addr, unsigned int port) {
bool RpcSession::setupInetClient(const char* addr, unsigned int port) {
    auto aiStart = InetSocketAddress::getAddrInfo(addr, port);
    auto aiStart = InetSocketAddress::getAddrInfo(addr, port);
    if (aiStart == nullptr) return false;
    if (aiStart == nullptr) return false;
@@ -219,28 +215,34 @@ bool RpcSession::setupSocketClient(const RpcSocketAddress& addr) {


    // we've already setup one client
    // we've already setup one client
    for (size_t i = 0; i + 1 < numThreadsAvailable; i++) {
    for (size_t i = 0; i + 1 < numThreadsAvailable; i++) {
        // TODO(b/185167543): avoid race w/ accept4 not being called on server
        // TODO(b/185167543): shutdown existing connections?
        for (size_t tries = 0; tries < 5; tries++) {
        if (!setupOneSocketClient(addr, mId.value())) return false;
            if (setupOneSocketClient(addr, mId.value())) break;
            usleep(10000);
        }
    }
    }


    return true;
    return true;
}
}


bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id) {
bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id) {
    for (size_t tries = 0; tries < 5; tries++) {
        if (tries > 0) usleep(10000);

        unique_fd serverFd(
        unique_fd serverFd(
                TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
                TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
        if (serverFd == -1) {
        if (serverFd == -1) {
            int savedErrno = errno;
            int savedErrno = errno;
        ALOGE("Could not create socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
            ALOGE("Could not create socket at %s: %s", addr.toString().c_str(),
                  strerror(savedErrno));
            return false;
            return false;
        }
        }


        if (0 != TEMP_FAILURE_RETRY(connect(serverFd.get(), addr.addr(), addr.addrSize()))) {
        if (0 != TEMP_FAILURE_RETRY(connect(serverFd.get(), addr.addr(), addr.addrSize()))) {
            if (errno == ECONNRESET) {
                ALOGW("Connection reset on %s", addr.toString().c_str());
                continue;
            }
            int savedErrno = errno;
            int savedErrno = errno;
        ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
            ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(),
                  strerror(savedErrno));
            return false;
            return false;
        }
        }


@@ -257,6 +259,10 @@ bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id)
        return true;
        return true;
    }
    }


    ALOGE("Ran out of retries to connect to %s", addr.toString().c_str());
    return false;
}

void RpcSession::addClient(unique_fd fd) {
void RpcSession::addClient(unique_fd fd) {
    std::lock_guard<std::mutex> _l(mMutex);
    std::lock_guard<std::mutex> _l(mMutex);
    sp<RpcConnection> session = sp<RpcConnection>::make();
    sp<RpcConnection> session = sp<RpcConnection>::make();
+1 −7
Original line number Original line Diff line number Diff line
@@ -24,9 +24,7 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/un.h>


#ifdef __BIONIC__
#include "vm_sockets.h"
#include <linux/vm_sockets.h>
#endif


namespace android {
namespace android {


@@ -59,8 +57,6 @@ private:
    sockaddr_un mAddr;
    sockaddr_un mAddr;
};
};


#ifdef __BIONIC__

class VsockSocketAddress : public RpcSocketAddress {
class VsockSocketAddress : public RpcSocketAddress {
public:
public:
    VsockSocketAddress(unsigned int cid, unsigned int port)
    VsockSocketAddress(unsigned int cid, unsigned int port)
@@ -80,8 +76,6 @@ private:
    sockaddr_vm mAddr;
    sockaddr_vm mAddr;
};
};


#endif // __BIONIC__

class InetSocketAddress : public RpcSocketAddress {
class InetSocketAddress : public RpcSocketAddress {
public:
public:
    InetSocketAddress(const sockaddr* sockAddr, size_t size, const char* addr, unsigned int port)
    InetSocketAddress(const sockaddr* sockAddr, size_t size, const char* addr, unsigned int port)
+0 −2
Original line number Original line Diff line number Diff line
@@ -57,12 +57,10 @@ public:
     */
     */
    [[nodiscard]] bool setupUnixDomainServer(const char* path);
    [[nodiscard]] bool setupUnixDomainServer(const char* path);


#ifdef __BIONIC__
    /**
    /**
     * Creates an RPC server at the current port.
     * Creates an RPC server at the current port.
     */
     */
    [[nodiscard]] bool setupVsockServer(unsigned int port);
    [[nodiscard]] bool setupVsockServer(unsigned int port);
#endif // __BIONIC__


    /**
    /**
     * Creates an RPC server at the current port using IPv4.
     * Creates an RPC server at the current port using IPv4.
+0 −2
Original line number Original line Diff line number Diff line
@@ -52,12 +52,10 @@ public:
     */
     */
    [[nodiscard]] bool setupUnixDomainClient(const char* path);
    [[nodiscard]] bool setupUnixDomainClient(const char* path);


#ifdef __BIONIC__
    /**
    /**
     * Connects to an RPC server at the CVD & port.
     * Connects to an RPC server at the CVD & port.
     */
     */
    [[nodiscard]] bool setupVsockClient(unsigned int cvd, unsigned int port);
    [[nodiscard]] bool setupVsockClient(unsigned int cvd, unsigned int port);
#endif // __BIONIC__


    /**
    /**
     * Connects to an RPC server at the given address and port.
     * Connects to an RPC server at the given address and port.
Loading