diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2008-06-06 19:04:52 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2008-06-06 19:04:52 +0000 |
| commit | e24204adb8925e1c37ecef410c34418ec3ad4c8f (patch) | |
| tree | 316fc59da189b466a82c60da49d7b9e4a1b8a9d1 /buildtool.cpp | |
| parent | rewrite pipe reading to avoid deadlock (diff) | |
| download | inkscape-e24204adb8925e1c37ecef410c34418ec3ad4c8f.tar.gz inkscape-e24204adb8925e1c37ecef410c34418ec3ad4c8f.zip | |
rewrite pipe reading to avoid deadlock
(bzr r5831)
Diffstat (limited to 'buildtool.cpp')
| -rw-r--r-- | buildtool.cpp | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/buildtool.cpp b/buildtool.cpp index da482971b..f4e4f8c99 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -4059,6 +4059,8 @@ bool MakeBase::executeCommand(const String &command, #include <sys/wait.h> + + /** * Execute a system call, using pipes to send data to the * program's stdin, and reading stdout and stderr. @@ -4119,28 +4121,50 @@ bool MakeBase::executeCommand(const String &command, String outb; String errb; - 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)) + int outRead = outfds[0]; + int errRead = errfds[0]; + int max = outRead; + if (errRead > max) + max = errRead; + + bool outOpen = true; + bool errOpen = true; + + while (outOpen && errOpen) { - char ch = fgetc(stdErrRead); - if (ch<0) + char ch; + fd_set fdset; + FD_ZERO(&fdset); + if (outOpen) + FD_SET(outRead, &fdset); + if (errOpen) + FD_SET(errRead, &fdset); + int ret = select(max+1, &fdset, NULL, NULL, NULL); + if (ret < 0) break; - errb.push_back(ch); + if (FD_ISSET(outRead, &fdset)) + { + read(outRead, &ch, 1); + if (ch <= 0) + outOpen = false; + else + outb.push_back(ch); + } + if (FD_ISSET(errRead, &fdset)) + { + read(errRead, &ch, 1); + if (ch <= 0) + errOpen = false; + else + errb.push_back(ch); + } } int childReturnValue; wait(&childReturnValue); - fclose(stdOutRead); - fclose(stdErrRead); + close(outRead); + close(errRead); outbuf = outb; errbuf = errb; |
