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

Commit 436f0e6d authored by Yifan Hong's avatar Yifan Hong
Browse files

~RpcServer() calls shutdown explicitly.

If a thread is calling RpcServer::join() and poll()-ing,
when ~RpcServer() is called, the first thing it does
is deleting mJoinShutdownTrigger, which will close the
read end first.

poll(2):
  For a discussion of what may happen if a file descriptor being
  monitored by poll() is closed in another thread, see select(2).

select(2):
  If a file descriptor being monitored by select() is closed in
  another thread, the result is unspecified.

To avoid relying on UB, properly shut down before closing these fds.

Test: binderRpcTest
Test: binderLibTest

Bug: 182914638

Change-Id: Id689fa31e6cbf055f6c60a443e8f4ad0dae7ceb1
parent fc907867
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -39,7 +39,9 @@ using base::ScopeGuard;
using base::unique_fd;
using base::unique_fd;


RpcServer::RpcServer() {}
RpcServer::RpcServer() {}
RpcServer::~RpcServer() {}
RpcServer::~RpcServer() {
    (void)shutdown();
}


sp<RpcServer> RpcServer::make() {
sp<RpcServer> RpcServer::make() {
    return sp<RpcServer>::make();
    return sp<RpcServer>::make();
@@ -204,7 +206,6 @@ bool RpcServer::acceptOneNoCheck() {
}
}


bool RpcServer::shutdown() {
bool RpcServer::shutdown() {
    LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
    std::unique_lock<std::mutex> _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    if (mShutdownTrigger == nullptr) return false;
    if (mShutdownTrigger == nullptr) return false;