diff options
author | Elliott Hughes <enh@google.com> | 2015-04-20 08:09:20 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-04-20 08:09:20 -0700 |
commit | 7b506090e1ac51f4990f17621c6e33847b0632a2 (patch) | |
tree | 2b458ebf507d7afed3e3330afa8dd9709962fde3 /adb/adb.cpp | |
parent | 623aa1c47a51990259fbbc271d7f9f40046153fd (diff) | |
download | system_core-7b506090e1ac51f4990f17621c6e33847b0632a2.zip system_core-7b506090e1ac51f4990f17621c6e33847b0632a2.tar.gz system_core-7b506090e1ac51f4990f17621c6e33847b0632a2.tar.bz2 |
Always explain why bind(2) failed.
This has confused several people lately.
Bug: http://b/20219978
Change-Id: I2537ceb83bff0b3166c230c728d4389a983db858
Diffstat (limited to 'adb/adb.cpp')
-rw-r--r-- | adb/adb.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp index b09e853..de82cd4 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -32,6 +32,8 @@ #include <string> +#include <base/stringprintf.h> + #include "adb_auth.h" #include "adb_io.h" #include "adb_listeners.h" @@ -802,7 +804,6 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri if (!strncmp(service, "forward:",8) || !strncmp(service, "killforward:",12)) { char *local, *remote; - int r; atransport *transport; int createForward = strncmp(service, "kill", 4); @@ -845,12 +846,13 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri return 1; } + install_status_t r; if (createForward) { r = install_listener(local, remote, transport, no_rebind); } else { r = remove_listener(local, transport); } - if(r == 0) { + if (r == INSTALL_STATUS_OK) { #if ADB_HOST /* On the host: 1st OKAY is connect, 2nd OKAY is status */ WriteFdExactly(reply_fd, "OKAY", 4); @@ -859,22 +861,19 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri return 1; } - if (createForward) { - const char* message; - switch (r) { - case INSTALL_STATUS_CANNOT_BIND: - message = "cannot bind to socket"; - break; - case INSTALL_STATUS_CANNOT_REBIND: - message = "cannot rebind existing socket"; - break; - default: - message = "internal error"; - } - sendfailmsg(reply_fd, message); - } else { - sendfailmsg(reply_fd, "cannot remove listener"); + std::string message; + switch (r) { + case INSTALL_STATUS_OK: message = " "; break; + case INSTALL_STATUS_INTERNAL_ERROR: message = "internal error"; break; + case INSTALL_STATUS_CANNOT_BIND: + message = android::base::StringPrintf("cannot bind to socket: %s", strerror(errno)); + break; + case INSTALL_STATUS_CANNOT_REBIND: + message = android::base::StringPrintf("cannot rebind existing socket: %s", strerror(errno)); + break; + case INSTALL_STATUS_LISTENER_NOT_FOUND: message = "listener not found"; break; } + sendfailmsg(reply_fd, message.c_str()); return 1; } return 0; |