summaryrefslogtreecommitdiff
path: root/libs/binder/RpcServer.cpp
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-06-28 15:57:06 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-06-28 15:57:06 +0000
commitaa30575a7cfd7a89a81da16186b13cfe10e53a73 (patch)
tree86f70a60e2112012732293d7de689e5539b41477 /libs/binder/RpcServer.cpp
parentf020253e3efa9dfd390d80e28301f06152008db3 (diff)
parent022db680633b483ec5fab4f6b0722981482b3a02 (diff)
Merge "RpcServer: let system allocate vsock ports" into main
Diffstat (limited to 'libs/binder/RpcServer.cpp')
-rw-r--r--libs/binder/RpcServer.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index d9e926a9d5..b8742af1f9 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -71,8 +71,23 @@ status_t RpcServer::setupUnixDomainServer(const char* path) {
return setupSocketServer(UnixSocketAddress(path));
}
-status_t RpcServer::setupVsockServer(unsigned int bindCid, unsigned int port) {
- return setupSocketServer(VsockSocketAddress(bindCid, port));
+status_t RpcServer::setupVsockServer(unsigned bindCid, unsigned port, unsigned* assignedPort) {
+ auto status = setupSocketServer(VsockSocketAddress(bindCid, port));
+ if (status != OK) return status;
+
+ if (assignedPort == nullptr) return OK;
+ sockaddr_vm addr;
+ socklen_t len = sizeof(addr);
+ if (0 != getsockname(mServer.fd.get(), reinterpret_cast<sockaddr*>(&addr), &len)) {
+ status = -errno;
+ ALOGE("setupVsockServer: Failed to getsockname: %s", strerror(-status));
+ return status;
+ }
+
+ LOG_ALWAYS_FATAL_IF(len != sizeof(addr), "Wrong socket type: len %zu vs len %zu",
+ static_cast<size_t>(len), sizeof(addr));
+ *assignedPort = addr.svm_port;
+ return OK;
}
status_t RpcServer::setupInetServer(const char* address, unsigned int port,