summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2016-06-08 11:11:01 -0700
committerFelipe Leme <felipeal@google.com>2016-06-08 13:00:14 -0700
commit1634d841af26421a76ef4c723095786da6d350a4 (patch)
tree150a4f829fa933120c3025782c3a8e0e99358fd0
parent0950fb3d20d100f62961db1cc3eff51b51f9ca6b (diff)
downloadnative-1634d841af26421a76ef4c723095786da6d350a4.tar.gz
Improved error handling.
adb bugreport now properly handles stderr. BUG: 29161586 Change-Id: I7a59d1feadda3d160eae6fe447a7a3c7e0843cbb
-rw-r--r--cmds/bugreportz/bugreportz.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/cmds/bugreportz/bugreportz.cpp b/cmds/bugreportz/bugreportz.cpp
index 19d2d64310..312dcebe0d 100644
--- a/cmds/bugreportz/bugreportz.cpp
+++ b/cmds/bugreportz/bugreportz.cpp
@@ -80,8 +80,8 @@ int main(int argc, char *argv[]) {
}
if (s == -1) {
- printf("Failed to connect to dumpstatez service: %s\n", strerror(errno));
- return EXIT_FAILURE;
+ printf("FAIL:Failed to connect to dumpstatez service: %s\n", strerror(errno));
+ return EXIT_SUCCESS;
}
// Set a timeout so that if nothing is read in 10 minutes, we'll stop
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
tv.tv_sec = 10 * 60;
tv.tv_usec = 0;
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
- printf("WARNING: Cannot set socket timeout: %s\n", strerror(errno));
+ fprintf(stderr, "WARNING: Cannot set socket timeout: %s\n", strerror(errno));
}
while (1) {
@@ -105,8 +105,7 @@ int main(int argc, char *argv[]) {
if (errno == EAGAIN) {
errno = ETIMEDOUT;
}
- printf("\nBugreport read terminated abnormally (%s).\n",
- strerror(errno));
+ printf("FAIL:Bugreport read terminated abnormally (%s)\n", strerror(errno));
break;
}
@@ -117,15 +116,17 @@ int main(int argc, char *argv[]) {
write(STDOUT_FILENO, buffer + bytes_read - bytes_to_send,
bytes_to_send));
if (bytes_written == -1) {
- printf(
+ fprintf(stderr,
"Failed to write data to stdout: read %zd, trying to send %zd (%s)\n",
bytes_read, bytes_to_send, strerror(errno));
- return EXIT_FAILURE;
+ break;
}
bytes_to_send -= bytes_written;
} while (bytes_written != 0 && bytes_to_send > 0);
}
- close(s);
+ if (close(s) == -1) {
+ fprintf(stderr, "WARNING: error closing socket: %s\n", strerror(errno));
+ }
return EXIT_SUCCESS;
}