Skip to content

Commit 81bd9db

Browse files
committed
Merging r354122:
------------------------------------------------------------------------ r354122 | mgorny | 2019-02-15 13:13:02 +0100 (Fri, 15 Feb 2019) | 10 lines [lldb] [MainLoop] Add kevent() EINTR handling Add missing EINTR handling for kevent() calls. If the call is interrupted, return from Poll() as if zero events were returned and let the polling resume on next iteration. This fixes test flakiness on NetBSD. Includes a test case suggested by Pavel Labath on D42206. Differential Revision: https://reviews.llvm.org/D58230 ------------------------------------------------------------------------ llvm-svn: 354255
1 parent 096ef4c commit 81bd9db

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lldb/source/Host/common/MainLoop.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ Status MainLoop::RunImpl::Poll() {
108108
num_events = kevent(loop.m_kqueue, in_events.data(), in_events.size(),
109109
out_events, llvm::array_lengthof(out_events), nullptr);
110110

111-
if (num_events < 0)
112-
return Status(errno, eErrorTypePOSIX);
111+
if (num_events < 0) {
112+
if (errno == EINTR) {
113+
// in case of EINTR, let the main loop run one iteration
114+
// we need to zero num_events to avoid assertions failing
115+
num_events = 0;
116+
} else
117+
return Status(errno, eErrorTypePOSIX);
118+
}
113119
return Status();
114120
}
115121

lldb/unittests/Host/MainLoopTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,28 @@ TEST_F(MainLoopTest, Signal) {
137137
ASSERT_TRUE(loop.Run().Success());
138138
ASSERT_EQ(1u, callback_count);
139139
}
140+
141+
// Test that a signal which is not monitored by the MainLoop does not
142+
// cause a premature exit.
143+
TEST_F(MainLoopTest, UnmonitoredSignal) {
144+
MainLoop loop;
145+
Status error;
146+
struct sigaction sa;
147+
sa.sa_sigaction = [](int, siginfo_t *, void *) { };
148+
sa.sa_flags = SA_SIGINFO; // important: no SA_RESTART
149+
sigemptyset(&sa.sa_mask);
150+
ASSERT_EQ(0, sigaction(SIGUSR2, &sa, nullptr));
151+
152+
auto handle = loop.RegisterSignal(SIGUSR1, make_callback(), error);
153+
ASSERT_TRUE(error.Success());
154+
std::thread killer([]() {
155+
sleep(1);
156+
kill(getpid(), SIGUSR2);
157+
sleep(1);
158+
kill(getpid(), SIGUSR1);
159+
});
160+
ASSERT_TRUE(loop.Run().Success());
161+
killer.join();
162+
ASSERT_EQ(1u, callback_count);
163+
}
140164
#endif

0 commit comments

Comments
 (0)