From b9d19c87abce709ba11da4f0307cc6922b9aa52d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Thu, 2 Aug 2018 14:09:55 -0700 Subject: lshal: close fd before joining thread In ~PipeRelay, since the data is no longer needed, just close the fd before joining the thread. In previous code, 'lshal debug' can hang: - lshal read() waiting for data in RelayThread - lshal send fd to service in main thread - service close the fd - service returns in debug() call - lshal calls ~PipeRelay - lshal read() is still blocking because it does not receive the signal But, since the service has already end the debug() call, the fds can be closed to bail out from blocking read(). Test: 'while true; do lshal debug ...; done' does not hang Fixes: 111997867 Change-Id: I90db486b0a6598bd9998ed904dc0c757dfa57e0e --- cmds/lshal/PipeRelay.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmds/lshal/PipeRelay.cpp b/cmds/lshal/PipeRelay.cpp index 3828bbf27f..905607f097 100644 --- a/cmds/lshal/PipeRelay.cpp +++ b/cmds/lshal/PipeRelay.cpp @@ -77,13 +77,12 @@ void PipeRelay::CloseFd(int *fd) { PipeRelay::~PipeRelay() { CloseFd(&mFds[1]); + CloseFd(&mFds[0]); if (mThread != NULL) { mThread->join(); mThread.clear(); } - - CloseFd(&mFds[0]); } status_t PipeRelay::initCheck() const { -- cgit v1.2.3