Index: head/devel/android-tools-adb/Makefile =================================================================== --- head/devel/android-tools-adb/Makefile (revision 444003) +++ head/devel/android-tools-adb/Makefile (revision 444004) @@ -1,98 +1,98 @@ # $FreeBSD$ PORTNAME= android-tools-adb DISTVERSIONPREFIX= android- DISTVERSION?= 7.1.2_r17 PORTREVISION?= 0 CATEGORIES= devel comms .ifndef EXTRA_PATCHES PATCH_SITES= https://github.com/android/platform_system_core/commit/ PATCHFILES= b4cff495a1f9.patch:-p1 .endif MAINTAINER= jbeich@FreeBSD.org COMMENT= Android debug bridge command line tool LICENSE= APACHE20 USE_GITHUB= yes GH_ACCOUNT= android GH_PROJECT= platform_system_core # Emulate GH_COMMIT without causing desync .ifdef DISTVERSIONSUFFIX GH_REVISION= ${DISTVERSIONSUFFIX:S/-g//} # snapshot .else GH_REVISION= 1346a4012db4 # generated by: make update-revision .endif CONFLICTS_INSTALL?= ${PORTNAME}-devel-* .ifndef EXTRA_PATCHES EXTRA_PATCHES+= ${PATCHDIR}/extra-patch-adb_sysdeps_mutex.h EXTRA_PATCHES+= ${PATCHDIR}/extra-patch-base_file.cpp .endif -USES= compiler:c++11-lib pkgconfig ssl uidfix +USES+= compiler:c++11-lib pkgconfig ssl uidfix BUILD_WRKSRC= ${WRKSRC}/adb INSTALL_WRKSRC= ${BUILD_WRKSRC} TEST_WRKSRC= ${BUILD_WRKSRC} CPPFLAGS+= -D_GLIBCXX_USE_C99 # XXX ports/193528 MAKEFILE= ${FILESDIR}/Makefile MAKE_ENV= BINDIR="${PREFIX}/bin" EXTRADIR="${FILESDIR}" \ FILESDIR="${DOCSDIR}" REVISION="${GH_REVISION}" ALL_TARGET= all TEST_TARGET= test PLIST_FILES= bin/adb PORTDOCS= * OPTIONS_DEFINE+=BASH DOCS TEST OPTIONS_SUB= yes .if make(makesum) # for optional distfiles .MAKEFLAGS: WITH="${OPTIONS_DEFINE}" .endif BASH_GH_ACCOUNT= mbrubeck:bashcomp BASH_GH_PROJECT= android-completion:bashcomp BASH_GH_TAGNAME= c1b0656:bashcomp BASH_PLIST_FILES= etc/bash_completion.d/adb BASH_VARS= LICENSE+=MIT LICENSE_COMB=multi DOCS_MAKE_ARGS_OFF= FILES="" FILESDIR="" TEST_BUILD_DEPENDS+= googlemock>=1.6.0:devel/googlemock \ googletest>=1.6.0:devel/googletest TEST_ALL_TARGET= adb_test pre-install-TEST-on: do-test post-patch: # XXX Hidden by poudriere/tinderbox, see lindev(4) for FreeBSD < 11.0 @if [ ! -e /dev/full ]; then \ ${REINPLACE_CMD} -e '/TEST/s/[^ ]*ENOSPC/DISABLED_&/' \ ${WRKSRC}/adb/adb_io_test.cpp; \ fi post-install-BASH-on: ${MKDIR} ${STAGEDIR}${PREFIX}/${BASH_PLIST_FILES:H} ${INSTALL_DATA} ${WRKSRC_bashcomp}/android \ ${STAGEDIR}${PREFIX}/${BASH_PLIST_FILES} update-revision: # https://developer.github.com/v3/repos/commits/#get-a-single-commit # Pretend to be curl(1) for pretty-printed JSON to help parse with sed(1) @${REINPLACE_CMD} -i '' -e "/^GH_REVISION.*$@/s/=.*/= $$(\ ${SETENV} HTTP_USER_AGENT=curl ${FETCH_CMD} -qo- \ https://api.github.com/repos/${GH_ACCOUNT}/${GH_PROJECT}/commits/${GH_TAGNAME} | \ ${SED} -n '/sha/ { s/.*\"\([0-9a-f]\{12\}\).*/\1/p; q; }' \ ) # generated by: make $@/" \ ${.CURDIR}/Makefile .include # XXX Work around !target(makesum) .ifndef DISTVERSIONSUFFIX makesum: update-revision .endif Index: head/devel/android-tools-adb-devel/Makefile =================================================================== --- head/devel/android-tools-adb-devel/Makefile (revision 444003) +++ head/devel/android-tools-adb-devel/Makefile (revision 444004) @@ -1,34 +1,42 @@ # $FreeBSD$ -# Hint: git describe --abbrev=12 --match android-n-preview-5 -DISTVERSION= n-preview-5-3582 -DISTVERSIONSUFFIX= -gdfd30c4a169e +# Hint: git describe --abbrev=12 --match android-o-preview-2 +DISTVERSION= o-preview-2-332 +DISTVERSIONSUFFIX= -gd1e9e7bc06f0 PORTREVISION= 0 PKGNAMESUFFIX= -devel CONFLICTS_INSTALL= ${PORTNAME}-[0-9]* MASTERDIR= ${.CURDIR}/../android-tools-adb DISTINFO_FILE= ${.CURDIR}/distinfo FILESDIR= ${.CURDIR}/files EXTRA_PATCHES= ${.CURDIR}/files/patch-* GH_MYTAG= ${DISTVERSIONPREFIX}${DISTVERSION:C/-[0-9]*$//} -OPTIONS_DEFINE= TEST_PYTHON +USES= compiler:c++14-lang +OPTIONS_DEFAULT=MDNSRESPONDER +OPTIONS_DEFINE= MDNSRESPONDER TEST_PYTHON + +MDNSRESPONDER_LIB_DEPENDS= libdns_sd.so:net/mDNSResponder +MDNSRESPONDER_USES= localbase:ldflags +MDNSRESPONDER_LDFLAGS= -ldns_sd +MDNSRESPONDER_MAKE_ENV_OFF= MDNSEXT=_unsupported + TEST_BROKEN= logging.* tests always fail after 4e5fd111d84d TEST_PYTHON_DESC= ${TEST_DESC:S/tests/python &/} TEST_PYTHON_GH_PROJECT= platform_development:development -TEST_PYTHON_GH_TAGNAME= ${GH_MYTAG}-14-g735aab1:development +TEST_PYTHON_GH_TAGNAME= ${GH_MYTAG}-83-gc5efdcc74:development TEST_PYTHON_BUILD_DEPENDS=${PYTHON_PKGNAMEPREFIX}mock>0:devel/py-mock TEST_PYTHON_USES= python:2.7,build pre-install-TEST_PYTHON-on: # XXX python tests may leave behind running adb server ${SETENV} PATH=${BUILD_WRKSRC}:${PATH} \ PYTHONPATH=${WRKSRC_development}/python-packages \ ${PYTHON_CMD} -m unittest discover -vs ${BUILD_WRKSRC} .include "${MASTERDIR}/Makefile" Index: head/devel/android-tools-adb-devel/distinfo =================================================================== --- head/devel/android-tools-adb-devel/distinfo (revision 444003) +++ head/devel/android-tools-adb-devel/distinfo (revision 444004) @@ -1,7 +1,7 @@ -TIMESTAMP = 1474960220 -SHA256 (android-platform_system_core-android-n-preview-5-3582-gdfd30c4a169e_GH0.tar.gz) = 2a4530432d51797fcc426b737d66b411d7ba4635afabe32b0c89cb581b19bc34 -SIZE (android-platform_system_core-android-n-preview-5-3582-gdfd30c4a169e_GH0.tar.gz) = 1464524 +TIMESTAMP = 1497955827 +SHA256 (android-platform_system_core-android-o-preview-2-332-gd1e9e7bc06f0_GH0.tar.gz) = 212dd9cbca65a167b3833e5077b1a9f2db3a50a04e637da3e0db7814f60cf9fd +SIZE (android-platform_system_core-android-o-preview-2-332-gd1e9e7bc06f0_GH0.tar.gz) = 5188822 SHA256 (mbrubeck-android-completion-c1b0656_GH0.tar.gz) = ca3311ba47a5edd56c929ac9aae57c02c2c3f1636519c5f67abb00b6e3ecd75c SIZE (mbrubeck-android-completion-c1b0656_GH0.tar.gz) = 5967 -SHA256 (android-platform_development-android-n-preview-5-14-g735aab1_GH0.tar.gz) = e3559503f88e0dc3f0fa3e04cd11b0666538c64a24275fc39af951b74e50f32c -SIZE (android-platform_development-android-n-preview-5-14-g735aab1_GH0.tar.gz) = 149193336 +SHA256 (android-platform_development-android-o-preview-2-83-gc5efdcc74_GH0.tar.gz) = d04393be7996dab127ede5f63b1722bead796a41f116ecb44f8367f8270ffe4c +SIZE (android-platform_development-android-o-preview-2-83-gc5efdcc74_GH0.tar.gz) = 93000818 Index: head/devel/android-tools-adb-devel/files/patch-adb_mutex =================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_mutex (revision 444003) +++ head/devel/android-tools-adb-devel/files/patch-adb_mutex (nonexistent) @@ -1,995 +0,0 @@ -Revert 0cd3ae1c281f until usb_libusb.cpp adopts 812f030477bc. - -diff --git adb/adb_utils.cpp adb/adb_utils.cpp -index db39ef4..5a3b401 100644 ---- adb/adb_utils.cpp -+++ adb/adb_utils.cpp -@@ -26,7 +26,6 @@ - #include - - #include --#include - #include - - #include -@@ -48,6 +47,8 @@ - #include - #endif - -+ADB_MUTEX_DEFINE(basename_lock); -+ADB_MUTEX_DEFINE(dirname_lock); - - #if defined(_WIN32) - constexpr char kNullFileName[] = "NUL"; -@@ -101,15 +102,13 @@ - } - - std::string adb_basename(const std::string& path) { -- static std::mutex& basename_lock = *new std::mutex(); -- - // Copy path because basename may modify the string passed in. - std::string result(path); - - // Use lock because basename() may write to a process global and return a - // pointer to that. Note that this locking strategy only works if all other -- // callers to basename in the process also grab this same lock. -- std::lock_guard lock(basename_lock); -+ // callers to dirname in the process also grab this same lock. -+ adb_mutex_lock(&basename_lock); - - // Note that if std::string uses copy-on-write strings, &str[0] will cause - // the copy to be made, so there is no chance of us accidentally writing to -@@ -120,19 +119,19 @@ - // before leaving the lock. - result.assign(name); - -+ adb_mutex_unlock(&basename_lock); -+ - return result; - } - - std::string adb_dirname(const std::string& path) { -- static std::mutex& dirname_lock = *new std::mutex(); -- - // Copy path because dirname may modify the string passed in. - std::string result(path); - - // Use lock because dirname() may write to a process global and return a - // pointer to that. Note that this locking strategy only works if all other - // callers to dirname in the process also grab this same lock. -- std::lock_guard lock(dirname_lock); -+ adb_mutex_lock(&dirname_lock); - - // Note that if std::string uses copy-on-write strings, &str[0] will cause - // the copy to be made, so there is no chance of us accidentally writing to -@@ -143,6 +142,8 @@ - // before leaving the lock. - result.assign(parent); - -+ adb_mutex_unlock(&dirname_lock); -+ - return result; - } - -diff --git adb/client/main.cpp adb/client/main.cpp -index 571c227..279bb70 100644 ---- adb/client/main.cpp -+++ adb/client/main.cpp -@@ -170,6 +170,7 @@ - } - - int main(int argc, char** argv) { -+ adb_sysdeps_init(); - adb_trace_init(argv); - return adb_commandline(argc - 1, const_cast(argv + 1)); - } -diff --git adb/mutex_list.h adb/mutex_list.h -deleted file mode 100644 -index 4a188ee..0000000 ---- /dev/null -+++ adb/mutex_list.h -@@ -0,0 +1,17 @@ -+/* the list of mutexes used by adb */ -+/* #ifndef __MUTEX_LIST_H -+ * Do not use an include-guard. This file is included once to declare the locks -+ * and once in win32 to actually do the runtime initialization. -+ */ -+#ifndef ADB_MUTEX -+#error ADB_MUTEX not defined when including this file -+#endif -+ADB_MUTEX(basename_lock) -+ADB_MUTEX(dirname_lock) -+ADB_MUTEX(transport_lock) -+#if ADB_HOST -+ADB_MUTEX(local_transports_lock) -+#endif -+ADB_MUTEX(usb_lock) -+ -+#undef ADB_MUTEX -diff --git adb/sysdeps.h adb/sysdeps.h -index 8d99722..3ed589c 100644 ---- adb/sysdeps.h -+++ adb/sysdeps.h -@@ -97,6 +97,27 @@ - return c == '\\' || c == '/'; - } - -+typedef CRITICAL_SECTION adb_mutex_t; -+ -+#define ADB_MUTEX_DEFINE(x) adb_mutex_t x -+ -+/* declare all mutexes */ -+/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */ -+#define ADB_MUTEX(x) extern adb_mutex_t x; -+#include "mutex_list.h" -+ -+extern void adb_sysdeps_init(void); -+ -+static __inline__ void adb_mutex_lock( adb_mutex_t* lock ) -+{ -+ EnterCriticalSection( lock ); -+} -+ -+static __inline__ void adb_mutex_unlock( adb_mutex_t* lock ) -+{ -+ LeaveCriticalSection( lock ); -+} -+ - typedef void (*adb_thread_func_t)(void* arg); - typedef HANDLE adb_thread_t; - -@@ -455,6 +476,27 @@ - return c == '/'; - } - -+typedef pthread_mutex_t adb_mutex_t; -+ -+#define ADB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER -+#define adb_mutex_init pthread_mutex_init -+#define adb_mutex_lock pthread_mutex_lock -+#define adb_mutex_unlock pthread_mutex_unlock -+#define adb_mutex_destroy pthread_mutex_destroy -+ -+#define ADB_MUTEX_DEFINE(m) adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER -+ -+#define adb_cond_t pthread_cond_t -+#define adb_cond_init pthread_cond_init -+#define adb_cond_wait pthread_cond_wait -+#define adb_cond_broadcast pthread_cond_broadcast -+#define adb_cond_signal pthread_cond_signal -+#define adb_cond_destroy pthread_cond_destroy -+ -+/* declare all mutexes */ -+#define ADB_MUTEX(x) extern adb_mutex_t x; -+#include "mutex_list.h" -+ - static __inline__ void close_on_exec(int fd) - { - fcntl( fd, F_SETFD, FD_CLOEXEC ); -@@ -776,6 +818,10 @@ - #undef mkdir - #define mkdir ___xxx_mkdir - -+static __inline__ void adb_sysdeps_init(void) -+{ -+} -+ - static __inline__ int adb_is_absolute_host_path(const char* path) { - return path[0] == '/'; - } -diff --git adb/sysdeps_test.cpp adb/sysdeps_test.cpp -index f871675..9f77942 100644 ---- adb/sysdeps_test.cpp -+++ adb/sysdeps_test.cpp -@@ -269,6 +269,17 @@ - m.unlock(); - } - -+// Our implementation on Windows aborts on double lock. -+#if defined(_WIN32) -+TEST(sysdeps_mutex, mutex_reentrant_lock) { -+ std::mutex &m = *new std::mutex(); -+ -+ m.lock(); -+ ASSERT_FALSE(m.try_lock()); -+ EXPECT_DEATH(m.lock(), "non-recursive mutex locked reentrantly"); -+} -+#endif -+ - TEST(sysdeps_mutex, recursive_mutex_smoke) { - static std::recursive_mutex &m = *new std::recursive_mutex(); - -diff --git adb/sysdeps_win32.cpp adb/sysdeps_win32.cpp -index 5fda27b..4dd549d 100644 ---- adb/sysdeps_win32.cpp -+++ adb/sysdeps_win32.cpp -@@ -27,7 +27,6 @@ - - #include - #include --#include - #include - #include - #include -@@ -138,7 +137,7 @@ - #define WIN32_FH_BASE 2048 - #define WIN32_MAX_FHS 2048 - --static std::mutex& _win32_lock = *new std::mutex(); -+static adb_mutex_t _win32_lock; - static FHRec _win32_fhs[ WIN32_MAX_FHS ]; - static int _win32_fh_next; // where to start search for free FHRec - -@@ -183,24 +182,27 @@ - { - FH f = NULL; - -- std::lock_guard lock(_win32_lock); -+ adb_mutex_lock( &_win32_lock ); - - for (int i = _win32_fh_next; i < WIN32_MAX_FHS; ++i) { - if (_win32_fhs[i].clazz == NULL) { - f = &_win32_fhs[i]; - _win32_fh_next = i + 1; -- f->clazz = clazz; -- f->used = 1; -- f->eof = 0; -- f->name[0] = '\0'; -- clazz->_fh_init(f); -- return f; -+ goto Exit; - } - } -- -- D("_fh_alloc: no more free file descriptors"); -- errno = EMFILE; // Too many open files -- return nullptr; -+ D( "_fh_alloc: no more free file descriptors" ); -+ errno = EMFILE; // Too many open files -+Exit: -+ if (f) { -+ f->clazz = clazz; -+ f->used = 1; -+ f->eof = 0; -+ f->name[0] = '\0'; -+ clazz->_fh_init(f); -+ } -+ adb_mutex_unlock( &_win32_lock ); -+ return f; - } - - -@@ -209,7 +211,7 @@ - { - // Use lock so that closing only happens once and so that _fh_alloc can't - // allocate a FH that we're in the middle of closing. -- std::lock_guard lock(_win32_lock); -+ adb_mutex_lock(&_win32_lock); - - int offset = f - _win32_fhs; - if (_win32_fh_next > offset) { -@@ -223,6 +225,7 @@ - f->used = 0; - f->clazz = NULL; - } -+ adb_mutex_unlock(&_win32_lock); - return 0; - } - -@@ -1231,6 +1234,17 @@ - return true; - } - -+static adb_mutex_t g_console_output_buffer_lock; -+ -+void -+adb_sysdeps_init( void ) -+{ -+#define ADB_MUTEX(x) InitializeCriticalSection( & x ); -+#include "mutex_list.h" -+ InitializeCriticalSection( &_win32_lock ); -+ InitializeCriticalSection( &g_console_output_buffer_lock ); -+} -+ - /**************************************************************************/ - /**************************************************************************/ - /***** *****/ -@@ -2423,13 +2437,12 @@ - // Bytes that have not yet been output to the console because they are incomplete UTF-8 sequences. - // Note that we use only one buffer even though stderr and stdout are logically separate streams. - // This matches the behavior of Linux. -+// Protected by g_console_output_buffer_lock. -+static auto& g_console_output_buffer = *new std::vector(); - - // Internal helper function to write UTF-8 bytes to a console. Returns -1 on error. - static int _console_write_utf8(const char* const buf, const size_t buf_size, FILE* stream, - HANDLE console) { -- static std::mutex& console_output_buffer_lock = *new std::mutex(); -- static auto& console_output_buffer = *new std::vector(); -- - const int saved_errno = errno; - std::vector combined_buffer; - -@@ -2437,25 +2450,24 @@ - const char* utf8; - size_t utf8_size; - -- { -- std::lock_guard lock(console_output_buffer_lock); -- if (console_output_buffer.empty()) { -- // If console_output_buffer doesn't have a buffered up incomplete UTF-8 sequence (the -- // common case with plain ASCII), parse buf directly. -- utf8 = buf; -- utf8_size = internal::ParseCompleteUTF8(buf, buf + buf_size, &console_output_buffer); -- } else { -- // If console_output_buffer has a buffered up incomplete UTF-8 sequence, move it to -- // combined_buffer (and effectively clear console_output_buffer) and append buf to -- // combined_buffer, then parse it all together. -- combined_buffer.swap(console_output_buffer); -- combined_buffer.insert(combined_buffer.end(), buf, buf + buf_size); -- -- utf8 = combined_buffer.data(); -- utf8_size = internal::ParseCompleteUTF8(utf8, utf8 + combined_buffer.size(), -- &console_output_buffer); -- } -+ adb_mutex_lock(&g_console_output_buffer_lock); -+ if (g_console_output_buffer.empty()) { -+ // If g_console_output_buffer doesn't have a buffered up incomplete UTF-8 sequence (the -+ // common case with plain ASCII), parse buf directly. -+ utf8 = buf; -+ utf8_size = internal::ParseCompleteUTF8(buf, buf + buf_size, &g_console_output_buffer); -+ } else { -+ // If g_console_output_buffer has a buffered up incomplete UTF-8 sequence, move it to -+ // combined_buffer (and effectively clear g_console_output_buffer) and append buf to -+ // combined_buffer, then parse it all together. -+ combined_buffer.swap(g_console_output_buffer); -+ combined_buffer.insert(combined_buffer.end(), buf, buf + buf_size); -+ -+ utf8 = combined_buffer.data(); -+ utf8_size = internal::ParseCompleteUTF8(utf8, utf8 + combined_buffer.size(), -+ &g_console_output_buffer); - } -+ adb_mutex_unlock(&g_console_output_buffer_lock); - - std::wstring utf16; - -diff --git adb/transport.cpp adb/transport.cpp -index 3eaeb06..87712fc 100644 ---- adb/transport.cpp -+++ adb/transport.cpp -@@ -28,7 +28,6 @@ - - #include - #include --#include - - #include - #include -@@ -45,7 +44,7 @@ - static auto& transport_list = *new std::list(); - static auto& pending_list = *new std::list(); - --static std::mutex& transport_lock = *new std::mutex(); -+ADB_MUTEX_DEFINE( transport_lock ); - - const char* const kFeatureShell2 = "shell_v2"; - const char* const kFeatureCmd = "cmd"; -@@ -298,12 +297,13 @@ - } - - void kick_transport(atransport* t) { -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - // As kick_transport() can be called from threads without guarantee that t is valid, - // check if the transport is in transport_list first. - if (std::find(transport_list.begin(), transport_list.end(), t) != transport_list.end()) { - t->Kick(); - } -+ adb_mutex_unlock(&transport_lock); - } - - static int transport_registration_send = -1; -@@ -333,7 +333,7 @@ - device_tracker** pnode = &device_tracker_list; - device_tracker* node = *pnode; - -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock( &transport_lock ); - while (node) { - if (node == tracker) { - *pnode = node->next; -@@ -342,6 +342,7 @@ - pnode = &node->next; - node = *pnode; - } -+ adb_mutex_unlock( &transport_lock ); - } - - static void -@@ -503,10 +504,9 @@ - fdevent_remove(&(t->transport_fde)); - adb_close(t->fd); - -- { -- std::lock_guard lock(transport_lock); -- transport_list.remove(t); -- } -+ adb_mutex_lock(&transport_lock); -+ transport_list.remove(t); -+ adb_mutex_unlock(&transport_lock); - - if (t->product) - free(t->product); -@@ -555,11 +555,10 @@ - } - } - -- { -- std::lock_guard lock(transport_lock); -- pending_list.remove(t); -- transport_list.push_front(t); -- } -+ adb_mutex_lock(&transport_lock); -+ pending_list.remove(t); -+ transport_list.push_front(t); -+ adb_mutex_unlock(&transport_lock); - - update_transports(); - } -@@ -610,8 +609,7 @@ - - static void transport_unref(atransport* t) { - CHECK(t != nullptr); -- -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - CHECK_GT(t->ref_count, 0u); - t->ref_count--; - if (t->ref_count == 0) { -@@ -621,6 +619,7 @@ - } else { - D("transport: %s unref (count=%zu)", t->serial, t->ref_count); - } -+ adb_mutex_unlock(&transport_lock); - } - - static int qual_match(const char *to_test, -@@ -666,7 +665,7 @@ - *error_out = "no devices found"; - } - -- std::unique_lock lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (const auto& t : transport_list) { - if (t->connection_state == kCsNoPerm) { - #if ADB_HOST -@@ -714,7 +713,7 @@ - } - } - } -- lock.unlock(); -+ adb_mutex_unlock(&transport_lock); - - // Don't return unauthorized devices; the caller can't do anything with them. - if (result && result->connection_state == kCsUnauthorized) { -@@ -915,20 +914,21 @@ - - std::string list_transports(bool long_listing) { - std::string result; -- -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (const auto& t : transport_list) { - append_transport(t, &result, long_listing); - } -+ adb_mutex_unlock(&transport_lock); - return result; - } - - /* hack for osx */ - void close_usb_devices() { -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (const auto& t : transport_list) { - t->Kick(); - } -+ adb_mutex_unlock(&transport_lock); - } - #endif // ADB_HOST - -@@ -947,9 +947,10 @@ - return -1; - } - -- std::unique_lock lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (const auto& transport : pending_list) { - if (transport->serial && strcmp(serial, transport->serial) == 0) { -+ adb_mutex_unlock(&transport_lock); - VLOG(TRANSPORT) << "socket transport " << transport->serial - << " is already in pending_list and fails to register"; - delete t; -@@ -959,6 +960,7 @@ - - for (const auto& transport : transport_list) { - if (transport->serial && strcmp(serial, transport->serial) == 0) { -+ adb_mutex_unlock(&transport_lock); - VLOG(TRANSPORT) << "socket transport " << transport->serial - << " is already in transport_list and fails to register"; - delete t; -@@ -968,8 +970,7 @@ - - pending_list.push_front(t); - t->serial = strdup(serial); -- -- lock.unlock(); -+ adb_mutex_unlock(&transport_lock); - - register_transport(t); - return 0; -@@ -979,19 +980,20 @@ - atransport *find_transport(const char *serial) { - atransport* result = nullptr; - -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (auto& t : transport_list) { - if (t->serial && strcmp(serial, t->serial) == 0) { - result = t; - break; - } - } -+ adb_mutex_unlock(&transport_lock); - - return result; - } - - void kick_all_tcp_devices() { -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - for (auto& t : transport_list) { - if (t->IsTcpDevice()) { - // Kicking breaks the read_transport thread of this transport out of any read, then -@@ -1001,6 +1003,7 @@ - t->Kick(); - } - } -+ adb_mutex_unlock(&transport_lock); - } - - #endif -@@ -1020,20 +1023,20 @@ - t->devpath = strdup(devpath); - } - -- { -- std::lock_guard lock(transport_lock); -- pending_list.push_front(t); -- } -+ adb_mutex_lock(&transport_lock); -+ pending_list.push_front(t); -+ adb_mutex_unlock(&transport_lock); - - register_transport(t); - } - - // This should only be used for transports with connection_state == kCsNoPerm. - void unregister_usb_transport(usb_handle *usb) { -- std::lock_guard lock(transport_lock); -+ adb_mutex_lock(&transport_lock); - transport_list.remove_if([usb](atransport* t) { - return t->usb == usb && t->connection_state == kCsNoPerm; - }); -+ adb_mutex_unlock(&transport_lock); - } - - int check_header(apacket *p, atransport *t) -diff --git adb/transport_local.cpp adb/transport_local.cpp -index 89e950d..f895943 100644 ---- adb/transport_local.cpp -+++ adb/transport_local.cpp -@@ -26,7 +26,6 @@ - #include - - #include --#include - #include - - #include -@@ -48,7 +47,7 @@ - // connected. - #define ADB_LOCAL_TRANSPORT_MAX 16 - --static std::mutex& local_transports_lock = *new std::mutex(); -+ADB_MUTEX_DEFINE(local_transports_lock); - - /* we keep a list of opened transports. The atransport struct knows to which - * local transport it is connected. The list is used to detect when we're -@@ -385,13 +384,14 @@ - - #if ADB_HOST - int nn; -- std::lock_guard lock(local_transports_lock); -+ adb_mutex_lock( &local_transports_lock ); - for (nn = 0; nn < ADB_LOCAL_TRANSPORT_MAX; nn++) { - if (local_transports[nn] == t) { - local_transports[nn] = NULL; - break; - } - } -+ adb_mutex_unlock( &local_transports_lock ); - #endif - } - -@@ -435,8 +435,9 @@ - - atransport* find_emulator_transport_by_adb_port(int adb_port) - { -- std::lock_guard lock(local_transports_lock); -+ adb_mutex_lock( &local_transports_lock ); - atransport* result = find_emulator_transport_by_adb_port_locked(adb_port); -+ adb_mutex_unlock( &local_transports_lock ); - return result; - } - -@@ -454,8 +455,9 @@ - - int get_available_local_transport_index() - { -- std::lock_guard lock(local_transports_lock); -+ adb_mutex_lock( &local_transports_lock ); - int result = get_available_local_transport_index_locked(); -+ adb_mutex_unlock( &local_transports_lock ); - return result; - } - #endif -@@ -475,20 +477,26 @@ - - #if ADB_HOST - if (local) { -- std::lock_guard lock(local_transports_lock); -- t->SetLocalPortForEmulator(adb_port); -- atransport* existing_transport = find_emulator_transport_by_adb_port_locked(adb_port); -- int index = get_available_local_transport_index_locked(); -- if (existing_transport != NULL) { -- D("local transport for port %d already registered (%p)?", adb_port, existing_transport); -- fail = -1; -- } else if (index < 0) { -- // Too many emulators. -- D("cannot register more emulators. Maximum is %d", ADB_LOCAL_TRANSPORT_MAX); -- fail = -1; -- } else { -- local_transports[index] = t; -- } -+ adb_mutex_lock( &local_transports_lock ); -+ { -+ t->SetLocalPortForEmulator(adb_port); -+ atransport* existing_transport = -+ find_emulator_transport_by_adb_port_locked(adb_port); -+ int index = get_available_local_transport_index_locked(); -+ if (existing_transport != NULL) { -+ D("local transport for port %d already registered (%p)?", -+ adb_port, existing_transport); -+ fail = -1; -+ } else if (index < 0) { -+ // Too many emulators. -+ D("cannot register more emulators. Maximum is %d", -+ ADB_LOCAL_TRANSPORT_MAX); -+ fail = -1; -+ } else { -+ local_transports[index] = t; -+ } -+ } -+ adb_mutex_unlock( &local_transports_lock ); - } - #endif - return fail; -diff --git adb/transport_test.cpp adb/transport_test.cpp -index a6db07a..8b38e03 100644 ---- adb/transport_test.cpp -+++ adb/transport_test.cpp -@@ -20,6 +20,27 @@ - - #include "adb.h" - -+class TransportSetup { -+public: -+ TransportSetup() { -+#ifdef _WIN32 -+ // Use extern instead of including sysdeps.h which brings in various macros -+ // that conflict with APIs used in this file. -+ extern void adb_sysdeps_init(void); -+ adb_sysdeps_init(); -+#else -+ // adb_sysdeps_init() is an inline function that we cannot link against. -+#endif -+ } -+}; -+ -+// Static initializer will call adb_sysdeps_init() before main() to initialize -+// the transport mutex before it is used in the tests. Alternatives would be to -+// use __attribute__((constructor)) here or to use that or a static initializer -+// for adb_sysdeps_init() itself in sysdeps_win32.cpp (caveats of unclear -+// init order), or to use a test fixture whose SetUp() could do the init once. -+static TransportSetup g_TransportSetup; -+ - TEST(transport, kick_transport) { - atransport t; - static size_t kick_count; -diff --git adb/usb_linux_client.cpp adb/usb_linux_client.cpp -index 0ba6b4b..1b05439 100644 ---- adb/usb_linux_client.cpp -+++ adb/usb_linux_client.cpp -@@ -32,8 +32,6 @@ - - #include - #include --#include --#include - - #include - -@@ -56,14 +54,12 @@ - - static int dummy_fd = -1; - --struct usb_handle { -- usb_handle() : kicked(false) { -- } -- -- std::condition_variable notify; -- std::mutex lock; -+struct usb_handle -+{ -+ adb_cond_t notify; -+ adb_mutex_t lock; -+ bool open_new_connection; - std::atomic kicked; -- bool open_new_connection = true; - - int (*write)(usb_handle *h, const void *data, int len); - int (*read)(usb_handle *h, void *data, int len); -@@ -71,12 +67,12 @@ - void (*close)(usb_handle *h); - - // Legacy f_adb -- int fd = -1; -+ int fd; - - // FunctionFS -- int control = -1; -- int bulk_out = -1; /* "out" from the host's perspective => source for adbd */ -- int bulk_in = -1; /* "in" from the host's perspective => sink for adbd */ -+ int control; -+ int bulk_out; /* "out" from the host's perspective => source for adbd */ -+ int bulk_in; /* "in" from the host's perspective => sink for adbd */ - }; - - struct func_desc { -@@ -252,12 +248,12 @@ - - while (true) { - // wait until the USB device needs opening -- std::unique_lock lock(usb->lock); -+ adb_mutex_lock(&usb->lock); - while (!usb->open_new_connection) { -- usb->notify.wait(lock); -+ adb_cond_wait(&usb->notify, &usb->lock); - } - usb->open_new_connection = false; -- lock.unlock(); -+ adb_mutex_unlock(&usb->lock); - - D("[ usb_thread - opening device ]"); - do { -@@ -343,20 +339,27 @@ - h->kicked = false; - adb_close(h->fd); - // Notify usb_adb_open_thread to open a new connection. -- h->lock.lock(); -+ adb_mutex_lock(&h->lock); - h->open_new_connection = true; -- h->lock.unlock(); -- h->notify.notify_one(); -+ adb_cond_signal(&h->notify); -+ adb_mutex_unlock(&h->lock); - } - - static void usb_adb_init() - { -- usb_handle* h = new usb_handle(); -+ usb_handle* h = reinterpret_cast(calloc(1, sizeof(usb_handle))); -+ if (h == nullptr) fatal("couldn't allocate usb_handle"); - - h->write = usb_adb_write; - h->read = usb_adb_read; - h->kick = usb_adb_kick; - h->close = usb_adb_close; -+ h->kicked = false; -+ h->fd = -1; -+ -+ h->open_new_connection = true; -+ adb_cond_init(&h->notify, 0); -+ adb_mutex_init(&h->lock, 0); - - // Open the file /dev/android_adb_enable to trigger - // the enabling of the adb USB function in the kernel. -@@ -465,12 +468,12 @@ - - while (true) { - // wait until the USB device needs opening -- std::unique_lock lock(usb->lock); -+ adb_mutex_lock(&usb->lock); - while (!usb->open_new_connection) { -- usb->notify.wait(lock); -+ adb_cond_wait(&usb->notify, &usb->lock); - } - usb->open_new_connection = false; -- lock.unlock(); -+ adb_mutex_unlock(&usb->lock); - - while (true) { - if (init_functionfs(usb)) { -@@ -554,22 +557,31 @@ - adb_close(h->bulk_out); - adb_close(h->bulk_in); - // Notify usb_adb_open_thread to open a new connection. -- h->lock.lock(); -+ adb_mutex_lock(&h->lock); - h->open_new_connection = true; -- h->lock.unlock(); -- h->notify.notify_one(); -+ adb_cond_signal(&h->notify); -+ adb_mutex_unlock(&h->lock); - } - - static void usb_ffs_init() - { - D("[ usb_init - using FunctionFS ]"); - -- usb_handle* h = new usb_handle(); -+ usb_handle* h = reinterpret_cast(calloc(1, sizeof(usb_handle))); -+ if (h == nullptr) fatal("couldn't allocate usb_handle"); - - h->write = usb_ffs_write; - h->read = usb_ffs_read; - h->kick = usb_ffs_kick; - h->close = usb_ffs_close; -+ h->kicked = false; -+ h->control = -1; -+ h->bulk_out = -1; -+ h->bulk_out = -1; -+ -+ h->open_new_connection = true; -+ adb_cond_init(&h->notify, 0); -+ adb_mutex_init(&h->lock, 0); - - D("[ usb_init - starting thread ]"); - if (!adb_thread_create(usb_ffs_open_thread, h)) { -@@ -596,7 +608,6 @@ - { - return h->read(h, data, len); - } -- - int usb_close(usb_handle *h) - { - h->close(h); -diff --git adb/usb_windows.cpp adb/usb_windows.cpp -index 8ecca37..4649454 100644 ---- adb/usb_windows.cpp -+++ adb/usb_windows.cpp -@@ -19,17 +19,13 @@ - #include "sysdeps.h" - - #include // winsock.h *must* be included before windows.h. --#include --#include --#include -- -+#include - #include - #include - #include -- --#include -- --#include -+#include -+#include -+#include - - #include - -@@ -77,7 +73,7 @@ - }; - - /// Locker for the list of opened usb handles --static std::mutex& usb_lock = *new std::mutex(); -+ADB_MUTEX_DEFINE( usb_lock ); - - /// Checks if there is opened usb handle in handle_list for this device. - int known_device(const wchar_t* dev_name); -@@ -145,8 +141,9 @@ - int ret = 0; - - if (NULL != dev_name) { -- std::lock_guard lock(usb_lock); -+ adb_mutex_lock(&usb_lock); - ret = known_device_locked(dev_name); -+ adb_mutex_unlock(&usb_lock); - } - - return ret; -@@ -156,10 +153,11 @@ - if (NULL == handle) - return 0; - -- std::lock_guard lock(usb_lock); -+ adb_mutex_lock(&usb_lock); - - // Check if device is already in the list - if (known_device_locked(handle->interface_name)) { -+ adb_mutex_unlock(&usb_lock); - return 0; - } - -@@ -169,6 +167,8 @@ - handle->prev->next = handle; - handle->next->prev = handle; - -+ adb_mutex_unlock(&usb_lock); -+ - return 1; - } - -@@ -493,8 +493,11 @@ - void usb_kick(usb_handle* handle) { - D("usb_kick"); - if (NULL != handle) { -- std::lock_guard lock(usb_lock); -+ adb_mutex_lock(&usb_lock); -+ - usb_kick_locked(handle); -+ -+ adb_mutex_unlock(&usb_lock); - } else { - errno = EINVAL; - } -@@ -505,17 +508,17 @@ - - if (NULL != handle) { - // Remove handle from the list -- { -- std::lock_guard lock(usb_lock); -- -- if ((handle->next != handle) && (handle->prev != handle)) { -- handle->next->prev = handle->prev; -- handle->prev->next = handle->next; -- handle->prev = handle; -- handle->next = handle; -- } -+ adb_mutex_lock(&usb_lock); -+ -+ if ((handle->next != handle) && (handle->prev != handle)) { -+ handle->next->prev = handle->prev; -+ handle->prev->next = handle->next; -+ handle->prev = handle; -+ handle->next = handle; - } - -+ adb_mutex_unlock(&usb_lock); -+ - // Cleanup handle - usb_cleanup_handle(handle); - free(handle); -@@ -648,8 +651,9 @@ - static void kick_devices() { - // Need to acquire lock to safely walk the list which might be modified - // by another thread. -- std::lock_guard lock(usb_lock); -+ adb_mutex_lock(&usb_lock); - for (usb_handle* usb = handle_list.next; usb != &handle_list; usb = usb->next) { - usb_kick_locked(usb); - } -+ adb_mutex_unlock(&usb_lock); - } Property changes on: head/devel/android-tools-adb-devel/files/patch-adb_mutex ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/usb_libusb.cpp =================================================================== --- head/devel/android-tools-adb-devel/files/usb_libusb.cpp (revision 444003) +++ head/devel/android-tools-adb-devel/files/usb_libusb.cpp (nonexistent) @@ -1,615 +0,0 @@ -/* - * Copyright (C) 2009 bsdroid project - * Alexey Tarasov - * - * 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. - */ - -#define TRACE_TAG USB - -#include "sysdeps.h" - -#include -#include -#include -#include -#include -#include - -#include "adb.h" -#include "transport.h" - -ADB_MUTEX_DEFINE( usb_lock ); -static libusb_context *ctx = NULL; - -struct usb_handle -{ - usb_handle *prev; - usb_handle *next; - - libusb_device *dev; - libusb_device_handle *devh; - int interface; - uint8_t dev_bus; - uint8_t dev_addr; - - int zero_mask; - unsigned char end_point_address[2]; - char serial[128]; - - adb_cond_t notify; - adb_mutex_t lock; -}; - -static usb_handle handle_list = { - .prev = &handle_list, - .next = &handle_list, -}; - -static void -usb_cleanup() -{ - libusb_exit(ctx); -} - -static void -report_bulk_libusb_error(int r) -{ - switch (r) { - case LIBUSB_ERROR_TIMEOUT: - D("Transfer timeout"); - break; - - case LIBUSB_ERROR_PIPE: - D("Control request is not supported"); - break; - - case LIBUSB_ERROR_OVERFLOW: - D("Device offered more data"); - break; - - case LIBUSB_ERROR_NO_DEVICE : - D("Device was disconnected"); - break; - - default: - D("Error %d during transfer", r); - break; - }; -} - -static int -usb_bulk_write(usb_handle *uh, const void *data, int len) -{ - int r = 0; - int transferred = 0; - - r = libusb_bulk_transfer(uh->devh, uh->end_point_address[1], - (unsigned char *)data, len, &transferred, 0); - - if (r != 0) { - D("usb_bulk_write(): "); - report_bulk_libusb_error(r); - return r; - } - - return (transferred); -} - -static int -usb_bulk_read(usb_handle *uh, void *data, int len) -{ - int r = 0; - int transferred = 0; - - r = libusb_bulk_transfer(uh->devh, uh->end_point_address[0], - (unsigned char *)data, len, - &transferred, 0); - - if (r != 0) { - D("usb_bulk_read(): "); - report_bulk_libusb_error(r); - return r; - } - - return (transferred); -} - -int -usb_write(usb_handle *uh, const void *_data, int len) -{ - unsigned char *data = (unsigned char*) _data; - int n; - int need_zero = 0; - - if (uh->zero_mask == 1) { - if (!(len & uh->zero_mask)) { - need_zero = 1; - } - } - - D("usb_write(): %p:%d -> transport %p", _data, len, uh); - - while (len > 0) { - int xfer = (len > 4096) ? 4096 : len; - - n = usb_bulk_write(uh, data, xfer); - - if (n != xfer) { - D("usb_write(): failed for transport %p (%d bytes left)", uh, len); - return -1; - } - - len -= xfer; - data += xfer; - } - - if (need_zero){ - n = usb_bulk_write(uh, _data, 0); - - if (n < 0) { - D("usb_write(): failed to finish operation for transport %p", uh); - } - return n; - } - - return 0; -} - -int -usb_read(usb_handle *uh, void *_data, int len) -{ - unsigned char *data = (unsigned char*)_data; - int n; - - D("usb_read(): %p:%d <- transport %p", _data, len, uh); - - while (len > 0) { - int xfer = (len > 4096) ? 4096 : len; - - n = usb_bulk_read(uh, data, xfer); - - if (n != xfer) { - if (n > 0) { - data += n; - len -= n; - continue; - } - - D("usb_read(): failed for transport %p (%d bytes left)", uh, len); - return -1; - } - - len -= xfer; - data += xfer; - } - - return 0; -} - -int -usb_close(usb_handle *h) -{ - D("usb_close(): closing transport %p", h); - adb_mutex_lock(&usb_lock); - - h->next->prev = h->prev; - h->prev->next = h->next; - h->prev = NULL; - h->next = NULL; - - libusb_release_interface(h->devh, h->interface); - libusb_close(h->devh); - libusb_unref_device(h->dev); - - adb_mutex_unlock(&usb_lock); - - free(h); - - return (0); -} - -void -usb_kick(usb_handle *h) -{ - D("usb_kick(): kicking transport %p", h); - - adb_mutex_lock(&h->lock); - unregister_usb_transport(h); - adb_mutex_unlock(&h->lock); - - h->next->prev = h->prev; - h->prev->next = h->next; - h->prev = NULL; - h->next = NULL; - - libusb_release_interface(h->devh, h->interface); - libusb_close(h->devh); - libusb_unref_device(h->dev); - free(h); -} - -static int -check_usb_interface(libusb_interface const *interface, - libusb_device_descriptor const *desc, - usb_handle *uh) -{ - int e; - - if (interface->num_altsetting == 0) { - D("check_usb_interface(): No interface settings"); - return -1; - } - - libusb_interface_descriptor const *idesc = &interface->altsetting[0]; - - if (idesc->bNumEndpoints != 2) { - D("check_usb_interface(): Interface have not 2 endpoints, ignoring"); - return -1; - } - - for (e = 0; e < idesc->bNumEndpoints; e++) { - libusb_endpoint_descriptor const *edesc = &idesc->endpoint[e]; - - if (edesc->bmAttributes != LIBUSB_TRANSFER_TYPE_BULK) { - D("check_usb_interface(): Endpoint (%u) is not bulk (%u), ignoring", - edesc->bmAttributes, LIBUSB_TRANSFER_TYPE_BULK); - return -1; - } - - if (edesc->bEndpointAddress & LIBUSB_ENDPOINT_IN) - uh->end_point_address[0] = edesc->bEndpointAddress; - else - uh->end_point_address[1] = edesc->bEndpointAddress; - - /* aproto 01 needs 0 termination */ - if (idesc->bInterfaceProtocol == 0x01) { - uh->zero_mask = edesc->wMaxPacketSize - 1; - D("check_usb_interface(): Forced Android interface protocol v.1"); - } - } - - D("check_usb_interface(): Device: %04x:%04x " - "iclass: %x, isclass: %x, iproto: %x ep: %x/%x-> ", - desc->idVendor, desc->idProduct, idesc->bInterfaceClass, - idesc->bInterfaceSubClass, idesc->bInterfaceProtocol, - uh->end_point_address[0], uh->end_point_address[1]); - - if (!is_adb_interface(desc->idVendor, desc->idProduct, - idesc->bInterfaceClass, idesc->bInterfaceSubClass, - idesc->bInterfaceProtocol)) - { - D("not matches"); - return -1; - } - - D("matches"); - return 1; -} - -static int -check_usb_interfaces(libusb_config_descriptor *config, - libusb_device_descriptor *desc, - usb_handle *uh) -{ - int i; - - for (i = 0; i < config->bNumInterfaces; ++i) { - if (check_usb_interface(&config->interface[i], desc, uh) != -1) { - /* found some interface and saved information about it */ - D("check_usb_interfaces(): Interface %d of %04x:%04x " - "matches Android device", i, desc->idVendor, - desc->idProduct); - - return i; - } - } - - return -1; -} - -static int -register_device(usb_handle *uh, const char *serial) -{ - D("register_device(): Registering %p [%s] as USB transport", - uh, serial); - - usb_handle* usb = reinterpret_cast(calloc(1, sizeof(usb_handle))); - if (usb == nullptr) fatal("couldn't allocate usb_handle"); - memcpy(usb, uh, sizeof(usb_handle)); - strcpy(usb->serial, uh->serial); - - adb_cond_init(&usb->notify, 0); - adb_mutex_init(&usb->lock, 0); - - adb_mutex_lock(&usb_lock); - - usb->next = &handle_list; - usb->prev = handle_list.prev; - usb->prev->next = usb; - usb->next->prev = usb; - - adb_mutex_unlock(&usb_lock); - - char devpath[64]; - snprintf(devpath, sizeof(devpath), "ugen%d.%d", - uh->dev_bus, uh->dev_addr); - - register_usb_transport(usb, serial, devpath, 1); - - return (1); -} - -static int -already_registered(usb_handle *uh) -{ - usb_handle *usb = NULL; - int exists = 0; - - adb_mutex_lock(&usb_lock); - - for (usb = handle_list.next; usb != &handle_list; usb = usb->next) { - if ((usb->dev_bus == uh->dev_bus) && - (usb->dev_addr == uh->dev_addr)) - { - exists = 1; - break; - } - } - - adb_mutex_unlock(&usb_lock); - - return exists; -} - -static void -check_device(libusb_device *dev) -{ - usb_handle uh; - int i = 0; - int found = -1; - char serial[256] = {0}; - - libusb_device_descriptor desc; - libusb_config_descriptor *config = NULL; - - int r = libusb_get_device_descriptor(dev, &desc); - - if (r != LIBUSB_SUCCESS) { - D("check_device(): Failed to get device descriptor"); - return; - } - - if ((desc.idVendor == 0) && (desc.idProduct == 0)) - return; - - D("check_device(): Probing usb device %04x:%04x", - desc.idVendor, desc.idProduct); - - if (!is_adb_interface(desc.idVendor, desc.idProduct, - ADB_CLASS, ADB_SUBCLASS, ADB_PROTOCOL)) - { - D("check_device(): Ignored due unknown vendor id"); - return; - } - - uh.dev_bus = libusb_get_bus_number(dev); - uh.dev_addr = libusb_get_device_address(dev); - - if (already_registered(&uh)) { - D("check_device(): Device (bus: %d, address: %d) " - "is already registered", uh.dev_bus, uh.dev_addr); - return; - } - - D("check_device(): Device bus: %d, address: %d", - uh.dev_bus, uh.dev_addr); - - r = libusb_get_active_config_descriptor(dev, &config); - - if (r != 0) { - if (r == LIBUSB_ERROR_NOT_FOUND) { - D("check_device(): Device %4x:%4x is unconfigured", - desc.idVendor, desc.idProduct); - return; - } - - D("check_device(): Failed to get configuration for %4x:%4x", - desc.idVendor, desc.idProduct); - return; - } - - if (config == NULL) { - D("check_device(): Sanity check failed after " - "getting active config"); - return; - } - - if (config->interface != NULL) { - found = check_usb_interfaces(config, &desc, &uh); - } - - /* not needed anymore */ - libusb_free_config_descriptor(config); - - r = libusb_open(dev, &uh.devh); - uh.dev = dev; - - if (r != 0) { - switch (r) { - case LIBUSB_ERROR_NO_MEM: - D("check_device(): Memory allocation problem"); - break; - - case LIBUSB_ERROR_ACCESS: - D("check_device(): Permissions problem, " - "current user priveleges are messed up?"); - break; - - case LIBUSB_ERROR_NO_DEVICE: - D("check_device(): Device disconected, bad cable?"); - break; - - default: - D("check_device(): libusb triggered error %d", r); - } - // skip rest - found = -1; - } - - if (found >= 0) { - D("check_device(): Device matches Android interface"); - // read the device's serial number - memset(serial, 0, sizeof(serial)); - uh.interface = found; - - r = libusb_claim_interface(uh.devh, uh.interface); - - if (r < 0) { - D("check_device(): Failed to claim interface %d", - uh.interface); - - goto fail; - } - - if (desc.iSerialNumber != 0) { - libusb_get_string_descriptor_ascii(uh.devh, desc.iSerialNumber, - (unsigned char *)uh.serial, sizeof(uh.serial)); - } - if (register_device(&uh, uh.serial) == 0) { - D("check_device(): Failed to register device\n"); - goto fail_interface; - } - } - - return; - -fail_interface: - libusb_release_interface(uh.devh, uh.interface); - -fail: - libusb_close(uh.devh); - uh.devh = NULL; -} - -static int -check_device_connected(usb_handle *uh) -{ - int r = libusb_kernel_driver_active(uh->devh, uh->interface); - - if (r == LIBUSB_ERROR_NO_DEVICE) - return 0; - - if (r < 0) - return -1; - - return 1; -} - -static void -kick_disconnected() -{ - usb_handle *usb = NULL; - - adb_mutex_lock(&usb_lock); - - for (usb = handle_list.next; usb != &handle_list; usb = usb->next) { - if (check_device_connected(usb) == 0) { - D("kick_disconnected(): Transport %p is not online anymore", - usb); - - usb_kick(usb); - } - } - - adb_mutex_unlock(&usb_lock); -} - -static void -scan_usb_devices() -{ - D("scan_usb_devices(): started"); - - libusb_device **devs= NULL; - libusb_device *dev= NULL; - ssize_t cnt = libusb_get_device_list(ctx, &devs); - - if (cnt < 0) { - D("scan_usb_devices(): Failed to get device list (error: %zd)", - cnt); - - return; - } - - int i = 0; - - while ((dev = devs[i++]) != NULL) { - check_device(dev); - } - - libusb_free_device_list(devs, 1); -} - -static void -device_poll_thread(void*) -{ - adb_thread_setname("USB scan"); - D("device_poll_thread(): Created USB scan thread"); - - for (;;) { - sleep(5); - kick_disconnected(); - scan_usb_devices(); - } -} - -static void -sigalrm_handler(int signo) -{ - /* nothing */ -} - -void -usb_init() -{ - D("usb_init(): started"); - struct sigaction actions; - - atexit(usb_cleanup); - int r = libusb_init(&ctx); - - if (r != LIBUSB_SUCCESS) { - fatal_errno("Failed to init libusb"); - } - - memset(&actions, 0, sizeof(actions)); - - sigemptyset(&actions.sa_mask); - - actions.sa_flags = 0; - actions.sa_handler = sigalrm_handler; - - sigaction(SIGALRM, &actions, NULL); - - /* initial device scan */ - scan_usb_devices(); - - /* starting USB event polling thread */ - if (!adb_thread_create(device_poll_thread, nullptr)) { - fatal_errno("cannot create USB scan thread"); - } - - D("usb_init(): finished"); -} Property changes on: head/devel/android-tools-adb-devel/files/usb_libusb.cpp ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/Makefile =================================================================== --- head/devel/android-tools-adb-devel/files/Makefile (revision 444003) +++ head/devel/android-tools-adb-devel/files/Makefile (revision 444004) @@ -1,150 +1,156 @@ # $FreeBSD$ PROG_CXX=adb NO_MAN= BINDIR?=/usr/bin FILESDIR?=${DOCDIR}/${PROG} FILES= *.[Tt][Xx][Tt] SRCS+= adb.cpp -SRCS+= adb_auth.cpp SRCS+= adb_auth_host.cpp SRCS+= adb_client.cpp SRCS+= adb_io.cpp SRCS+= adb_listeners.cpp SRCS+= adb_trace.cpp SRCS+= adb_utils.cpp SRCS+= bugreport.cpp SRCS+= commandline.cpp SRCS+= console.cpp SRCS+= diagnose_usb.cpp SRCS+= fdevent.cpp SRCS+= file_sync_client.cpp SRCS+= line_printer.cpp SRCS+= services.cpp SRCS+= shell_service_protocol.cpp SRCS+= socket_spec.cpp SRCS+= ../adb/sockets.cpp SRCS+= sysdeps_unix.cpp SRCS+= transport.cpp SRCS+= transport_local.cpp +SRCS+= transport_mdns${MDNSEXT}.cpp SRCS+= transport_usb.cpp TEST_SRCS+= adb_io_test.cpp TEST_SRCS+= adb_listeners_test.cpp TEST_SRCS+= adb_utils_test.cpp TEST_SRCS+= bugreport_test.cpp TEST_SRCS+= fdevent_test.cpp TEST_SRCS+= shell_service_protocol_test.cpp TEST_SRCS+= socket_spec_test.cpp TEST_SRCS+= socket_test.cpp TEST_SRCS+= sysdeps_test.cpp TEST_SRCS+= transport_test.cpp .PATH: ${.CURDIR}/client SRCS+= main.cpp +SRCS+= usb_libusb.cpp .PATH: ${.CURDIR}/sysdeps +SRCS+= errno.cpp TEST_SRCS+= stat_test.cpp -.PATH: ${EXTRADIR} -SRCS+= usb_libusb.cpp +.PATH: ${.CURDIR}/sysdeps/posix +SRCS+= network.cpp .PATH: ${.CURDIR}/../base SRCS+= file.cpp SRCS+= logging.cpp SRCS+= parsenetaddress.cpp +SRCS+= quick_exit.cpp SRCS+= stringprintf.cpp SRCS+= strings.cpp TEST_SRCS+= file_test.cpp TEST_SRCS+= logging_test.cpp TEST_SRCS+= parsenetaddress_test.cpp +TEST_SRCS+= quick_exit_test.cpp TEST_SRCS+= stringprintf_test.cpp TEST_SRCS+= strings_test.cpp TEST_SRCS+= test_main.cpp TEST_SRCS+= test_utils.cpp .PATH: ${.CURDIR}/../libcrypto_utils SRCS+= android_pubkey.c .PATH: ${.CURDIR}/../libcrypto_utils/tests TEST_SRCS+= android_pubkey_test.cpp .PATH: ${.CURDIR}/../libcutils SRCS+= socket_inaddr_any_server_unix.c SRCS+= socket_local_client_unix.c SRCS+= socket_local_server_unix.c -SRCS+= socket_loopback_client_unix.c -SRCS+= socket_loopback_server_unix.c SRCS+= socket_network_client_unix.c SRCS+= ../libcutils/sockets.cpp SRCS+= load_file.c SRCS+= threads.c # XXX Obsolete after 10.2 or r279980/r280329 CPPFLAGS.sockets.cpp+= -o ${.TARGET} # required by base/file.cpp .PATH: ${.CURDIR}/../liblog +SRCS+= config_read.c SRCS+= config_write.c SRCS+= fake_log_device.c SRCS+= fake_writer.c +SRCS+= local_logger.c SRCS+= logger_lock.c SRCS+= logger_name.c SRCS+= logger_write.c -CPPFLAGS.config_write.c+= -DFAKE_LOG_DEVICE=1 +SRCS+= logprint.c +SRCS+= stderr_write.c REVISION?= $$(${GIT} rev-parse --short=12 HEAD 2>/dev/null || echo unknown) -CPPFLAGS+= -DADB_REVISION="\"${REVISION}-android\"" +CPPFLAGS+= -DADB_VERSION="\"0.0.0-${REVISION}-android\"" CPPFLAGS+= -DADB_HOST=1 CPPFLAGS+= -DHAVE_FORKEXEC=1 CPPFLAGS+= -DHAVE_SYMLINKS CPPFLAGS+= -DHAVE_TERMIO_H CPPFLAGS+= -DHAVE_SYS_SOCKET_H CPPFLAGS+= -D_FILE_OFFSET_BITS=64 +CPPFLAGS+= -DFAKE_LOG_DEVICE=1 CPPFLAGS+= -I${.CURDIR} CPPFLAGS+= -I${.CURDIR}/../include CPPFLAGS+= -I${.CURDIR}/../base/include CPPFLAGS+= -I${.CURDIR}/../libcrypto_utils/include CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}} CPPFLAGS+= $$(${PKG_CONFIG} libcrypto --cflags 2>/dev/null) CPPFLAGS+= $$(${PKG_CONFIG} libusb-1.0 --cflags 2>/dev/null) -CXXFLAGS+= -std=gnu++11 +CXXFLAGS+= -std=gnu++14 .ifndef COMPILE.c CFLAGS+= ${CPPFLAGS} CXXFLAGS+= ${CPPFLAGS} .endif TEST_CPPFLAGS+= $$(${GTEST_CONFIG} --cppflags) TEST_CPPFLAGS+= $$(${GMOCK_CONFIG} --cppflags) .for f in ${TEST_SRCS} CPPFLAGS.${f}+= ${TEST_CPPFLAGS} .endfor LDADD+= $$(${PKG_CONFIG} libcrypto --libs 2>/dev/null || echo -lcrypto) LDADD+= $$(${PKG_CONFIG} libusb-1.0 --libs 2>/dev/null || echo -lusb) LDADD+= -lz \-lpthread DPADD+= ${LIBCRYPTO} ${LIBPTHREAD} ${LIBUSB} ${LIBZ} TEST_LDADD+= $$(${GTEST_CONFIG} --libs --ldflags) TEST_LDADD+= $$(${GMOCK_CONFIG} --libs --ldflags) TEST_OBJS+= ${TEST_SRCS:R:S/$/.o/} CLEANFILES+= ${PROG}_test ${TEST_OBJS} GIT?= git GTEST_CONFIG?= gtest-config GMOCK_CONFIG?= gmock-config PKG_CONFIG?= pkg-config beforeinstall: ${INSTALL} -d ${DESTDIR}${FILESDIR} .include test: ${PROG}_test @for f in ${.ALLSRC}; do ./$$f; done ${PROG}_test: ${OBJS:Nmain.o:Ncommandline.o} ${TEST_OBJS} ${CXX} ${CPPFLAGS} ${CXXFLAGS} ${LDFLAGS} -o $@ $> ${LDADD} ${TEST_LDADD} Index: head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp =================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp (nonexistent) +++ head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp (revision 444004) @@ -0,0 +1,77 @@ +--- adb/client/usb_libusb.cpp.orig 2017-06-20 10:50:27 UTC ++++ adb/client/usb_libusb.cpp +@@ -28,7 +28,7 @@ + #include + #include + +-#include ++#include + + #include + #include +@@ -89,7 +89,11 @@ struct transfer_info { + }; + + namespace libusb { ++#if defined(__linux__) || defined(__APPLE__) + struct usb_handle : public ::usb_handle { ++#else ++struct usb_handle { ++#endif + usb_handle(const std::string& device_address, const std::string& serial, + unique_device_handle&& device_handle, uint8_t interface, uint8_t bulk_in, + uint8_t bulk_out, size_t zero_mask, size_t max_packet_size) +@@ -152,7 +156,9 @@ struct usb_handle : public ::usb_handle { + static auto& usb_handles = *new std::unordered_map>(); + static auto& usb_handles_mutex = *new std::mutex(); + ++#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 + static libusb_hotplug_callback_handle hotplug_handle; ++#endif + + static std::string get_device_address(libusb_device* device) { + return StringPrintf("usb:%d:%d", libusb_get_bus_number(device), +@@ -420,6 +426,7 @@ static void device_disconnected(libusb_device* device) + } + } + ++#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 + static auto& hotplug_queue = *new BlockingQueue>(); + static void hotplug_thread() { + adb_thread_setname("libusb hotplug"); +@@ -449,6 +456,7 @@ static int hotplug_callback(libusb_context*, libusb_de + hotplug_queue.Push({event, device}); + return 0; + } ++#endif + + void usb_init() { + LOG(DEBUG) << "initializing libusb..."; +@@ -457,6 +465,7 @@ void usb_init() { + LOG(FATAL) << "failed to initialize libusb: " << libusb_error_name(rc); + } + ++#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 + // Register the hotplug callback. + rc = libusb_hotplug_register_callback( + nullptr, static_cast(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | +@@ -467,6 +476,9 @@ void usb_init() { + if (rc != LIBUSB_SUCCESS) { + LOG(FATAL) << "failed to register libusb hotplug callback"; + } ++#else ++ LOG(FATAL) << "libusb doesn't support hotplug but scanning isn't implemented"; ++#endif + + // Spawn a thread for libusb_handle_events. + std::thread([]() { +@@ -478,7 +490,9 @@ void usb_init() { + } + + void usb_cleanup() { ++#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 + libusb_hotplug_deregister_callback(nullptr, hotplug_handle); ++#endif + } + + // Dispatch a libusb transfer, unlock |device_lock|, and then wait for the result. Property changes on: head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/patch-adb_sysdeps_posix_network.cpp =================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_sysdeps_posix_network.cpp (nonexistent) +++ head/devel/android-tools-adb-devel/files/patch-adb_sysdeps_posix_network.cpp (revision 444004) @@ -0,0 +1,10 @@ +--- adb/sysdeps/posix/network.cpp.orig 2017-06-20 10:50:27 UTC ++++ adb/sysdeps/posix/network.cpp +@@ -17,6 +17,7 @@ + #include "sysdeps/network.h" + + #include ++#include // strerror + #include + #include + Property changes on: head/devel/android-tools-adb-devel/files/patch-adb_sysdeps_posix_network.cpp ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/patch-adb_transport__usb.cpp =================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_transport__usb.cpp (nonexistent) +++ head/devel/android-tools-adb-devel/files/patch-adb_transport__usb.cpp (revision 444004) @@ -0,0 +1,11 @@ +--- adb/transport_usb.cpp.orig 2017-06-20 10:50:27 UTC ++++ adb/transport_usb.cpp +@@ -191,6 +191,8 @@ int is_adb_interface(int usb_class, int usb_subclass, + bool should_use_libusb() { + #if defined(_WIN32) || !ADB_HOST + return false; ++#elif !defined(__linux__) && !defined(__APPLE__) ++ return true; + #else + static bool disable = getenv("ADB_LIBUSB") && strcmp(getenv("ADB_LIBUSB"), "0") == 0; + return !disable; Property changes on: head/devel/android-tools-adb-devel/files/patch-adb_transport__usb.cpp ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/patch-adb_usb.h =================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_usb.h (nonexistent) +++ head/devel/android-tools-adb-devel/files/patch-adb_usb.h (revision 444004) @@ -0,0 +1,20 @@ +--- adb/usb.h.orig 2017-06-20 10:50:27 UTC ++++ adb/usb.h +@@ -43,6 +43,7 @@ namespace libusb { + ADB_USB_INTERFACE(libusb::usb_handle*); + } + ++#if defined(__linux__) || defined(__APPLE__) + namespace native { + struct usb_handle; + ADB_USB_INTERFACE(native::usb_handle*); +@@ -53,6 +54,9 @@ struct usb_handle { + }; + + ADB_USB_INTERFACE(::usb_handle*); ++#else ++using namespace libusb; ++#endif + + #endif // linux host || darwin + Property changes on: head/devel/android-tools-adb-devel/files/patch-adb_usb.h ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/devel/android-tools-adb-devel/files/patch-base_file.cpp =================================================================== --- head/devel/android-tools-adb-devel/files/patch-base_file.cpp (revision 444003) +++ head/devel/android-tools-adb-devel/files/patch-base_file.cpp (revision 444004) @@ -1,40 +1,40 @@ ---- base/file.cpp.orig 2016-09-28 18:07:09 UTC +--- base/file.cpp.orig 2017-06-20 10:50:27 UTC +++ base/file.cpp -@@ -18,6 +18,9 @@ - +@@ -19,6 +19,9 @@ #include #include + #include +#include // PATH_MAX +#include // BUFSIZ +#include // strerror #include #include #include -@@ -34,6 +37,9 @@ +@@ -36,6 +39,9 @@ #if defined(__APPLE__) #include #endif +#if defined(__DragonFly__) || defined(__FreeBSD__) +#include +#endif #if defined(_WIN32) #include - #endif -@@ -231,6 +237,17 @@ std::string GetExecutablePath() { + #define O_CLOEXEC O_NOINHERIT +@@ -251,6 +257,17 @@ std::string GetExecutablePath() { if (result == 0 || result == sizeof(path) - 1) return ""; path[PATH_MAX - 1] = 0; return path; +#elif defined(KERN_PROC_PATHNAME) + char path[PATH_MAX + 1]; + size_t path_len = sizeof(path); + int mib[] = { + CTL_KERN, + KERN_PROC, + KERN_PROC_PATHNAME, + getpid() + }; + int rc = sysctl(mib, arraysize(mib), path, &path_len, NULL, 0); + return rc ? "" : path; #else #error unknown OS #endif Index: head/devel/android-tools-adb-devel/files/patch-include_cutils_trace.h =================================================================== --- head/devel/android-tools-adb-devel/files/patch-include_cutils_trace.h (nonexistent) +++ head/devel/android-tools-adb-devel/files/patch-include_cutils_trace.h (revision 444004) @@ -0,0 +1,17 @@ +--- include/cutils/trace.h.orig 2017-06-20 10:50:27 UTC ++++ include/cutils/trace.h +@@ -18,8 +18,14 @@ + #define _LIBS_CUTILS_TRACE_H + + #include ++#ifdef __cplusplus ++#include ++using std::atomic_bool; ++using std::memory_order_acquire; ++#else + #include + #include ++#endif + #include + #include + #include Property changes on: head/devel/android-tools-adb-devel/files/patch-include_cutils_trace.h ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property