From d2e2caaae6119b5abc2aca3a95e2da7db547eac3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 29 Oct 2021 22:34:16 +1100 Subject: [PATCH] Fix incorrect reading logic and EAGAIN handling This is one of the issues raised by #4410 --- src/shell_manager.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index b3605609..bd101633 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -176,9 +176,12 @@ FDWatcher make_reader(int fd, String& contents, OnClose&& on_close) char buffer[1024]; while (fd_readable(fd)) { - size_t size = ::read(fd, buffer, sizeof(buffer)); + ssize_t size = ::read(fd, buffer, sizeof(buffer)); if (size <= 0) { + if (size < 0 and errno == EAGAIN) + continue; // try again + watcher.disable(); on_close(); return;