From 24eb8a0643d50b636c77ffa8f3e23c7c3a8f5bf9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 15 Jun 2016 15:12:17 -0700 Subject: Minor minadbd cleanup. Distinguish our "services.cpp" more clearly from the regular adbd "services.cpp", and remove a few useless includes of "sysdeps.h". Change-Id: Ided4945a3ac5916133322ca7e95fa51add9abaa4 --- minadbd/Android.mk | 2 +- minadbd/adb_main.cpp | 2 - minadbd/fuse_adb_provider.cpp | 2 - minadbd/minadbd_services.cpp | 103 +++++++++++++++++++++++++++++++++++++++++ minadbd/services.cpp | 104 ------------------------------------------ 5 files changed, 104 insertions(+), 109 deletions(-) create mode 100644 minadbd/minadbd_services.cpp delete mode 100644 minadbd/services.cpp diff --git a/minadbd/Android.mk b/minadbd/Android.mk index 3db3b4114..b3bbb428c 100644 --- a/minadbd/Android.mk +++ b/minadbd/Android.mk @@ -13,7 +13,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ adb_main.cpp \ fuse_adb_provider.cpp \ - services.cpp \ + minadbd_services.cpp \ LOCAL_CLANG := true LOCAL_MODULE := libminadbd diff --git a/minadbd/adb_main.cpp b/minadbd/adb_main.cpp index 0694280cb..8e581c2a9 100644 --- a/minadbd/adb_main.cpp +++ b/minadbd/adb_main.cpp @@ -19,8 +19,6 @@ #include #include -#include "sysdeps.h" - #include "adb.h" #include "adb_auth.h" #include "transport.h" diff --git a/minadbd/fuse_adb_provider.cpp b/minadbd/fuse_adb_provider.cpp index d71807dfb..0f4c2563d 100644 --- a/minadbd/fuse_adb_provider.cpp +++ b/minadbd/fuse_adb_provider.cpp @@ -19,8 +19,6 @@ #include #include -#include "sysdeps.h" - #include "adb.h" #include "adb_io.h" #include "fuse_adb_provider.h" diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp new file mode 100644 index 000000000..003b51913 --- /dev/null +++ b/minadbd/minadbd_services.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "adb.h" +#include "fdevent.h" +#include "fuse_adb_provider.h" +#include "sysdeps.h" + +typedef struct stinfo stinfo; + +struct stinfo { + void (*func)(int fd, void *cookie); + int fd; + void *cookie; +}; + +void service_bootstrap_func(void* x) { + stinfo* sti = reinterpret_cast(x); + sti->func(sti->fd, sti->cookie); + free(sti); +} + +static void sideload_host_service(int sfd, void* data) { + char* args = reinterpret_cast(data); + int file_size; + int block_size; + if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) { + printf("bad sideload-host arguments: %s\n", args); + exit(1); + } + free(args); + + printf("sideload-host file size %d block size %d\n", file_size, block_size); + + int result = run_adb_fuse(sfd, file_size, block_size); + + printf("sideload_host finished\n"); + sleep(1); + exit(result == 0 ? 0 : 1); +} + +static int create_service_thread(void (*func)(int, void *), void *cookie) { + int s[2]; + if (adb_socketpair(s)) { + printf("cannot create service socket pair\n"); + return -1; + } + + stinfo* sti = reinterpret_cast(malloc(sizeof(stinfo))); + if(sti == 0) fatal("cannot allocate stinfo"); + sti->func = func; + sti->cookie = cookie; + sti->fd = s[1]; + + if (!adb_thread_create(service_bootstrap_func, sti)) { + free(sti); + adb_close(s[0]); + adb_close(s[1]); + printf("cannot create service thread\n"); + return -1; + } + + VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1]; + return s[0]; +} + +int service_to_fd(const char* name, const atransport* transport) { + int ret = -1; + + if (!strncmp(name, "sideload:", 9)) { + // this exit status causes recovery to print a special error + // message saying to use a newer adb (that supports + // sideload-host). + exit(3); + } else if (!strncmp(name, "sideload-host:", 14)) { + char* arg = strdup(name + 14); + ret = create_service_thread(sideload_host_service, arg); + } + if (ret >= 0) { + close_on_exec(ret); + } + return ret; +} diff --git a/minadbd/services.cpp b/minadbd/services.cpp deleted file mode 100644 index 658a43f36..000000000 --- a/minadbd/services.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -#include "sysdeps.h" - -#include "adb.h" -#include "fdevent.h" -#include "fuse_adb_provider.h" - -typedef struct stinfo stinfo; - -struct stinfo { - void (*func)(int fd, void *cookie); - int fd; - void *cookie; -}; - -void service_bootstrap_func(void* x) { - stinfo* sti = reinterpret_cast(x); - sti->func(sti->fd, sti->cookie); - free(sti); -} - -static void sideload_host_service(int sfd, void* data) { - char* args = reinterpret_cast(data); - int file_size; - int block_size; - if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) { - printf("bad sideload-host arguments: %s\n", args); - exit(1); - } - free(args); - - printf("sideload-host file size %d block size %d\n", file_size, block_size); - - int result = run_adb_fuse(sfd, file_size, block_size); - - printf("sideload_host finished\n"); - sleep(1); - exit(result == 0 ? 0 : 1); -} - -static int create_service_thread(void (*func)(int, void *), void *cookie) { - int s[2]; - if(adb_socketpair(s)) { - printf("cannot create service socket pair\n"); - return -1; - } - - stinfo* sti = reinterpret_cast(malloc(sizeof(stinfo))); - if(sti == 0) fatal("cannot allocate stinfo"); - sti->func = func; - sti->cookie = cookie; - sti->fd = s[1]; - - if (!adb_thread_create(service_bootstrap_func, sti)) { - free(sti); - adb_close(s[0]); - adb_close(s[1]); - printf("cannot create service thread\n"); - return -1; - } - - VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1]; - return s[0]; -} - -int service_to_fd(const char* name, const atransport* transport) { - int ret = -1; - - if (!strncmp(name, "sideload:", 9)) { - // this exit status causes recovery to print a special error - // message saying to use a newer adb (that supports - // sideload-host). - exit(3); - } else if (!strncmp(name, "sideload-host:", 14)) { - char* arg = strdup(name + 14); - ret = create_service_thread(sideload_host_service, arg); - } - if (ret >= 0) { - close_on_exec(ret); - } - return ret; -} -- cgit v1.2.3