summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2020-05-20 21:01:23 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-05-20 21:01:23 +0000
commitb27365510d89ebfebb4f1b7b24cc29aaa6db7a0a (patch)
tree780ca4d063507beb7e84541f22d329f07ccb65e2
parentfc4e54ecb03c6367b3a23df373f42c39fc789b6a (diff)
parentbe41ae566617bc6e063011b1216a0aaa3e9ca80d (diff)
downloadcore-b27365510d89ebfebb4f1b7b24cc29aaa6db7a0a.tar.gz
Merge "adb: fix flakiness in PTY shell protocol."
-rw-r--r--adb/daemon/shell_service.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/adb/daemon/shell_service.cpp b/adb/daemon/shell_service.cpp
index fbfae1e44..dbca4adb6 100644
--- a/adb/daemon/shell_service.cpp
+++ b/adb/daemon/shell_service.cpp
@@ -646,15 +646,21 @@ unique_fd* Subprocess::PollLoop(SubprocessPollfds* pfds) {
}
// After handling all of the events we've received, check to see if any fds have died.
- if (stdinout_pfd.revents & (POLLHUP | POLLRDHUP | POLLERR | POLLNVAL)) {
+ auto poll_finished = [](int events) {
+ // Don't return failure until we've read out all of the fd's incoming data.
+ return (events & POLLIN) == 0 &&
+ (events & (POLLHUP | POLLRDHUP | POLLERR | POLLNVAL)) != 0;
+ };
+
+ if (poll_finished(stdinout_pfd.revents)) {
return &stdinout_sfd_;
}
- if (stderr_pfd.revents & (POLLHUP | POLLRDHUP | POLLERR | POLLNVAL)) {
+ if (poll_finished(stderr_pfd.revents)) {
return &stderr_sfd_;
}
- if (protocol_pfd.revents & (POLLHUP | POLLRDHUP | POLLERR | POLLNVAL)) {
+ if (poll_finished(protocol_pfd.revents)) {
return &protocol_sfd_;
}
} // while (!dead_sfd)