From 207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 7 May 2015 23:37:40 -0700 Subject: Fix "adb remount" for devices without an oem partition. On a device without an oem partition, we now have an /oem directory anyway. This causes find_mount to fail, and that was returning nullptr from a std::string-returning function. Boom! Also clean up the bits of code I had to trace through between "adb remount" on the host to the crash on the device as I debugged this. The only other meaningful change is the error checking in adb_connect_command --- adb_connect can also return -2. Bug: http://b/20916855 Change-Id: I4c3b7858e13f3a3a8bbc7d30b3c0ee470bead587 (cherry picked from commit 5677c23e8d0c085be8d8429a5d125147d11e9bb2) --- adb/commandline.cpp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'adb/commandline.cpp') diff --git a/adb/commandline.cpp b/adb/commandline.cpp index af05dc0a9..cef5f39ce 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -263,23 +263,16 @@ static void stdin_raw_restore(int fd) { } #endif -static void read_and_dump(int fd) -{ - char buf[4096]; - int len; - - while(fd >= 0) { +static void read_and_dump(int fd) { + while (fd >= 0) { D("read_and_dump(): pre adb_read(fd=%d)\n", fd); - len = adb_read(fd, buf, 4096); + char buf[BUFSIZ]; + int len = adb_read(fd, buf, sizeof(buf)); D("read_and_dump(): post adb_read(fd=%d): len=%d\n", fd, len); - if(len == 0) { + if (len <= 0) { break; } - if(len < 0) { - if(errno == EINTR) continue; - break; - } fwrite(buf, 1, len, stdout); fflush(stdout); } @@ -928,13 +921,13 @@ static void parse_push_pull_args(const char **arg, int narg, char const **path1, static int adb_connect_command(const std::string& command) { std::string error; int fd = adb_connect(command, &error); - if (fd != -1) { - read_and_dump(fd); - adb_close(fd); - return 0; + if (fd < 0) { + fprintf(stderr, "error: %s\n", error.c_str()); + return 1; } - fprintf(stderr, "Error: %s\n", error.c_str()); - return 1; + read_and_dump(fd); + adb_close(fd); + return 0; } static int adb_query_command(const std::string& command) { @@ -1253,13 +1246,13 @@ int adb_commandline(int argc, const char **argv) { !strcmp(argv[0], "unroot") || !strcmp(argv[0], "disable-verity") || !strcmp(argv[0], "enable-verity")) { - char command[100]; + std::string command; if (!strcmp(argv[0], "reboot-bootloader")) { - snprintf(command, sizeof(command), "reboot:bootloader"); + command = "reboot:bootloader"; } else if (argc > 1) { - snprintf(command, sizeof(command), "%s:%s", argv[0], argv[1]); + command = android::base::StringPrintf("%s:%s", argv[0], argv[1]); } else { - snprintf(command, sizeof(command), "%s:", argv[0]); + command = android::base::StringPrintf("%s:", argv[0]); } return adb_connect_command(command); } -- cgit v1.2.3