Skip to content

Commit 0b41990

Browse files
committed
[lldb] [debugserver] Handle interrupted reads correctly (llvm#84872)
The first half of this patch is a long-standing annoyance, if I attach to debugserver with lldb while it is waiting for an lldb connection, the syscall is interrupted and it doesn't retry, debugserver exits immediately. The second half is a request from another tool that is communicating with debugserver, that we retry reads on our sockets in the same way. I haven't dug in to the details of how they're communicating that this is necessary, but the best I've been able to find reading the POSIX API docs, this is fine. rdar://117113298 (cherry picked from commit 87dc068)
1 parent b7ab938 commit 0b41990

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lldb/tools/debugserver/source/RNBSocket.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ rnb_err_t RNBSocket::Listen(const char *listen_host, uint16_t port,
120120
while (!accept_connection) {
121121

122122
struct kevent event_list[4];
123-
int num_events =
124-
kevent(queue_id, events.data(), events.size(), event_list, 4, NULL);
123+
int num_events;
124+
do {
125+
errno = 0;
126+
num_events =
127+
kevent(queue_id, events.data(), events.size(), event_list, 4, NULL);
128+
} while (num_events == -1 &&
129+
(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR));
125130

126131
if (num_events < 0) {
127132
err.SetError(errno, DNBError::MachKernel);
@@ -291,7 +296,12 @@ rnb_err_t RNBSocket::Read(std::string &p) {
291296
// DNBLogThreadedIf(LOG_RNB_COMM, "%8u RNBSocket::%s calling read()",
292297
// (uint32_t)m_timer.ElapsedMicroSeconds(true), __FUNCTION__);
293298
DNBError err;
294-
ssize_t bytesread = read(m_fd, buf, sizeof(buf));
299+
ssize_t bytesread;
300+
do {
301+
errno = 0;
302+
bytesread = read(m_fd, buf, sizeof(buf));
303+
} while (bytesread == -1 &&
304+
(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR));
295305
if (bytesread <= 0)
296306
err.SetError(errno, DNBError::POSIX);
297307
else

0 commit comments

Comments
 (0)