adb: Kill subprocess when the client exits.
When the client exits (e.g. with Ctrl+C) the subprocess should be
notified as well so it can cleanup if needed.
Bug: http://b/23825725
Change-Id: Idb771710b293e0a9f7bebc9e2814b3a816e2c50e
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index 0274ae3..f1bc36d 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -413,6 +413,14 @@
D("closing FD %d", dead_sfd->fd());
FD_CLR(dead_sfd->fd(), &master_read_set);
FD_CLR(dead_sfd->fd(), &master_write_set);
+ if (dead_sfd == &protocol_sfd_) {
+ // Using SIGHUP is a decent general way to indicate that the
+ // controlling process is going away. If specific signals are
+ // needed (e.g. SIGINT), pass those through the shell protocol
+ // and only fall back on this for unexpected closures.
+ D("protocol FD died, sending SIGHUP to pid %d", pid_);
+ kill(pid_, SIGHUP);
+ }
dead_sfd->Reset();
}
}