From c8873dd749805443359ac8c2ebc8e483d2f82672 Mon Sep 17 00:00:00 2001 From: ishmal Date: Fri, 6 Jun 2008 18:36:58 +0000 Subject: [PATCH] rewrite pipe reading to avoid deadlock --- buildtool.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/buildtool.cpp b/buildtool.cpp index 1dee10448..da482971b 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -59,8 +59,6 @@ #ifdef __WIN32__ #include -#else -#include #endif @@ -4059,6 +4057,8 @@ bool MakeBase::executeCommand(const String &command, #else /*do it unix style*/ +#include + /** * Execute a system call, using pipes to send data to the * program's stdin, and reading stdout and stderr. @@ -4119,25 +4119,28 @@ bool MakeBase::executeCommand(const String &command, String outb; String errb; - while (1) - { - unsigned char outch; - int rout = read(outfds[0], &outch, 1); - if (rout>0) - outb.push_back(outch); - unsigned char errch; - int rerr = read(errfds[0], &errch, 1); - if (rerr>0) - errb.push_back(errch); - if (rout <=0 && rerr <=0) + FILE *stdOutRead = fdopen(outfds[0], "r"); + while (!feof(stdOutRead)) + { + char ch = fgetc(stdOutRead); + if (ch<0) + break; + outb.push_back(ch); + } + FILE *stdErrRead = fdopen(errfds[0], "r"); + while (!feof(stdErrRead)) + { + char ch = fgetc(stdErrRead); + if (ch<0) break; + errb.push_back(ch); } int childReturnValue; wait(&childReturnValue); - close(outfds[0]); - close(errfds[0]); + fclose(stdOutRead); + fclose(stdErrRead); outbuf = outb; errbuf = errb; -- 2.30.2