From cac8839211fc5bb53592d3d04c344834c4c054df Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 4 Mar 2015 17:54:43 +0100 Subject: Don't abort if the output buffer overflows EAGAIN on write(2) is not really a fatal problem. We can just select(2) and try again when the buffer is ready. We include the signal pipe into the select so that we can abort it. Change-Id: I827a3f184922d696e0e07fe1ac014502af1d51cc Reviewed-by: Rainer Keller --- process.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/process.cpp b/process.cpp index 1320d02..1fe811b 100644 --- a/process.cpp +++ b/process.cpp @@ -122,6 +122,18 @@ void Process::forwardProcessOutput(qintptr fd, const QByteArray &data) while (size > 0) { int written = write(fd, constData, size); if (written == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + fd_set outputFdSet; + FD_ZERO(&outputFdSet); + FD_SET(fd, &outputFdSet); + fd_set inputFdSet; + FD_ZERO(&inputFdSet); + FD_SET(pipefd[0], &inputFdSet); + if (select(qMax(fd, pipefd[0]) + 1, &inputFdSet, &outputFdSet, NULL, NULL) > 0 && + !FD_ISSET(pipefd[0], &inputFdSet)) + continue; + // else fprintf below will output the appropriate errno + } fprintf(stderr, "Cannot forward application output: %d - %s\n", errno, strerror(errno)); qApp->quit(); break; -- cgit v1.2.3