adb: don't dup local socket fd.

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 is contained in:
Josh Gao 2016-06-22 15:57:12 -07:00
parent 495541c5bb
commit cd5d7376dc
1 changed files with 5 additions and 6 deletions

View File

@ -155,7 +155,7 @@ class Subprocess {
const std::string& command() const { return command_; }
int local_socket_fd() const { return local_socket_sfd_; }
int ReleaseLocalSocket() { return local_socket_sfd_.release(); }
pid_t pid() const { return pid_; }
@ -449,7 +449,7 @@ void Subprocess::ThreadHandler(void* userdata) {
Subprocess* subprocess = reinterpret_cast<Subprocess*>(userdata);
adb_thread_setname(android::base::StringPrintf(
"shell srvc %d", subprocess->local_socket_fd()));
"shell srvc %d", subprocess->pid()));
D("passing data streams for PID %d", subprocess->pid());
subprocess->PassDataStreams();
@ -756,14 +756,13 @@ int StartSubprocess(const char* name, const char* terminal_type,
return ReportError(protocol, error);
}
unique_fd local_socket(dup(subprocess->local_socket_fd()));
D("subprocess creation successful: local_socket_fd=%d, pid=%d", local_socket.get(),
subprocess->pid());
int local_socket = subprocess->ReleaseLocalSocket();
D("subprocess creation successful: local_socket_fd=%d, pid=%d", local_socket, subprocess->pid());
if (!Subprocess::StartThread(std::move(subprocess), &error)) {
LOG(ERROR) << "failed to start subprocess management thread: " << error;
return ReportError(protocol, error);
}
return local_socket.release();
return local_socket;
}