libbinder: server sessions shut down independently

Before this CL, for a server, there is a single pipe which when hungup
will end every session with that server. This, as it turned out in
hindsight to be problematic, since we want to shutdown problematic
sessions without interrupting other clients.

Assuming we keep the pipe-based interrupt, there are essential two
solutions to consider here (this CL is option B).
a. instead of hanging up these pipes, write information to them, and
   then wake up all relevant threads which can figure out the right
   thing to do.
   - pro: only need to create one FD
   - con: very complicated because there may be multiple readers of the
          pipe, etc...
   - con: will mess with all clients
b. have a separate pipe per session
   - pro: relatively simple logic
   - con: an extra FD per session

So, for now, going with (b).

Bug: 183140903
Test: binderRpcTest, run biner_rpc_fuzzer for 5 minutes
    (I checked locally, w/o the RpcServer check for isTriggered, this
    also detected that deadlock in less than 1 minute! :D)
Change-Id: I9e290cd0a6df1d33435183fb16f508f38071ad62
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index c563377..93e04f7 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -144,7 +144,10 @@
 
 std::unique_ptr<RpcSession::FdTrigger> RpcSession::FdTrigger::make() {
     auto ret = std::make_unique<RpcSession::FdTrigger>();
-    if (!android::base::Pipe(&ret->mRead, &ret->mWrite)) return nullptr;
+    if (!android::base::Pipe(&ret->mRead, &ret->mWrite)) {
+        ALOGE("Could not create pipe %s", strerror(errno));
+        return nullptr;
+    }
     return ret;
 }
 
@@ -152,6 +155,10 @@
     mWrite.reset();
 }
 
+bool RpcSession::FdTrigger::isTriggered() {
+    return mWrite == -1;
+}
+
 status_t RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) {
     while (true) {
         pollfd pfd[]{{.fd = fd.get(), .events = POLLIN | POLLHUP, .revents = 0},
@@ -408,20 +415,21 @@
     return true;
 }
 
-void RpcSession::setForServer(const wp<RpcServer>& server, const wp<EventListener>& eventListener,
-                              int32_t sessionId,
-                              const std::shared_ptr<FdTrigger>& shutdownTrigger) {
+bool RpcSession::setForServer(const wp<RpcServer>& server, const wp<EventListener>& eventListener,
+                              int32_t sessionId) {
     LOG_ALWAYS_FATAL_IF(mForServer != nullptr);
     LOG_ALWAYS_FATAL_IF(server == nullptr);
     LOG_ALWAYS_FATAL_IF(mEventListener != nullptr);
     LOG_ALWAYS_FATAL_IF(eventListener == nullptr);
     LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr);
-    LOG_ALWAYS_FATAL_IF(shutdownTrigger == nullptr);
+
+    mShutdownTrigger = FdTrigger::make();
+    if (mShutdownTrigger == nullptr) return false;
 
     mId = sessionId;
     mForServer = server;
     mEventListener = eventListener;
-    mShutdownTrigger = shutdownTrigger;
+    return true;
 }
 
 sp<RpcSession::RpcConnection> RpcSession::assignServerToThisThread(unique_fd fd) {