Loading adb/adb.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -611,8 +611,7 @@ static unsigned __stdcall _redirect_stderr_thread(HANDLE h) { #endif int launch_server(int server_port) { int launch_server(const std::string& socket_spec) { #if defined(_WIN32) /* we need to start the server in the background */ /* we create a PIPE that will be used to wait for the server's "OK" */ Loading Loading @@ -715,9 +714,8 @@ int launch_server(int server_port) } WCHAR args[64]; snwprintf(args, arraysize(args), L"adb -P %d fork-server server --reply-fd %d", server_port, ack_write_as_int); snwprintf(args, arraysize(args), L"adb -L %s fork-server server --reply-fd %d", socket_spec.c_str(), ack_write_as_int); PROCESS_INFORMATION pinfo; ZeroMemory(&pinfo, sizeof(pinfo)); Loading Loading @@ -862,12 +860,11 @@ int launch_server(int server_port) adb_close(fd[0]); char str_port[30]; snprintf(str_port, sizeof(str_port), "%d", server_port); char reply_fd[30]; snprintf(reply_fd, sizeof(reply_fd), "%d", fd[1]); // child process int result = execl(path.c_str(), "adb", "-P", str_port, "fork-server", "server", "--reply-fd", reply_fd, NULL); int result = execl(path.c_str(), "adb", "-L", socket_spec.c_str(), "fork-server", "server", "--reply-fd", reply_fd, NULL); // this should not return fprintf(stderr, "OOPS! execl returned %d, errno: %d\n", result, errno); } else { Loading adb/adb.h +2 −2 Original line number Diff line number Diff line Loading @@ -126,8 +126,8 @@ void fatal_errno(const char* fmt, ...) __attribute__((noreturn, format(__printf_ void handle_packet(apacket *p, atransport *t); int launch_server(int server_port); int adb_server_main(int is_daemon, int server_port, int ack_reply_fd); int launch_server(const std::string& socket_spec); int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply_fd); /* initialize a transport object's func pointers and state */ #if ADB_HOST Loading adb/adb_client.cpp +15 −30 Original line number Diff line number Diff line Loading @@ -37,12 +37,12 @@ #include "adb_io.h" #include "adb_utils.h" #include "socket_spec.h" static TransportType __adb_transport = kTransportAny; static const char* __adb_serial = NULL; static int __adb_server_port = DEFAULT_ADB_PORT; static const char* __adb_server_name = NULL; static const char* __adb_server_socket_spec; void adb_set_transport(TransportType type, const char* serial) { Loading @@ -59,14 +59,11 @@ void adb_get_transport(TransportType* type, const char** serial) { } } void adb_set_tcp_specifics(int server_port) { __adb_server_port = server_port; void adb_set_socket_spec(const char* socket_spec) { if (!__adb_server_socket_spec) { LOG(FATAL) << "attempted to reinitialize adb_server_socket_spec"; } void adb_set_tcp_name(const char* hostname) { __adb_server_name = hostname; __adb_server_socket_spec = socket_spec; } static int switch_socket_transport(int fd, std::string* error) { Loading Loading @@ -139,24 +136,13 @@ int _adb_connect(const std::string& service, std::string* error) { return -1; } int fd; std::string reason; if (__adb_server_name) { fd = network_connect(__adb_server_name, __adb_server_port, SOCK_STREAM, 0, &reason); if (fd == -1) { *error = android::base::StringPrintf("can't connect to %s:%d: %s", __adb_server_name, __adb_server_port, reason.c_str()); return -2; } } else { fd = network_loopback_client(__adb_server_port, SOCK_STREAM, &reason); if (fd == -1) { *error = android::base::StringPrintf("cannot connect to daemon: %s", reason.c_str()); int fd = socket_spec_connect(__adb_server_socket_spec, &reason); if (fd < 0) { *error = android::base::StringPrintf("cannot connect to daemon at %s: %s", __adb_server_socket_spec, reason.c_str()); return -2; } } if ((memcmp(&service[0],"host",4) != 0 || service == "host:reconnect") && switch_socket_transport(fd, error)) { Loading Loading @@ -185,15 +171,14 @@ int adb_connect(const std::string& service, std::string* error) { int fd = _adb_connect("host:version", error); D("adb_connect: service %s", service.c_str()); if (fd == -2 && __adb_server_name) { if (fd == -2 && !is_local_socket_spec(__adb_server_socket_spec)) { fprintf(stderr,"** Cannot start server on remote host\n"); // error is the original network connection error return fd; } else if (fd == -2) { fprintf(stdout,"* daemon not running. starting it now on port %d *\n", __adb_server_port); fprintf(stdout, "* daemon not running. starting it now at %s *\n", __adb_server_socket_spec); start_server: if (launch_server(__adb_server_port)) { if (launch_server(__adb_server_socket_spec)) { fprintf(stderr,"* failed to start daemon *\n"); // launch_server() has already printed detailed error info, so just // return a generic error string about the overall adb_connect() Loading adb/adb_client.h +3 −5 Original line number Diff line number Diff line Loading @@ -43,11 +43,9 @@ void adb_set_transport(TransportType type, const char* _Nullable serial); // Get the preferred transport to connect to. void adb_get_transport(TransportType* _Nullable type, const char* _Nullable* _Nullable serial); // Set TCP specifics of the transport to use. void adb_set_tcp_specifics(int server_port); // Set TCP Hostname of the transport to use. void adb_set_tcp_name(const char* _Nullable hostname); // Set the socket specification for the adb server. // This function can only be called once, and the argument must live to the end of the process. void adb_set_socket_spec(const char* _Nonnull socket_spec); // Send commands to the current emulator instance. Will fail if there is not // exactly one emulator connected (or if you use -s <serial> with a <serial> Loading adb/client/main.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ static BOOL WINAPI ctrlc_handler(DWORD type) { } #endif int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply_fd) { #if defined(_WIN32) // adb start-server starts us up with stdout and stderr hooked up to // anonymous pipes. When the C Runtime sees this, it makes stderr and Loading @@ -113,8 +113,7 @@ int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT); std::string error; std::string local_name = android::base::StringPrintf("tcp:%d", server_port); if (install_listener(local_name, "*smartsocket*", nullptr, 0, nullptr, &error)) { if (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error)) { fatal("could not install *smartsocket* listener: %s", error.c_str()); } Loading Loading
adb/adb.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -611,8 +611,7 @@ static unsigned __stdcall _redirect_stderr_thread(HANDLE h) { #endif int launch_server(int server_port) { int launch_server(const std::string& socket_spec) { #if defined(_WIN32) /* we need to start the server in the background */ /* we create a PIPE that will be used to wait for the server's "OK" */ Loading Loading @@ -715,9 +714,8 @@ int launch_server(int server_port) } WCHAR args[64]; snwprintf(args, arraysize(args), L"adb -P %d fork-server server --reply-fd %d", server_port, ack_write_as_int); snwprintf(args, arraysize(args), L"adb -L %s fork-server server --reply-fd %d", socket_spec.c_str(), ack_write_as_int); PROCESS_INFORMATION pinfo; ZeroMemory(&pinfo, sizeof(pinfo)); Loading Loading @@ -862,12 +860,11 @@ int launch_server(int server_port) adb_close(fd[0]); char str_port[30]; snprintf(str_port, sizeof(str_port), "%d", server_port); char reply_fd[30]; snprintf(reply_fd, sizeof(reply_fd), "%d", fd[1]); // child process int result = execl(path.c_str(), "adb", "-P", str_port, "fork-server", "server", "--reply-fd", reply_fd, NULL); int result = execl(path.c_str(), "adb", "-L", socket_spec.c_str(), "fork-server", "server", "--reply-fd", reply_fd, NULL); // this should not return fprintf(stderr, "OOPS! execl returned %d, errno: %d\n", result, errno); } else { Loading
adb/adb.h +2 −2 Original line number Diff line number Diff line Loading @@ -126,8 +126,8 @@ void fatal_errno(const char* fmt, ...) __attribute__((noreturn, format(__printf_ void handle_packet(apacket *p, atransport *t); int launch_server(int server_port); int adb_server_main(int is_daemon, int server_port, int ack_reply_fd); int launch_server(const std::string& socket_spec); int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply_fd); /* initialize a transport object's func pointers and state */ #if ADB_HOST Loading
adb/adb_client.cpp +15 −30 Original line number Diff line number Diff line Loading @@ -37,12 +37,12 @@ #include "adb_io.h" #include "adb_utils.h" #include "socket_spec.h" static TransportType __adb_transport = kTransportAny; static const char* __adb_serial = NULL; static int __adb_server_port = DEFAULT_ADB_PORT; static const char* __adb_server_name = NULL; static const char* __adb_server_socket_spec; void adb_set_transport(TransportType type, const char* serial) { Loading @@ -59,14 +59,11 @@ void adb_get_transport(TransportType* type, const char** serial) { } } void adb_set_tcp_specifics(int server_port) { __adb_server_port = server_port; void adb_set_socket_spec(const char* socket_spec) { if (!__adb_server_socket_spec) { LOG(FATAL) << "attempted to reinitialize adb_server_socket_spec"; } void adb_set_tcp_name(const char* hostname) { __adb_server_name = hostname; __adb_server_socket_spec = socket_spec; } static int switch_socket_transport(int fd, std::string* error) { Loading Loading @@ -139,24 +136,13 @@ int _adb_connect(const std::string& service, std::string* error) { return -1; } int fd; std::string reason; if (__adb_server_name) { fd = network_connect(__adb_server_name, __adb_server_port, SOCK_STREAM, 0, &reason); if (fd == -1) { *error = android::base::StringPrintf("can't connect to %s:%d: %s", __adb_server_name, __adb_server_port, reason.c_str()); return -2; } } else { fd = network_loopback_client(__adb_server_port, SOCK_STREAM, &reason); if (fd == -1) { *error = android::base::StringPrintf("cannot connect to daemon: %s", reason.c_str()); int fd = socket_spec_connect(__adb_server_socket_spec, &reason); if (fd < 0) { *error = android::base::StringPrintf("cannot connect to daemon at %s: %s", __adb_server_socket_spec, reason.c_str()); return -2; } } if ((memcmp(&service[0],"host",4) != 0 || service == "host:reconnect") && switch_socket_transport(fd, error)) { Loading Loading @@ -185,15 +171,14 @@ int adb_connect(const std::string& service, std::string* error) { int fd = _adb_connect("host:version", error); D("adb_connect: service %s", service.c_str()); if (fd == -2 && __adb_server_name) { if (fd == -2 && !is_local_socket_spec(__adb_server_socket_spec)) { fprintf(stderr,"** Cannot start server on remote host\n"); // error is the original network connection error return fd; } else if (fd == -2) { fprintf(stdout,"* daemon not running. starting it now on port %d *\n", __adb_server_port); fprintf(stdout, "* daemon not running. starting it now at %s *\n", __adb_server_socket_spec); start_server: if (launch_server(__adb_server_port)) { if (launch_server(__adb_server_socket_spec)) { fprintf(stderr,"* failed to start daemon *\n"); // launch_server() has already printed detailed error info, so just // return a generic error string about the overall adb_connect() Loading
adb/adb_client.h +3 −5 Original line number Diff line number Diff line Loading @@ -43,11 +43,9 @@ void adb_set_transport(TransportType type, const char* _Nullable serial); // Get the preferred transport to connect to. void adb_get_transport(TransportType* _Nullable type, const char* _Nullable* _Nullable serial); // Set TCP specifics of the transport to use. void adb_set_tcp_specifics(int server_port); // Set TCP Hostname of the transport to use. void adb_set_tcp_name(const char* _Nullable hostname); // Set the socket specification for the adb server. // This function can only be called once, and the argument must live to the end of the process. void adb_set_socket_spec(const char* _Nonnull socket_spec); // Send commands to the current emulator instance. Will fail if there is not // exactly one emulator connected (or if you use -s <serial> with a <serial> Loading
adb/client/main.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ static BOOL WINAPI ctrlc_handler(DWORD type) { } #endif int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply_fd) { #if defined(_WIN32) // adb start-server starts us up with stdout and stderr hooked up to // anonymous pipes. When the C Runtime sees this, it makes stderr and Loading @@ -113,8 +113,7 @@ int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT); std::string error; std::string local_name = android::base::StringPrintf("tcp:%d", server_port); if (install_listener(local_name, "*smartsocket*", nullptr, 0, nullptr, &error)) { if (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error)) { fatal("could not install *smartsocket* listener: %s", error.c_str()); } Loading