summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-03-04 17:54:43 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-03-24 13:51:08 +0200
commitcac8839211fc5bb53592d3d04c344834c4c054df (patch)
treec5927ba9dde29cb2004d9261e7094d20451fd835
parentadf95bca87410244fde97fc732dcc346e25e0dca (diff)
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 <rainer.keller@theqtcompany.com>
-rw-r--r--process.cpp12
1 files changed, 12 insertions, 0 deletions
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;