summaryrefslogtreecommitdiffstats
path: root/buildtool.cpp
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2008-06-06 18:36:58 +0000
committerishmal <ishmal@users.sourceforge.net>2008-06-06 18:36:58 +0000
commit95846e122876e55ab9a085a9ece0ea9fd36dd35c (patch)
tree89ace6731f0aab751e83275e363de441f75afd70 /buildtool.cpp
parentRemoving cast and replacing with a proper definition. (diff)
downloadinkscape-95846e122876e55ab9a085a9ece0ea9fd36dd35c.tar.gz
inkscape-95846e122876e55ab9a085a9ece0ea9fd36dd35c.zip
rewrite pipe reading to avoid deadlock
(bzr r5830)
Diffstat (limited to 'buildtool.cpp')
-rw-r--r--buildtool.cpp33
1 files 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 <windows.h>
-#else
-#include <sys/wait.h>
#endif
@@ -4059,6 +4057,8 @@ bool MakeBase::executeCommand(const String &command,
#else /*do it unix style*/
+#include <sys/wait.h>
+
/**
* 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;