From 8ac1b044afd879ff6e0bb969d6c25c89b1869ea8 Mon Sep 17 00:00:00 2001 From: bohu Date: Mon, 29 Feb 2016 13:13:19 -0800 Subject: [PATCH] Emulator: fix adbd qemu pipe partial write It does happens that the adb_write only writes to the qemu pipe partially which throws host side's adb backend into confusion and crashes. This CL replaces adb_write with WriteFdExactly; adb_read with ReadFdExactly. (cherry picked from commit f66c5938be56c6fe607725c80129e677e196f03a) Change-Id: I684f5df79b1e3f00b4b7a2452c2712a73c15973c --- adb/transport_local.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp index e6e699b6d..372bedf7c 100644 --- a/adb/transport_local.cpp +++ b/adb/transport_local.cpp @@ -225,7 +225,7 @@ static void qemu_socket_thread(void* arg) { static const char _ok_resp[] = "ok"; const int port = (int) (uintptr_t) arg; - int res, fd; + int fd; char tmp[256]; char con_name[32]; @@ -251,19 +251,19 @@ static void qemu_socket_thread(void* arg) { */ /* Send the 'accept' request. */ - res = adb_write(fd, _accept_req, strlen(_accept_req)); - if ((size_t)res == strlen(_accept_req)) { + if (WriteFdExactly(fd, _accept_req, strlen(_accept_req))) { /* Wait for the response. In the response we expect 'ok' on success, * or 'ko' on failure. */ - res = adb_read(fd, tmp, sizeof(tmp)); - if (res != 2 || memcmp(tmp, _ok_resp, 2)) { + if (!ReadFdExactly(fd, tmp, 2) || memcmp(tmp, _ok_resp, 2)) { D("Accepting ADB host connection has failed."); adb_close(fd); } else { /* Host is connected. Register the transport, and start the * exchange. */ register_socket_transport(fd, "host", port, 1); - adb_write(fd, _start_req, strlen(_start_req)); + if (!WriteFdExactly(fd, _start_req, strlen(_start_req))) { + adb_close(fd); + } } /* Prepare for accepting of the next ADB host connection. */