From a6d56611404f2e1c0c9f4ab7c8471af0e80b2026 Mon Sep 17 00:00:00 2001
From: David Pursell <dpursell@google.com>
Date: Mon, 6 Jun 2016 09:37:16 -0700
Subject: [PATCH] adbd: properly close subprocess pipes on Ctrl+C.

When non-interactive sessions exit via Ctrl+C, adbd sends SIGHUP
to the child process to let it know to exit. However, adbd was not
closing the pipes to the child process, so if the subprocess ignored
SIGHUP and continued writing it could fill up the pipe and block
forever while adbd waits for it to exit.

This CL adds the necessary calls to close the subprocess pipe after
sending SIGHUP.

Bug: 28981563
Change-Id: I318e322e563241052648361172f4859c297837fb
(cherry picked from commit f2aa186c7b0792ef4d3e106e2a03be5c3c215118)
---
 adb/shell_service.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index ce107084cb..f58af9f49a 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -479,6 +479,12 @@ void Subprocess::PassDataStreams() {
                 // and only fall back on this for unexpected closures.
                 D("protocol FD died, sending SIGHUP to pid %d", pid_);
                 kill(pid_, SIGHUP);
+
+                // We also need to close the pipes connected to the child process
+                // so that if it ignores SIGHUP and continues to write data it
+                // won't fill up the pipe and block.
+                stdinout_sfd_.Reset();
+                stderr_sfd_.Reset();
             }
             dead_sfd->Reset();
         }
-- 
GitLab