fwrite() is a macro that maps to adb_fwrite(), which can write UTF-8 to
the console. Use it to write the output that comes from the subprocess
adb server.
To do this, dup the stdout/stderr file descriptor and make a duplicate
FILE* stream, in binary mode (since we're reading raw bytes from the
subprocess), and unbuffered.
Change-Id: I480761bae0bd576dc9e03fa4d31266f4e49635ed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
SendFail and SendSyncFail are similarly named, and have the same
prototype. Use `#pragma GCC poison` to prevent use of SendFail in
file_sync_service.cpp, and fix the places where it was used
accidentally.
Change-Id: I6b9a7e565b76dfab10f8ae38f889d046ad80a403
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.
The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.
Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
- Introduces unix_read_interruptible() which is like unix_read() except
that it can return EINTR.
- The big idea is that the Windows ReadConsoleInput() API will return an
event on window resize and then we return EINTR from
unix_read_interruptible() just like Unix.
- Only handles horizontal resize since Windows doesn't seem to give an
event for vertical resize when no special screen buffer is used. This
should be sufficient for the primary use case of adb on Windows
(people are not running vi in the first place).
Change-Id: Id8d1710b559834c8098f2d7fbecedf2d0ade4b88
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Previously, the various adb_printf, adb_fwrite, etc. functions did not
correctly handle the case of the passed buffer ending with an incomplete
UTF-8 sequence. This is fixed by buffering up incomplete UTF-8 sequences
in g_console_output_buffer (protected by the mutex
g_console_output_buffer) and outputting it later once the full sequence
is available.
A unittest for the main worker function, ParseCompleteUTF8(), was added
to adb_test.
Other fixes:
- Fix the return value of number-of-chars written to be number of UTF-8
bytes instead of number of UTF-16 characters.
- Don't overwrite errno in success cases of various adb_printf, etc.
functions. This might be excessive, but might be useful in the case
when these functions are used for debugging/tracing.
- Add missing UTF-8 stdio functions that aren't currently used by adb,
but might be in the future: vprintf, putc, putchar, puts.
- stdin_raw_init: If we can't get the console handle, don't call
SetConsoleMode(). Not a big deal, but this will prevent erroneous
trace output.
Change-Id: I8730e8af92882c42b884ad921b39a17b54465085
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
http://r.android.com/166419 changed `adb shell` behavior to not
allocate a remote PTY for non-interactive commands, but adbd relied on
having a PTY to properly terminate the subprocess.
One impact of this is that when using older versions of adb or passing
the -x flag, `adb screenrecord` wasn't properly terminating and closing
out the video file.
This CL restores the old behavior for legacy shell connections: always
use a PTY, but put it in raw mode if the client is doing local PTY
input/output processing itself.
Bug: http://b/26742824
Change-Id: I9ee630c0ff0d2d6a0db367387af7123deea79676
Previously GetFeatureSet() on an invalid target would just return an
empty feature set, leading to some invalid assumptions, e.g. if there
isn't exactly one device connected this happens:
$ adb shell -t
error: target doesn't support PTY args -Tt
This CL adds a success/failure return value to GetFeatureSet(), and
also adds an option to print errors to stderr since that's the most
common behavior.
This will cause a slight difference in behavior for install/uninstall.
Previously they would block until the device was available, now they
print an error and quit immediately, which seems to be the more common
behavior for adb functions.
Bug: http://b/26387641
Change-Id: I0ea6ffaec922e04b9946e84f05c3870e5b549fde
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
Also, fix bugs that this uncovered. In particular, the sysdeps_win32
FATAL macro would only print __FUNCTION__.
Change-Id: I6307ec9749edec21b4fee192e135a86ec445c84b
The actual maximum length will depend on the version of the shell
protocol being used, and any additional parameters being passed through
(e.g. TERM=xterm-256color). This should be able to be raised to 64K for
devices with commit 3d2904c (L-MR1 and above), but that'll require some
plumbing.
Bug: http://b/20467103
Change-Id: Idf0c46af5b18b854110aba58df13a53297d2475f
With https://android-review.googlesource.com/#/c/195460,
adbd can depend only on libminijail, without having to include its
dependencies.
Bug: 26099611
Change-Id: I2312d8584dda88b4a4619d3100d0983fa2833ba5
With https://android-review.googlesource.com/#/c/195400, Minijail will
check for this failure so there's no need to do it here, which allows
to simplify the code.
Bug: 26099611
Change-Id: I7c876fdcab874ed403f82bdd5a4048c0f1e5db58
Without -s argument, adb wait-for-device will make a call to
acquire_one_transport() with sinfo->serial.c_str() == "".
Waiting for acquire_one_transport() to be reworked to use std::string
rather than const char * for serial, work around this by passing NULL
when sinfo->serial is not initialized in host_service_to_socket().
Change-Id: Ifef53e0e82850364f5029ee36560376f2a4a5104
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
It uses libadb, which is also only compiled for the primary
architecture. BUILD_HOST_NATIVE_TEST is changing the default
LOCAL_MULTILIB to match BUILD_NATIVE_TEST.
Change-Id: Ia9c002e641125eb996a7f198af1f182d0d6171c6
This factors out the duplication in the single-file progress, and adds a
whole-sync progress percentage to the front of the line. A number that's
both more interesting and easier to read.
This also fixes the >100 percentage reporting for files of unknown size.
Bug: http://b/26189482
Change-Id: I51501ccef6ae1f52425db0eb0862d87e90947a6c
We still don't really have a clue what went wrong, but "Failed to write"
made it sound like we did.
Change-Id: Ic58b13202e2d8ea6b095f7046db9d0771d77ce65
By using Minijail we avoid writing the same priv-dropping code over
and over again. This also enables future hardening opportunities.
We're already using Minijail for priv-dropping on Brillo.
Minijail is unit- and integration-tested on the
Chrome OS CI infrastructure (pulling from the same repo, see
https://wmatrix.googleplex.com/security?tests=security_Minijail0).
Once CI comes to Android, it will be continuously tested there as well.
Both 'adb root' and 'adb unroot' still work.
Bug: 26099611
Change-Id: I52c456ea272d27bd6fbc71200f4fdd928a592158
The current implementation of the host commands "adb wait-for-*" allows
to specify only the transport layer (local, usb or any).
This patch allows the specification of the expected device state
(bootloader, recovery, device or sideload), this is usefull for
scripting purposes.
Use case:
$ adb reboot sideload-auto-reboot
$ adb wait-for-usb-sideload && adb sideload package.zip
Change-Id: I276a6be4d82f8b7901f74e1e5395b86d16548e8f
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
Reads from functionfs allocate contiguous buffers in the kernel, causing
long ones to sometimes fail because of memory fragmentation.
Bug: http://b/26206622
Change-Id: Id40753d6f29b37b5ca97c3e2fa3921f52b4242de
Back in 080427e4e2, we said:
If the kernel doesn't support file capabilities, we ignore
a prctl(PR_CAPBSET_DROP) failure. In a future CL, this could
become a fatal error.
Make it a fatal error. With SELinux support, all devices are
required to support file capabilities.
Change-Id: I0ce0c4cb9387c42e325cbf1a63c5d82e6aab530c
Previously, for `adb shell`, we were using setenv after forking to set
up the child's environment. This would occasionally deadlock in the
child, which would cause the main thread to deadlock waiting for the
child to complete. This patch constructs the environment before forking
and passes it to execle, eliminating the deadlock.
Bug: http://b/25847115
Change-Id: I720d472770564b1449819ddaab945a89844244a8