diff options
author | David Turner <digit@android.com> | 2013-01-21 02:56:36 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-01-21 02:56:36 -0800 |
commit | 5bf8a4200c5f1695b0210e59b6b6ef421cedee8f (patch) | |
tree | 7aec230d651156fb2dc84e6bf2b924c2724ac8c9 | |
parent | 51e06618dbd87c4374c56d9193a5e567aa3d02ac (diff) | |
parent | 3dbcb6d6c6befc406e4ce4e2b7aa9ad2635dfbb8 (diff) | |
download | system_core-5bf8a4200c5f1695b0210e59b6b6ef421cedee8f.zip system_core-5bf8a4200c5f1695b0210e59b6b6ef421cedee8f.tar.gz system_core-5bf8a4200c5f1695b0210e59b6b6ef421cedee8f.tar.bz2 |
am 3dbcb6d6: am 98d07897: Merge "Windows adb: Make client stdout and stderr handles uninheritable"
* commit '3dbcb6d6c6befc406e4ce4e2b7aa9ad2635dfbb8':
Windows adb: Make client stdout and stderr handles uninheritable
-rw-r--r-- | adb/adb.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1018,6 +1018,7 @@ int launch_server(int server_port) /* message since the pipe handles must be inheritable, we use a */ /* security attribute */ HANDLE pipe_read, pipe_write; + HANDLE stdout_handle, stderr_handle; SECURITY_ATTRIBUTES sa; STARTUPINFO startup; PROCESS_INFORMATION pinfo; @@ -1037,6 +1038,26 @@ int launch_server(int server_port) SetHandleInformation( pipe_read, HANDLE_FLAG_INHERIT, 0 ); + /* Some programs want to launch an adb command and collect its output by + * calling CreateProcess with inheritable stdout/stderr handles, then + * using read() to get its output. When this happens, the stdout/stderr + * handles passed to the adb client process will also be inheritable. + * When starting the adb server here, care must be taken to reset them + * to non-inheritable. + * Otherwise, something bad happens: even if the adb command completes, + * the calling process is stuck while read()-ing from the stdout/stderr + * descriptors, because they're connected to corresponding handles in the + * adb server process (even if the latter never uses/writes to them). + */ + stdout_handle = GetStdHandle( STD_OUTPUT_HANDLE ); + stderr_handle = GetStdHandle( STD_ERROR_HANDLE ); + if (stdout_handle != INVALID_HANDLE_VALUE) { + SetHandleInformation( stdout_handle, HANDLE_FLAG_INHERIT, 0 ); + } + if (stderr_handle != INVALID_HANDLE_VALUE) { + SetHandleInformation( stderr_handle, HANDLE_FLAG_INHERIT, 0 ); + } + ZeroMemory( &startup, sizeof(startup) ); startup.cb = sizeof(startup); startup.hStdInput = GetStdHandle( STD_INPUT_HANDLE ); |