Commit graph

19 commits

Author SHA1 Message Date
Josh Gao
f0d3b4fc11 adb: make ScopedFd universally accessible and useful.
Change-Id: I707ffbd10958e7449b4c95dff48638480c746939
2016-03-04 15:15:56 -08:00
David Pursell
706955ff0d base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.

libbase seemed like the right choice because:
  1. It already has some parsing functions (parseint)
  2. The net address parsing function uses the libbase string
     functions so we have a libbase dependency anyway.

The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.

For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.

Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
2016-01-21 20:03:33 -08:00
Josh Gao
7d58607360 adb: shell: add -n flag to not read from stdin.
Shell scripts of the following form do not work properly with adb:
    echo "foo\nbar\nbaz" | {
        read FOO
        while [ "$FOO" != "" ]; do
            adb shell echo $FOO
            read FOO
        done
    }
The first run of adb shell will consume all of the contents of stdin,
causing the loop to immediately end. ssh solves this by providing a -n
flag that causes it to not read from stdin. This commit adds the same.

Bug: http://b/25817224
Change-Id: Id74ca62ef520bcf03678b50f4bf203916fd81038
2015-12-10 12:52:06 -08:00
Yabin Cui
6dfef255b8 adb: keep file flags in fdevent_install.
Bug: 24615098
Change-Id: Ia791ecbe612f09aca3bbd5787513f121fae54da5
2015-10-06 16:15:30 -07:00
Yabin Cui
aed3c61c44 Adb: use VLOG() to replace D() for verbose logging.
As there are too many D(), we can keep both VLOG() and D() now, and get
rid of D() gradually.

Change-Id: I2f1cb70bcab3e82c99fed939341d03f6b2216076
2015-09-23 12:53:38 -07:00
Elliott Hughes
aa24549190 adb sync cleanup.
We can double the speed of "adb sync" (on N9) if we increase SYNC_DATA_MAX
from 64KiB to 256KiB. This change doesn't do that, because I still haven't
managed to plumb through the information about whether we're a new adb/adbd
to file_sync_client.cpp and file_sync_service.cpp. But this is already a big
change with a lot of cleanup, so let's do the cleanup and worry about the
intended change another day...

This change does improve performance somewhat by halving the number of
lstat(2) calls made on the client side, and ensuring that most packets are
sent with a single write. This has the pleasing result of making the null
sync on an AOSP N9 go from just over 300ms to around 100ms, which means it
now seems instantaneous (https://en.wikipedia.org/wiki/Mental_chronometry).

Change-Id: If9f6d4c1f93ec752b95f71211bbbb1c513045166
2015-08-24 11:15:01 -07:00
Spencer Low
22191c30a6 adb: fix mkdirs / adb pull with relative paths, fix win32 issues
Relative paths were being prefixed with OS_PATH_SEPARATOR on unix and
win32 causing adb to incorrectly try to make directories at the root.
Plus, absolute paths didn't work on win32 (C: got prefixed into \C:).

This fix is to use dirname (available on win32 via mingw's crt) to do
the messy parsing.

I added a test for the relative path case.

Change-Id: Ibb0a4a8ec7756351d252a4d267122ab18e182858
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-03 13:24:18 -07:00
Spencer Low
5200c6670f adb: win32: initial IPv6 support and improved Winsock error reporting
Call getaddrinfo() for connecting to IPv6 destinations.

Winsock APIs do not set errno. WSAGetLastError() returns Winsock errors
that are more numerous than BSD sockets, so it really doesn't make sense
to map those to BSD socket errors. Plus, even if we did that, the
Windows C Runtime (that mingw binaries use) has a strerror() that does
not recognize BSD socket error codes.

The solution is to wrap the various libcutils socket_* APIs with
sysdeps.h network_* APIs. For POSIX, the network_* APIs just call
strerror(). For Windows, they call SystemErrorCodeToString() (adapted
from Chromium).

Also in this change:

 - Various other code was modified to return errors in a std::string*
   argument, to be able to surface the error string to the end-user.

 - Improved error checking and use of D() to log Winsock errors for
   improved debuggability.

 - For sysdeps_win32.cpp, added unique_fh class that works like
   std::unique_ptr, for calling _fh_close().

 - Fix win32 adb_socketpair() setting of errno in error case.

 - Improve _socket_set_errno() D() logging to reduce confusion. Map
   a few extra error codes.

 - Move adb_shutdown() lower in sysdeps_win32.cpp so it can call
   _socket_set_errno().

 - Move network_connect() from adb_utils.cpp to sysdeps.h.

 - Merge socket_loopback_server() and socket_inaddr_any_server() into
   _network_server() since most of the code was identical.

Change-Id: I945f36870f320578b3a11ba093852ba6f7b93400
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-30 23:07:55 -07:00
Elliott Hughes
5c74270f95 More adb cleanup.
This removes adb_dirstart and adb_dirstop. It also fixes a couple of memory
leaks by switching to std::string. This also fixes the bug in the previous
change --- mkdirs is given input like "/system/bin/sh" and only expected to
create "/system/bin". In a later change, we should remove mkdirs and only
expose the intended "unlink && mkdirs && create" functionality.

Change-Id: I30289dc1b3dff575cc1b158d993652178f587552
2015-07-30 17:46:58 -07:00
Alex Vallée
47d67c96ec Write mkdirs in more idiomatic C++ style.
~ Rewrote mkdirs to be in C++ style.
~ Replaced adb_dir{start,stop} with std::string params and (r)find.
+ Added test for mkdirs.

Also make base/test_utils.h public and support temporary directories
as well as files.

Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-30 15:08:53 -07:00
Elliott Hughes
3e7048c027 Fix const-ness of strrchr callers.
This causes build failures in google3 where they use GCC. glibc only
provides const-correct overloads for string functions for GCC >= 4.4,
but clang -- which is what we use -- pretends to be GCC 4.2.

Change-Id: I2a054823ea6201ebcea46d5e77b80a975eefc622
2015-07-28 08:07:21 -07:00
Elliott Hughes
381cfa9a8b Report getaddrinfo failures correctly.
Also move us off the "convenience" function because you can't get useful
error reporting from it.

Change-Id: I5fcc6a6d762f5f60906980a7835f01a35045be65
2015-07-23 21:14:38 -07:00
Elliott Hughes
3d5f60dbba Recognize IPv6 addresses for "adb connect".
Bug: http://b/22559299
Change-Id: I32891d706b5010c38db84a056e76dd279b780f75
2015-07-21 15:25:14 -07:00
Alex Vallée
1421614821 Move mkdirs to adb_utils.
There were duplicate implementations in commandline.cpp and
file_sync_client.cpp.

Change-Id: Ib448f76c0d7ffdcd577336b1c610a881425bc2db
2015-07-15 19:37:18 +00:00
Dan Albert
286bb6ddbd Revert "Turn on -Wformat-nonliteral."
One of my build aliases doesn't play nice with USE_MINGW=1, so my build lied to me. Will revert until I fix it up.

This reverts commit 459df8f3a1.

Change-Id: I7905c5ae5ee85fb2d228ce63d81c79f140998c18
2015-07-09 20:35:09 +00:00
Dan Albert
459df8f3a1 Turn on -Wformat-nonliteral.
Apparently there are two classes of this warning in clang.
-Wformat-security is only emitted for cases of
`func(nonliteral_fmt_string)` (no args), and -Wformat-nonliteral is
emitted for cases *with* arguments. For whatever reason, the latter
isn't included in -Wextra and must be manually enabled.

To make this more easily portable to Windows, move the existing
gnu_printf/__printf__ decision into base/macros.h as ATTRIBUTE_FORMAT.

Change-Id: I3b0990e1d1f0a2e9c13b32f5cd60478946cb5fc6
2015-07-09 10:47:24 -07:00
Elliott Hughes
e67f1f87d9 More adb buffer fixes.
This patch factors out a lot of the basic protocol code: sending OKAY,
sending FAIL, and sending a length-prefixed string.

ADB_TRACE has been non-optional for a long time, so let's just remove
the #ifs.

Also actually build the device tracker test tool (and remove its duplicate).

Bug: http://b/20666660
Change-Id: I6c7d59f18707bdc62ca69dea45547617f9f31fc6
2015-05-01 15:55:37 -07:00
Elliott Hughes
a7090b94c1 Remove yet more fixed-length buffers (and their overruns).
Bug: 20317724
Change-Id: If137fc96f5f23576ccecd388ac87afefa47337c6
2015-04-17 17:58:35 -07:00
Elliott Hughes
5830577bd8 Fix more buffer overruns.
Also add some tests.

Bug: 20323050
Change-Id: I9eaf3dc04efd85206663c4cca4f8c1208620a89a
2015-04-17 15:23:31 -07:00