adb: fix subprocess termination for legacy shell.
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
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index f886698..1f5d29f 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -742,10 +742,6 @@
argc -= 2;
argv += 2;
} else if (!strcmp(argv[0], "-T") || !strcmp(argv[0], "-t")) {
- if (!CanUseFeature(features, kFeatureShell2)) {
- fprintf(stderr, "error: target doesn't support PTY args -Tt\n");
- return 1;
- }
// Like ssh, -t arguments are cumulative so that multiple -t's
// are needed to force a PTY.
if (argv[0][1] == 't') {
@@ -769,6 +765,17 @@
}
}
+ // Legacy shell protocol requires a remote PTY to close the subprocess properly which creates
+ // some weird interactions with -tT.
+ if (!use_shell_protocol && t_arg_count != 0) {
+ if (!CanUseFeature(features, kFeatureShell2)) {
+ fprintf(stderr, "error: target doesn't support PTY args -Tt\n");
+ } else {
+ fprintf(stderr, "error: PTY args -Tt cannot be used with -x\n");
+ }
+ return 1;
+ }
+
std::string shell_type_arg;
if (CanUseFeature(features, kFeatureShell2)) {
if (t_arg_count < 0) {