summaryrefslogtreecommitdiffstats
path: root/adb/commandline.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-05-07 23:37:40 -0700
committerElliott Hughes <enh@google.com>2015-05-08 10:49:31 -0700
commit207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6 (patch)
treed5e5a6e057e8d93a4b5c5d38dd3b71ec0917a984 /adb/commandline.cpp
parentc33e62bdc63ddaf7a17c5f317e73349bf3df2b83 (diff)
downloadsystem_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.tar.gz
system_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.tar.bz2
system_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.zip
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)
Diffstat (limited to 'adb/commandline.cpp')
-rw-r--r--adb/commandline.cpp37
1 files changed, 15 insertions, 22 deletions
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);
}