From 038c4a11db2652bc9a212ab9c375bbb6d1a80a28 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 27 Jul 2018 11:18:30 -0700 Subject: minadbd: avoid overrriding services_to_fd. Previously, we were relying on linker ordering pulling in minadbd's copy of services_to_fd instead of libadbd's, which breaks when we switch to dynamically linking. Separate out libadbd's services into a separate function that's in a file that isn't built into libadbd, so that we can provide our own here. Bug: http://b/111831478 Test: mma Change-Id: I2479947b2d81db5e750020fffc2c2c770cb31a78 --- minadbd/minadbd_services.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp index 043c51a6a..ab1939e92 100644 --- a/minadbd/minadbd_services.cpp +++ b/minadbd/minadbd_services.cpp @@ -21,15 +21,18 @@ #include #include +#include #include #include #include "adb.h" +#include "adb_unique_fd.h" #include "fdevent.h" #include "fuse_adb_provider.h" +#include "services.h" #include "sysdeps.h" -static void sideload_host_service(int sfd, const std::string& args) { +static void sideload_host_service(unique_fd sfd, const std::string& args) { int file_size; int block_size; if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) { @@ -45,22 +48,7 @@ static void sideload_host_service(int sfd, const std::string& args) { exit(result == 0 ? 0 : 1); } -static int create_service_thread(void (*func)(int, const std::string&), const std::string& args) { - int s[2]; - if (adb_socketpair(s)) { - printf("cannot create service socket pair\n"); - return -1; - } - - std::thread([s, func, args]() { func(s[1], args); }).detach(); - - VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1]; - return s[0]; -} - -int service_to_fd(const char* name, atransport* /* transport */) { - int ret = -1; - +unique_fd daemon_service_to_fd(const char* name, atransport* /* transport */) { if (!strncmp(name, "sideload:", 9)) { // this exit status causes recovery to print a special error // message saying to use a newer adb (that supports @@ -68,10 +56,8 @@ int service_to_fd(const char* name, atransport* /* transport */) { exit(3); } else if (!strncmp(name, "sideload-host:", 14)) { std::string arg(name + 14); - ret = create_service_thread(sideload_host_service, arg); - } - if (ret >= 0) { - close_on_exec(ret); + return create_service_thread("sideload-host", + std::bind(sideload_host_service, std::placeholders::_1, arg)); } - return ret; + return unique_fd{}; } -- cgit v1.2.3