From 40babf07099c226fa423b58f79e63030230ee983 Mon Sep 17 00:00:00 2001 From: Spencer Low Date: Sun, 2 Sep 2018 19:19:39 -0700 Subject: [PATCH] adb: win32: fix ReportServerStartupFailure The code was passing an fd from adb_open() to android::base::ReadFdToString() which actually takes a C-Runtime fd (on Windows), so it wasn't working. The fix is to use APIs that deal with C-Runtime fds: * unix_open() * android::base::unique_fd * unix_lseek() (added in this change) I also removed an unnecessary call to GetProcessId() since we already have the process id from the structure returned by CreateProcess(). Test: adb start-server on Win10 and Ubuntu (with a failing server) Test: mma Change-Id: Id6e2dd5532a02fe5d9caf96aa007a1b3434a0b59 Signed-off-by: Spencer Low --- adb/adb.cpp | 6 +++--- adb/sysdeps.h | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/adb/adb.cpp b/adb/adb.cpp index 791899e59..62e8908c0 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -633,11 +633,11 @@ static void ReportServerStartupFailure(pid_t pid) { fprintf(stderr, "Full server startup log: %s\n", GetLogFilePath().c_str()); fprintf(stderr, "Server had pid: %d\n", pid); - unique_fd fd(adb_open(GetLogFilePath().c_str(), O_RDONLY)); + android::base::unique_fd fd(unix_open(GetLogFilePath().c_str(), O_RDONLY)); if (fd == -1) return; // Let's not show more than 128KiB of log... - adb_lseek(fd, -128 * 1024, SEEK_END); + unix_lseek(fd, -128 * 1024, SEEK_END); std::string content; if (!android::base::ReadFdToString(fd, &content)) return; @@ -827,7 +827,7 @@ int launch_server(const std::string& socket_spec) { memcmp(temp, expected, expected_length) == 0) { got_ack = true; } else { - ReportServerStartupFailure(GetProcessId(process_handle.get())); + ReportServerStartupFailure(pinfo.dwProcessId); return -1; } } else { diff --git a/adb/sysdeps.h b/adb/sysdeps.h index 0c2e45cb4..bc1899423 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -129,6 +129,13 @@ static __inline__ int unix_write(int fd, const void* buf, size_t len) #undef write #define write ___xxx_write +// See the comments for the !defined(_WIN32) version of unix_lseek(). +static __inline__ int unix_lseek(int fd, int pos, int where) { + return lseek(fd, pos, where); +} +#undef lseek +#define lseek ___xxx_lseek + // See the comments for the !defined(_WIN32) version of adb_open_mode(). static __inline__ int adb_open_mode(const char* path, int options, int mode) { @@ -523,6 +530,7 @@ inline int adb_socket_get_local_port(int fd) { // via _setmode()). #define unix_read adb_read #define unix_write adb_write +#define unix_lseek adb_lseek #define unix_close adb_close static __inline__ int adb_thread_setname(const std::string& name) {