Loading adb/adb.cpp +6 −2 Original line number Original line Diff line number Diff line Loading @@ -979,8 +979,12 @@ bool handle_forward_request(const char* service, if (kill_forward) { if (kill_forward) { r = remove_listener(pieces[0].c_str(), transport); r = remove_listener(pieces[0].c_str(), transport); } else { } else { r = install_listener(pieces[0], pieces[1].c_str(), transport, no_rebind, int flags = 0; &resolved_tcp_port, &error); if (no_rebind) { flags |= INSTALL_LISTENER_NO_REBIND; } r = install_listener(pieces[0], pieces[1].c_str(), transport, flags, &resolved_tcp_port, &error); } } if (r == INSTALL_STATUS_OK) { if (r == INSTALL_STATUS_OK) { #if ADB_HOST #if ADB_HOST Loading adb/adb_listeners.cpp +15 −4 Original line number Original line Diff line number Diff line Loading @@ -164,6 +164,15 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) { } } } } void enable_daemon_sockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); for (auto& l : listener_list) { if (l->connect_to == "*smartsocket*") { fdevent_set(l->fde, FDE_READ); } } } void close_smartsockets() EXCLUDES(listener_list_mutex) { void close_smartsockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); std::lock_guard<std::mutex> lock(listener_list_mutex); auto pred = [](const std::unique_ptr<alistener>& listener) { auto pred = [](const std::unique_ptr<alistener>& listener) { Loading @@ -173,7 +182,7 @@ void close_smartsockets() EXCLUDES(listener_list_mutex) { } } InstallStatus install_listener(const std::string& local_name, const char* connect_to, InstallStatus install_listener(const std::string& local_name, const char* connect_to, atransport* transport, int no_rebind, int* resolved_tcp_port, atransport* transport, int flags, int* resolved_tcp_port, std::string* error) EXCLUDES(listener_list_mutex) { std::string* error) EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); std::lock_guard<std::mutex> lock(listener_list_mutex); for (auto& l : listener_list) { for (auto& l : listener_list) { Loading @@ -184,8 +193,8 @@ InstallStatus install_listener(const std::string& local_name, const char* connec return INSTALL_STATUS_INTERNAL_ERROR; return INSTALL_STATUS_INTERNAL_ERROR; } } // Can't repurpose a listener if 'no_rebind' is true. // Can't repurpose a listener if INSTALL_LISTENER_NO_REBIND is set if (no_rebind) { if (flags & INSTALL_LISTENER_NO_REBIND) { *error = "cannot rebind"; *error = "cannot rebind"; return INSTALL_STATUS_CANNOT_REBIND; return INSTALL_STATUS_CANNOT_REBIND; } } Loading Loading @@ -222,7 +231,9 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } else { } else { listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get()); listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get()); } } if ((flags & INSTALL_LISTENER_DISABLED) == 0) { fdevent_set(listener->fde, FDE_READ); fdevent_set(listener->fde, FDE_READ); } listener->transport = transport; listener->transport = transport; Loading adb/adb_listeners.h +5 −1 Original line number Original line Diff line number Diff line Loading @@ -32,8 +32,11 @@ enum InstallStatus { INSTALL_STATUS_LISTENER_NOT_FOUND = -4, INSTALL_STATUS_LISTENER_NOT_FOUND = -4, }; }; inline constexpr int INSTALL_LISTENER_NO_REBIND = 1 << 0; inline constexpr int INSTALL_LISTENER_DISABLED = 1 << 1; InstallStatus install_listener(const std::string& local_name, const char* connect_to, InstallStatus install_listener(const std::string& local_name, const char* connect_to, atransport* transport, int no_rebind, int* resolved_tcp_port, atransport* transport, int flags, int* resolved_tcp_port, std::string* error); std::string* error); std::string format_listeners(); std::string format_listeners(); Loading @@ -41,6 +44,7 @@ std::string format_listeners(); InstallStatus remove_listener(const char* local_name, atransport* transport); InstallStatus remove_listener(const char* local_name, atransport* transport); void remove_all_listeners(void); void remove_all_listeners(void); void enable_daemon_sockets(); void close_smartsockets(); void close_smartsockets(); #endif /* __ADB_LISTENERS_H */ #endif /* __ADB_LISTENERS_H */ adb/client/main.cpp +17 −10 Original line number Original line Diff line number Diff line Loading @@ -137,9 +137,10 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now(); // If we told a previous adb server to quit because of version mismatch, we can get to this // If we told a previous adb server to quit because of version mismatch, we can get to this // point before it's finished exiting. Retry for a while to give it some time. // point before it's finished exiting. Retry for a while to give it some time. Don't actually while (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error) != // accept any connections until adb_wait_for_device_initialization finishes below. INSTALL_STATUS_OK) { while (install_listener(socket_spec, "*smartsocket*", nullptr, INSTALL_LISTENER_DISABLED, nullptr, &error) != INSTALL_STATUS_OK) { if (std::chrono::steady_clock::now() - start > 0.5s) { if (std::chrono::steady_clock::now() - start > 0.5s) { LOG(FATAL) << "could not install *smartsocket* listener: " << error; LOG(FATAL) << "could not install *smartsocket* listener: " << error; } } Loading @@ -160,12 +161,14 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply PLOG(FATAL) << "setsid() failed"; PLOG(FATAL) << "setsid() failed"; } } #endif #endif } // Wait for the USB scan to complete before notifying the parent that we're up. // Wait for the USB scan to complete before notifying the parent that we're up. // We need to perform this in a thread, because we would otherwise block the event loop. // We need to perform this in a thread, because we would otherwise block the event loop. std::thread notify_thread([ack_reply_fd]() { std::thread notify_thread([ack_reply_fd]() { adb_wait_for_device_initialization(); adb_wait_for_device_initialization(); if (ack_reply_fd >= 0) { // Any error output written to stderr now goes to adb.log. We could // Any error output written to stderr now goes to adb.log. We could // keep around a copy of the stderr fd and use that to write any errors // keep around a copy of the stderr fd and use that to write any errors // encountered by the following code, but that is probably overkill. // encountered by the following code, but that is probably overkill. Loading @@ -191,9 +194,13 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply } } unix_close(ack_reply_fd); unix_close(ack_reply_fd); #endif #endif } // We don't accept() client connections until this point: this way, clients // can't see wonky state early in startup even if they're connecting directly // to the server instead of going through the adb program. fdevent_run_on_main_thread([] { enable_daemon_sockets(); }); }); }); notify_thread.detach(); notify_thread.detach(); } #if defined(__linux__) #if defined(__linux__) // Write our location to .android/adb.$PORT, so that older clients can exec us. // Write our location to .android/adb.$PORT, so that older clients can exec us. Loading Loading
adb/adb.cpp +6 −2 Original line number Original line Diff line number Diff line Loading @@ -979,8 +979,12 @@ bool handle_forward_request(const char* service, if (kill_forward) { if (kill_forward) { r = remove_listener(pieces[0].c_str(), transport); r = remove_listener(pieces[0].c_str(), transport); } else { } else { r = install_listener(pieces[0], pieces[1].c_str(), transport, no_rebind, int flags = 0; &resolved_tcp_port, &error); if (no_rebind) { flags |= INSTALL_LISTENER_NO_REBIND; } r = install_listener(pieces[0], pieces[1].c_str(), transport, flags, &resolved_tcp_port, &error); } } if (r == INSTALL_STATUS_OK) { if (r == INSTALL_STATUS_OK) { #if ADB_HOST #if ADB_HOST Loading
adb/adb_listeners.cpp +15 −4 Original line number Original line Diff line number Diff line Loading @@ -164,6 +164,15 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) { } } } } void enable_daemon_sockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); for (auto& l : listener_list) { if (l->connect_to == "*smartsocket*") { fdevent_set(l->fde, FDE_READ); } } } void close_smartsockets() EXCLUDES(listener_list_mutex) { void close_smartsockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); std::lock_guard<std::mutex> lock(listener_list_mutex); auto pred = [](const std::unique_ptr<alistener>& listener) { auto pred = [](const std::unique_ptr<alistener>& listener) { Loading @@ -173,7 +182,7 @@ void close_smartsockets() EXCLUDES(listener_list_mutex) { } } InstallStatus install_listener(const std::string& local_name, const char* connect_to, InstallStatus install_listener(const std::string& local_name, const char* connect_to, atransport* transport, int no_rebind, int* resolved_tcp_port, atransport* transport, int flags, int* resolved_tcp_port, std::string* error) EXCLUDES(listener_list_mutex) { std::string* error) EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); std::lock_guard<std::mutex> lock(listener_list_mutex); for (auto& l : listener_list) { for (auto& l : listener_list) { Loading @@ -184,8 +193,8 @@ InstallStatus install_listener(const std::string& local_name, const char* connec return INSTALL_STATUS_INTERNAL_ERROR; return INSTALL_STATUS_INTERNAL_ERROR; } } // Can't repurpose a listener if 'no_rebind' is true. // Can't repurpose a listener if INSTALL_LISTENER_NO_REBIND is set if (no_rebind) { if (flags & INSTALL_LISTENER_NO_REBIND) { *error = "cannot rebind"; *error = "cannot rebind"; return INSTALL_STATUS_CANNOT_REBIND; return INSTALL_STATUS_CANNOT_REBIND; } } Loading Loading @@ -222,7 +231,9 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } else { } else { listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get()); listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get()); } } if ((flags & INSTALL_LISTENER_DISABLED) == 0) { fdevent_set(listener->fde, FDE_READ); fdevent_set(listener->fde, FDE_READ); } listener->transport = transport; listener->transport = transport; Loading
adb/adb_listeners.h +5 −1 Original line number Original line Diff line number Diff line Loading @@ -32,8 +32,11 @@ enum InstallStatus { INSTALL_STATUS_LISTENER_NOT_FOUND = -4, INSTALL_STATUS_LISTENER_NOT_FOUND = -4, }; }; inline constexpr int INSTALL_LISTENER_NO_REBIND = 1 << 0; inline constexpr int INSTALL_LISTENER_DISABLED = 1 << 1; InstallStatus install_listener(const std::string& local_name, const char* connect_to, InstallStatus install_listener(const std::string& local_name, const char* connect_to, atransport* transport, int no_rebind, int* resolved_tcp_port, atransport* transport, int flags, int* resolved_tcp_port, std::string* error); std::string* error); std::string format_listeners(); std::string format_listeners(); Loading @@ -41,6 +44,7 @@ std::string format_listeners(); InstallStatus remove_listener(const char* local_name, atransport* transport); InstallStatus remove_listener(const char* local_name, atransport* transport); void remove_all_listeners(void); void remove_all_listeners(void); void enable_daemon_sockets(); void close_smartsockets(); void close_smartsockets(); #endif /* __ADB_LISTENERS_H */ #endif /* __ADB_LISTENERS_H */
adb/client/main.cpp +17 −10 Original line number Original line Diff line number Diff line Loading @@ -137,9 +137,10 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now(); // If we told a previous adb server to quit because of version mismatch, we can get to this // If we told a previous adb server to quit because of version mismatch, we can get to this // point before it's finished exiting. Retry for a while to give it some time. // point before it's finished exiting. Retry for a while to give it some time. Don't actually while (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error) != // accept any connections until adb_wait_for_device_initialization finishes below. INSTALL_STATUS_OK) { while (install_listener(socket_spec, "*smartsocket*", nullptr, INSTALL_LISTENER_DISABLED, nullptr, &error) != INSTALL_STATUS_OK) { if (std::chrono::steady_clock::now() - start > 0.5s) { if (std::chrono::steady_clock::now() - start > 0.5s) { LOG(FATAL) << "could not install *smartsocket* listener: " << error; LOG(FATAL) << "could not install *smartsocket* listener: " << error; } } Loading @@ -160,12 +161,14 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply PLOG(FATAL) << "setsid() failed"; PLOG(FATAL) << "setsid() failed"; } } #endif #endif } // Wait for the USB scan to complete before notifying the parent that we're up. // Wait for the USB scan to complete before notifying the parent that we're up. // We need to perform this in a thread, because we would otherwise block the event loop. // We need to perform this in a thread, because we would otherwise block the event loop. std::thread notify_thread([ack_reply_fd]() { std::thread notify_thread([ack_reply_fd]() { adb_wait_for_device_initialization(); adb_wait_for_device_initialization(); if (ack_reply_fd >= 0) { // Any error output written to stderr now goes to adb.log. We could // Any error output written to stderr now goes to adb.log. We could // keep around a copy of the stderr fd and use that to write any errors // keep around a copy of the stderr fd and use that to write any errors // encountered by the following code, but that is probably overkill. // encountered by the following code, but that is probably overkill. Loading @@ -191,9 +194,13 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply } } unix_close(ack_reply_fd); unix_close(ack_reply_fd); #endif #endif } // We don't accept() client connections until this point: this way, clients // can't see wonky state early in startup even if they're connecting directly // to the server instead of going through the adb program. fdevent_run_on_main_thread([] { enable_daemon_sockets(); }); }); }); notify_thread.detach(); notify_thread.detach(); } #if defined(__linux__) #if defined(__linux__) // Write our location to .android/adb.$PORT, so that older clients can exec us. // Write our location to .android/adb.$PORT, so that older clients can exec us. Loading