From 8a27fa9c617533e76673ce61a65e2ba869b52208 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 31 Aug 2020 20:07:13 -0400 Subject: add upstream 11.1 --- zen/shell_execute.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'zen/shell_execute.cpp') diff --git a/zen/shell_execute.cpp b/zen/shell_execute.cpp index 90ccfdf3..241b9786 100644 --- a/zen/shell_execute.cpp +++ b/zen/shell_execute.cpp @@ -89,7 +89,7 @@ std::pair zen::consoleExecute(const Zstring& cm THROW_LAST_SYS_ERROR("open"); auto guardTmpFile = makeGuard([&] { ::close(fdTempFile); }); - //"deleting while handles are open" == FILE_FLAG_DELETE_ON_CLOSE + //"deleting while handle is open" == FILE_FLAG_DELETE_ON_CLOSE if (::unlink(tempFilePath.c_str()) != 0) THROW_LAST_SYS_ERROR("unlink"); @@ -158,11 +158,16 @@ std::pair zen::consoleExecute(const Zstring& cm guardFdLifeSignW.dismiss(); ::close(fdLifeSignW); //[!] make sure we get EOF when fd is closed by child! - if (::fcntl(fdLifeSignR, F_SETFL, O_NONBLOCK) != 0) - THROW_LAST_SYS_ERROR("fcntl(O_NONBLOCK)"); + const int flags = ::fcntl(fdLifeSignR, F_GETFL); + if (flags == -1) + THROW_LAST_SYS_ERROR("fcntl(F_GETFL)"); + + if (::fcntl(fdLifeSignR, F_SETFL, flags | O_NONBLOCK) == -1) + THROW_LAST_SYS_ERROR("fcntl(F_SETFL, O_NONBLOCK)"); + const auto endTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(*timeoutMs); - for (;;) //EINTR handling? => allow interrupt!? + for (;;) //EINTR handling? => allow interruption!? { //read until EAGAIN char buf[16]; -- cgit