From c77904e3c5b71e005e70ce0b1022501ac47b5677 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Tue, 12 Nov 2019 18:55:29 +0000 Subject: [PATCH] Revert "Support socket activation of adb server" This reverts commit 4456b5fc15c233afe3e8aedf5b87aaeed1d9e0f9. Reason for revert: Device boot failure BUG: 144355953 Change-Id: I539400fa2422bd4d6e396634c629a928cd2ac398 --- adb/SOCKET-ACTIVATION.txt | 42 --------------------------------- adb/client/adb_client.cpp | 2 +- adb/client/commandline.cpp | 1 - adb/socket_spec.cpp | 48 +------------------------------------- adb/sysdeps.h | 9 +------ 5 files changed, 3 insertions(+), 99 deletions(-) delete mode 100644 adb/SOCKET-ACTIVATION.txt diff --git a/adb/SOCKET-ACTIVATION.txt b/adb/SOCKET-ACTIVATION.txt deleted file mode 100644 index 4ef62ac9d..000000000 --- a/adb/SOCKET-ACTIVATION.txt +++ /dev/null @@ -1,42 +0,0 @@ -adb can be configured to work with systemd-style socket activation, -allowing the daemon to start automatically when the adb control port -is forwarded across a network. You need two files, placed in the usual -systemd service directories (e.g., ~/.config/systemd/user for a user -service). - -adb.service: - ---- START adb.service CUT HERE --- -[Unit] -Description=adb -After=adb.socket -Requires=adb.socket -[Service] -Type=simple -# FD 3 is part of the systemd interface -ExecStart=/path/to/adb server nodaemon -L acceptfd:3 ---- END adb.service CUT HERE --- - ---- START adb.socket CUT HERE --- -[Unit] -Description=adb -PartOf=adb.service -[Socket] -ListenStream=127.0.0.1:5037 -Accept=no -[Install] -WantedBy=sockets.target ---- END adb.socket CUT HERE --- - -After installing the adb service, the adb server will be started -automatically on any connection to 127.0.0.1:5037 (the default adb -control port), even after adb kill-server kills the server. - -Other "superserver" launcher systems (like macOS launchd) can be -configured analogously. The important part is that adb be started with -"server" and "nodaemon" command line arguments and that the listen -address (passed to -L) name a file descriptor that's ready to -accept(2) connections and that's already bound to the desired address -and listening. inetd-style pre-accepted sockets do _not_ work in this -configuration: the file descriptor passed to acceptfd must be the -serve socket, not the accepted connection socket. diff --git a/adb/client/adb_client.cpp b/adb/client/adb_client.cpp index f724cb522..d91ae35ce 100644 --- a/adb/client/adb_client.cpp +++ b/adb/client/adb_client.cpp @@ -222,7 +222,7 @@ std::optional adb_get_server_executable_path() { int port; std::string error; if (!parse_tcp_socket_spec(__adb_server_socket_spec, nullptr, &port, nullptr, &error)) { - return {}; + LOG(FATAL) << "failed to parse server socket spec: " << error; } return adb_get_android_dir_path() + OS_PATH_SEPARATOR + "adb." + std::to_string(port); diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp index 6465ffe6d..0ffdbc28b 100644 --- a/adb/client/commandline.cpp +++ b/adb/client/commandline.cpp @@ -107,7 +107,6 @@ static void help() { " localfilesystem:\n" " dev:\n" " jdwp: (remote only)\n" - " acceptfd: (listen only)\n" " forward --remove LOCAL remove specific forward socket connection\n" " forward --remove-all remove all forward socket connections\n" " ppp TTY [PARAMETER...] run PPP over USB\n" diff --git a/adb/socket_spec.cpp b/adb/socket_spec.cpp index e5129e6b5..98468b5cf 100644 --- a/adb/socket_spec.cpp +++ b/adb/socket_spec.cpp @@ -16,7 +16,6 @@ #include "socket_spec.h" -#include #include #include #include @@ -29,12 +28,10 @@ #include #include "adb.h" -#include "adb_utils.h" #include "sysdeps.h" using namespace std::string_literals; -using android::base::ConsumePrefix; using android::base::StringPrintf; #if defined(__linux__) @@ -134,7 +131,7 @@ bool is_socket_spec(std::string_view spec) { return true; } } - return spec.starts_with("tcp:") || spec.starts_with("acceptfd:"); + return spec.starts_with("tcp:"); } bool is_local_socket_spec(std::string_view spec) { @@ -238,9 +235,6 @@ bool socket_spec_connect(unique_fd* fd, std::string_view address, int* port, std *error = "vsock is only supported on linux"; return false; #endif // ADB_LINUX - } else if (address.starts_with("acceptfd:")) { - *error = "cannot connect to acceptfd"; - return false; } for (const auto& it : kLocalSocketTypes) { @@ -338,46 +332,6 @@ int socket_spec_listen(std::string_view spec, std::string* error, int* resolved_ *error = "vsock is only supported on linux"; return -1; #endif // ADB_LINUX - } else if (ConsumePrefix(&spec, "acceptfd:")) { -#if ADB_WINDOWS - *error = "socket activation not supported under Windows"; - return -1; -#else - // We inherited the socket from some kind of launcher. It's already bound and - // listening. Return a copy of the FD instead of the FD itself so we implement the - // normal "listen" contract and can succeed more than once. - unsigned int fd_u; - if (!ParseUint(&fd_u, spec) || fd_u > std::numeric_limits::max()) { - *error = "invalid fd"; - return -1; - } - int fd = static_cast(fd_u); - int flags = get_fd_flags(fd); - if (flags < 0) { - *error = android::base::StringPrintf("could not get flags of inherited fd %d: '%s'", fd, - strerror(errno)); - return -1; - } - if (flags & O_CLOEXEC) { - *error = android::base::StringPrintf("fd %d was not inherited from parent", fd); - return -1; - } - - int dummy_sock_type; - socklen_t dummy_sock_type_size = sizeof(dummy_sock_type); - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &dummy_sock_type, &dummy_sock_type_size)) { - *error = android::base::StringPrintf("fd %d does not refer to a socket", fd); - return -1; - } - - int new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); - if (new_fd < 0) { - *error = android::base::StringPrintf("could not dup inherited fd %d: '%s'", fd, - strerror(errno)); - return -1; - } - return new_fd; -#endif } for (const auto& it : kLocalSocketTypes) { diff --git a/adb/sysdeps.h b/adb/sysdeps.h index 979413a3d..466c2cedb 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -349,15 +349,8 @@ static __inline__ bool adb_is_separator(char c) { return c == '/'; } -static __inline__ int get_fd_flags(borrowed_fd fd) { - return fcntl(fd.get(), F_GETFD); -} - static __inline__ void close_on_exec(borrowed_fd fd) { - int flags = get_fd_flags(fd); - if (flags >= 0 && (flags & O_CLOEXEC) == 0) { - fcntl(fd.get(), F_SETFD, flags | O_CLOEXEC); - } + fcntl(fd.get(), F_SETFD, FD_CLOEXEC); } // Open a file and return a file descriptor that may be used with unix_read(),