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
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 27ab7b4..211cb46 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -263,23 +263,16 @@
}
#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 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) {
@@ -1242,13 +1235,13 @@
!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);
}