diff options
| author | Pavel Labath <labath@google.com> | 2017-12-11 09:33:18 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2017-12-11 09:33:18 +0000 |
| commit | 390b4879940edd78ab00d535917014df3a43bec4 (patch) | |
| tree | 752e79318fc6a27cc65926c21ad451038c4abf35 /lldb | |
| parent | ad45bf5895182563b2d107e4ecb76d0e340ebd17 (diff) | |
| download | bcm5719-llvm-390b4879940edd78ab00d535917014df3a43bec4.tar.gz bcm5719-llvm-390b4879940edd78ab00d535917014df3a43bec4.zip | |
MainLoop: avoid infinite loop when pty slave gets closed
Summary:
For ptys (at least on Linux), the end-of-file (closing of the slave FD)
is signalled by the POLLHUP flag. We were ignoring this flag, which
meant that when this happened, we would spin in a loop, continuously
calling poll(2) and not making any progress.
This makes sure we treat POLLHUP as a read event (reading will return
0), and we call the registered callback when it happens. This is the
behavior our clients expect (and is consistent with how select(2)
works).
Reviewers: eugene, beanz
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D41008
llvm-svn: 320345
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/source/Host/common/MainLoop.cpp | 2 | ||||
| -rw-r--r-- | lldb/unittests/Host/MainLoopTest.cpp | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lldb/source/Host/common/MainLoop.cpp b/lldb/source/Host/common/MainLoop.cpp index feff0521396..6cbb5a84256 100644 --- a/lldb/source/Host/common/MainLoop.cpp +++ b/lldb/source/Host/common/MainLoop.cpp @@ -221,7 +221,7 @@ void MainLoop::RunImpl::ProcessEvents() { for (const auto &handle : fds) { #else for (const auto &fd : read_fds) { - if ((fd.revents & POLLIN) == 0) + if ((fd.revents & (POLLIN | POLLHUP)) == 0) continue; IOObject::WaitableHandle handle = fd.fd; #endif diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp index 3a39ea1c9ac..ee73f23d1a3 100644 --- a/lldb/unittests/Host/MainLoopTest.cpp +++ b/lldb/unittests/Host/MainLoopTest.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/MainLoop.h" +#include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/PseudoTerminal.h" #include "lldb/Host/common/TCPSocket.h" #include "gtest/gtest.h" #include <future> @@ -107,6 +109,24 @@ TEST_F(MainLoopTest, TerminatesImmediately) { } #ifdef LLVM_ON_UNIX +TEST_F(MainLoopTest, DetectsEOF) { + lldb_utility::PseudoTerminal term; + ASSERT_TRUE(term.OpenFirstAvailableMaster(O_RDWR, nullptr, 0)); + ASSERT_TRUE(term.OpenSlave(O_RDWR | O_NOCTTY, nullptr, 0)); + auto conn = llvm::make_unique<ConnectionFileDescriptor>( + term.ReleaseMasterFileDescriptor(), true); + + Status error; + MainLoop loop; + auto handle = + loop.RegisterReadObject(conn->GetReadObject(), make_callback(), error); + ASSERT_TRUE(error.Success()); + term.CloseSlaveFileDescriptor(); + + ASSERT_TRUE(loop.Run().Success()); + ASSERT_EQ(1u, callback_count); +} + TEST_F(MainLoopTest, Signal) { MainLoop loop; Status error; |

