POSIX lets you choose whether or not SIGPIPE disposition is inherited,
and Linux chose "yes". Work around that.
Bug: http://b/35209888
Test: "ps -A | head" without the toybox workaround
Change-Id: I6b5afa3d87eb2af04b24c6c37fa338ab60ad2336
Should use android/log.h instead of log/log.h as a good example
to all others. Adjust header order to comply with Android Coding
standards.
Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I33a8fb4e754d2dc4754d335660c450e0a67190fc
Some POSIX-only files would like to use functions declared in
adb_utils.h without being forced to use the sysdeps stuff for open,
close, etc. Extract the adb-specific unique_fd into its own header so
those files can use adb_utils.h alongside the real unique_fd.
Change-Id: I10344ef26b7e72fce46bf7e3033f89aa54bd6118
Test: mm
SIGHUP handling depends on the local socket fd being fully closed in
order to trigger an event on its counterpart. Release the local socket
fd inside of Subprocess when returning it to ensure this.
Functionally, a cherry-pick of internal commit 42afe20.
Bug: http://b/29565233
Change-Id: I13b17bcddf0b396a5f4880f9e410fbbf24d9370d
This commit fixes two somewhat related issues in shell_service.
- The fd returned by StartSubprocess is owned by a unique_fd
contained in the Subprocess object, but also gets closed by the
caller. Resolve this by duping the returned file descriptor.
- A Subprocess object can be destroyed immediately after its initial
construction in StartSubprocess if we're sufficiently unlucky.
Split up the fork/exec and "start management thread" steps, so that
we can safely do everything we need to do on the Subprocess before
handing it over to the thread that'll eventually destroy it.
Bug: http://b/29254462
Change-Id: Id9cf0b7e7a7293bee7176919edc758597691c636
When non-interactive sessions exit via Ctrl+C, adbd sends SIGHUP
to the child process to let it know to exit. However, adbd was not
closing the pipes to the child process, so if the subprocess ignored
SIGHUP and continued writing it could fill up the pipe and block
forever while adbd waits for it to exit.
This CL adds the necessary calls to close the subprocess pipe after
sending SIGHUP.
Bug: 28981563
Change-Id: I318e322e563241052648361172f4859c297837fb
This makes it possible to get a core dump from adbd when it decides to
exit.
Bug: http://b/28347842
Change-Id: I4cfe5f273f62b2c32e61232d3c39881ecdd6b582
* changes:
adb: wait for restore to complete before returning.
adb: wait for adbd to die and respawn in root/unroot.
adb: make ScopedFd universally accessible and useful.
forkpty only returns an fd on the master side; trying to keep track of
it on both sides is incorrect.
Bug: http://b/27504427
Change-Id: Ia4a454d8490c77738f9c3350a4236b3d99c8758b
Windows restricts the return value of threads to 32-bits, even on 64-bit
platforms. Since we don't actually return meaningful values from thread,
resolve this inconsistency with POSIX by making adb's thread abstraction
only take void functions.
Change-Id: I5c23b4432314f13bf16d606fd5e6b6b7b6ef98b5
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, 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
During early boot, we may be mounting and unmounting /data.
Having the home directory for adb shell commands, such as
"adb shell logcat", on the /data directory prevents unmounting.
This reverts commit 173eb396c7.
Bug: 26132185
Change-Id: Ib7c2f9e696f52bf5bbb79223d90dd76791779587
Make the home directory for adb shell be /data/local/tmp and
automatically change into that directory.
Change-Id: Ib5cc6e1ecdd31a37e986cf03836f7589ebd40868
Unfortunately, this isn't backwards-compatible with the current shell
protocol because we made unknown shell: arguments errors. We could try
to commit the change to make them just warnings first, but how would
we know when everyone was running adbd with that change? Bumping the
protocol version doesn't help because that only affects the code running
on the host. And although we could add another feature to the reported
features, since shell_v2 is still in development, that doesn't seem
worthwhile.
Bug: http://b/25601436
Change-Id: I12b81aa656cd25b91d14ef691dcbd2b7dab49535
Previously we've set these from /system/etc/mkshrc, which caused a behavioral
difference between interactive and non-interactive shells.
Bug: http://b/19635681
Change-Id: I4608c42dd3de821046220fdb1770ab3216b5d5eb
Non-interactive `adb shell` previously only read from the remote shell,
but we want it to write as well so interactive and non-interactive
shells can both send data. With this CL, we can now do:
$ echo foo | adb shell cat
foo
This is primarily usable with newer devices that support the shell_v2
features. Older devices will receive stdin but the shell will still
hang after all input has been sent, requiring user Ctrl+C. This seems
better than closing communication altogether which could potentially
miss an unpredictable amount of return data by closing too early.
Known issue: non-interactive stdin to a PTY shell isn't reliable.
However I don't think this is a common case as ssh doesn't seem to
handle it properly either. Examples:
* echo 'echo foo' | adb shell
* echo 'foo' | adb shell -t cat
Bug: http://b/24565284
Change-Id: I5b017fd12d8478765bb6e8400ea76d535c24ce42
When the client exits (e.g. with Ctrl+C) the subprocess should be
notified as well so it can cleanup if needed.
Bug: http://b/23825725
Change-Id: Idb771710b293e0a9f7bebc9e2814b3a816e2c50e
Adds functionality for handling stdin/stdout/stderr streams and exit
codes using the shell protocol.
This CL just contains implementation for adbd which will not yet be
enabled. Once we have the ability to query transport features from the
adb client, another CL will add the implementation for the client side
and update the feature list to turn this on.
Note: this CL must be submitted together with a minadbd CL to update
the service_to_fd() function signature.
Bug: http://b/23030641
Change-Id: Ibed55e9c1946d8a35190696163ff63e8fb880238
Refactor shell_service.cpp to remove dependencies on service.cpp and
combine some common logic between PTY and raw subprocesses.
This will make it easier to add additional common code paths for
the upcoming shell protocol.
Change-Id: I497d30dd388de61b6e68d9086dce38f33dd92876
Upcoming changes to the shell will require significant additions to
the subprocess code, and it will be cleaner if it's in a separate file.
The only functional change here is a new debug tag specifically for
the shell service. Everything else has been copied exactly as-is in
order to make it easier to determine what's changing in upcoming CLs.
Change-Id: I13bd4294059051ee10e0d0c6a06affd8eca62967