adb: make `adb kill-server` wait for the server to die.
Make the host:kill service shutdown its socket on process exit, instead
of immediately. Also, unify the two 'kill-server' implementations and
hide _adb_connect.
Bug: http://b/37104408
Test: adb kill-server; adb start-server
Change-Id: I9475f5d084d5fb91d33e393f2fd4e34056613384
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index a9b1540..f49c69d 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -1546,25 +1546,7 @@
return 0;
}
else if (!strcmp(argv[0], "kill-server")) {
- std::string error;
- int fd = _adb_connect("host:kill", &error);
- if (fd == -2) {
- // Failed to make network connection to server. Don't output the
- // network error since that is expected.
- fprintf(stderr,"* server not running *\n");
- // Successful exit code because the server is already "killed".
- return 0;
- } else if (fd == -1) {
- // Some other error.
- fprintf(stderr, "error: %s\n", error.c_str());
- return 1;
- } else {
- // Successfully connected, kill command sent, okay status came back.
- // Server should exit() in a moment, if not already.
- ReadOrderlyShutdown(fd);
- adb_close(fd);
- return 0;
- }
+ return adb_kill_server() ? 0 : 1;
}
else if (!strcmp(argv[0], "sideload")) {
if (argc != 2) return syntax_error("sideload requires an argument");