From cc07b3556510d03e389a8994a8e5dbed3f3bbbb4 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 12 Feb 2016 15:00:52 -0800 Subject: minadbd: update for adb_thread_create signature change. Change-Id: Ifa0b4d8c1cf0bb39abac61984ff165e82e41222c --- minadbd/services.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'minadbd') diff --git a/minadbd/services.cpp b/minadbd/services.cpp index d25648fb4..658a43f36 100644 --- a/minadbd/services.cpp +++ b/minadbd/services.cpp @@ -35,11 +35,10 @@ struct stinfo { void *cookie; }; -void* service_bootstrap_func(void* x) { +void service_bootstrap_func(void* x) { stinfo* sti = reinterpret_cast(x); sti->func(sti->fd, sti->cookie); free(sti); - return 0; } static void sideload_host_service(int sfd, void* data) { -- cgit v1.2.3 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 (limited to 'minadbd') 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 From 1675848a39512ad512c530c0e47ccd1ce13f96e5 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 9 Aug 2016 18:46:57 -0700 Subject: adb headers now refer to openssl headers. Change-Id: Icddc4a4f226595338fafbcb14ee9338c58b4a80f --- minadbd/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'minadbd') diff --git a/minadbd/Android.mk b/minadbd/Android.mk index b3bbb428c..34631a944 100644 --- a/minadbd/Android.mk +++ b/minadbd/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS := $(minadbd_cflags) LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration LOCAL_C_INCLUDES := bootable/recovery system/core/adb LOCAL_WHOLE_STATIC_LIBRARIES := libadbd -LOCAL_STATIC_LIBRARIES := libbase +LOCAL_STATIC_LIBRARIES := libcrypto libbase include $(BUILD_STATIC_LIBRARY) -- cgit v1.2.3 From acb2a2fa4c415944a27539461ba3757f3edbb128 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 26 Aug 2016 18:24:34 -0700 Subject: minadbd: rename adb_server_main to minadbd_main. adb_server_main in adb refers to the adb server on the host, not adbd. Since there doesn't seem to be a good reason to reuse the declaration from adb's headers, give minadbd a main function of its own. Change-Id: I748f1a6822dc14c726cb73ef3b533c57a6615608 --- minadbd/Android.mk | 2 +- minadbd/adb_main.cpp | 41 ----------------------------------------- minadbd/minadbd.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ minadbd/minadbd.h | 22 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 42 deletions(-) delete mode 100644 minadbd/adb_main.cpp create mode 100644 minadbd/minadbd.cpp create mode 100644 minadbd/minadbd.h (limited to 'minadbd') diff --git a/minadbd/Android.mk b/minadbd/Android.mk index 34631a944..7eef13ee0 100644 --- a/minadbd/Android.mk +++ b/minadbd/Android.mk @@ -11,8 +11,8 @@ minadbd_cflags := \ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ - adb_main.cpp \ fuse_adb_provider.cpp \ + minadbd.cpp \ minadbd_services.cpp \ LOCAL_CLANG := true diff --git a/minadbd/adb_main.cpp b/minadbd/adb_main.cpp deleted file mode 100644 index 8e581c2a9..000000000 --- a/minadbd/adb_main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2015 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 "adb.h" -#include "adb_auth.h" -#include "transport.h" - -int adb_server_main(int is_daemon, int server_port, int /* reply_fd */) { - adb_device_banner = "sideload"; - - signal(SIGPIPE, SIG_IGN); - - // We can't require authentication for sideloading. http://b/22025550. - auth_required = false; - - init_transport_registration(); - usb_init(); - - VLOG(ADB) << "Event loop starting"; - fdevent_loop(); - - return 0; -} diff --git a/minadbd/minadbd.cpp b/minadbd/minadbd.cpp new file mode 100644 index 000000000..349189cc7 --- /dev/null +++ b/minadbd/minadbd.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 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 "minadbd.h" + +#include +#include +#include +#include + +#include "adb.h" +#include "adb_auth.h" +#include "transport.h" + +int minadbd_main() { + adb_device_banner = "sideload"; + + signal(SIGPIPE, SIG_IGN); + + // We can't require authentication for sideloading. http://b/22025550. + auth_required = false; + + init_transport_registration(); + usb_init(); + + VLOG(ADB) << "Event loop starting"; + fdevent_loop(); + + return 0; +} diff --git a/minadbd/minadbd.h b/minadbd/minadbd.h new file mode 100644 index 000000000..3570a5da5 --- /dev/null +++ b/minadbd/minadbd.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2016 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. + */ + +#ifndef MINADBD_H__ +#define MINADBD_H__ + +int minadbd_main(); + +#endif -- cgit v1.2.3 From b29f23f7e7c791e7d8786de93d630a12e4250c71 Mon Sep 17 00:00:00 2001 From: Rahul Chaudhry Date: Wed, 9 Nov 2016 13:17:01 -0800 Subject: Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap. static_cast is preferable to reinterpret_cast when casting from void* pointers returned by malloc/calloc/realloc/mmap calls. Discovered while looking at compiler warnings (b/26936282). Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mma Change-Id: Iaffd537784aa857108f6981fdfd82d0496eb5592 Merged-In: I151642d5a60c94f312d0611576ad0143c249ba3d --- minadbd/minadbd_services.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'minadbd') diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp index 003b51913..426d982eb 100644 --- a/minadbd/minadbd_services.cpp +++ b/minadbd/minadbd_services.cpp @@ -66,7 +66,7 @@ static int create_service_thread(void (*func)(int, void *), void *cookie) { return -1; } - stinfo* sti = reinterpret_cast(malloc(sizeof(stinfo))); + stinfo* sti = static_cast(malloc(sizeof(stinfo))); if(sti == 0) fatal("cannot allocate stinfo"); sti->func = func; sti->cookie = cookie; -- cgit v1.2.3 From 7a890e5cf5900a1eff63de06c813475305cabc37 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 7 Jan 2017 12:49:32 -0800 Subject: Move to .md files for even trivial documentation. So it's automatically displayed for folks browsing the source. Bug: N/A Test: N/A Change-Id: Ie9b190072ebdf0faf06cc1fd7b3467c031056753 --- minadbd/README.md | 8 ++++++++ minadbd/README.txt | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 minadbd/README.md delete mode 100644 minadbd/README.txt (limited to 'minadbd') diff --git a/minadbd/README.md b/minadbd/README.md new file mode 100644 index 000000000..e69dc87c6 --- /dev/null +++ b/minadbd/README.md @@ -0,0 +1,8 @@ +minadbd is now mostly built from libadbd. The fuse features are unique to +minadbd, and services.c has been modified as follows: + + - all services removed + - all host mode support removed + - sideload_service() added; this is the only service supported. It + receives a single blob of data, writes it to a fixed filename, and + makes the process exit. diff --git a/minadbd/README.txt b/minadbd/README.txt deleted file mode 100644 index e69dc87c6..000000000 --- a/minadbd/README.txt +++ /dev/null @@ -1,8 +0,0 @@ -minadbd is now mostly built from libadbd. The fuse features are unique to -minadbd, and services.c has been modified as follows: - - - all services removed - - all host mode support removed - - sideload_service() added; this is the only service supported. It - receives a single blob of data, writes it to a fixed filename, and - makes the process exit. -- cgit v1.2.3 From ff8fdc955af4083df2c98b6a08d2bff5e0d97087 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 9 Jan 2017 14:28:42 -0800 Subject: Address review comment. Bug: N/A Test: N/A Change-Id: I9467286e57522c6ed640a3599cb678ac10d9e2a4 --- minadbd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'minadbd') diff --git a/minadbd/README.md b/minadbd/README.md index e69dc87c6..5a0a067de 100644 --- a/minadbd/README.md +++ b/minadbd/README.md @@ -3,6 +3,6 @@ minadbd, and services.c has been modified as follows: - all services removed - all host mode support removed - - sideload_service() added; this is the only service supported. It + - `sideload_service()` added; this is the only service supported. It receives a single blob of data, writes it to a fixed filename, and makes the process exit. -- cgit v1.2.3