- len += count;
- if (len >= ressize-1) {
- err("ressize %ld too short", (long)ressize);
- retval = -1;
- break;
+ count = read(outpipe[0], inbuf, sizeof(inbuf)-1);
+ if (count <= 0) {
+ close(outpipe[0]);
+ outpipe[0] = -1;
+ if (count < 0) {
+ err("stdin read failed with '%s'", strerror(errno));
+ retval = -1;
+ }
+ continue;
+ }
+ inbuf[count] = '\0';
+ dbg("stdout: '%s'", inbuf);
+
+ if (result) {
+ if (respos + count >= ressize) {
+ err("ressize %ld too short", (long)ressize);
+ retval = -1;
+ continue;
+ }
+ memcpy(&result[respos], inbuf, count);
+ respos += count;
+ }
+ }
+
+ /* get stderr */
+ if (errpipe[0] > 0 && FD_ISSET(errpipe[0], &readfds)) {
+ char errbuf[1024];
+
+ count = read(errpipe[0], errbuf, sizeof(errbuf)-1);
+ if (count <= 0) {
+ close(errpipe[0]);
+ errpipe[0] = -1;
+ if (count < 0)
+ err("stderr read failed with '%s'", strerror(errno));
+ continue;
+ }
+ errbuf[count] = '\0';
+ dbg("stderr: '%s'", errbuf);