EOF handling) in the loop we do the FD_SET, not after we drain the
buffer after write() since we don't know what order reads and writes
will occur in.
FD_SET(sv[0], fdsr);
for (iob = iobufs; iob; iob = iob->next) {
+ if (iob->rfd == -1 && iob->wfd == -1)
+ continue;
+ if (iob->off == iob->len) {
+ iob->off = iob->len = 0;
+ /* Forward the EOF from reader to writer. */
+ if (iob->rfd == -1) {
+ close(iob->wfd);
+ iob->wfd = -1;
+ }
+ }
/* Don't read/write /dev/tty if we are not in the foreground. */
if (iob->rfd != -1 &&
(ttymode == TERM_RAW || iob->rfd != script_fds[SFD_USERTTY])) {
} else {
iob->off += n;
}
- if (iob->off == iob->len) {
- iob->off = iob->len = 0;
- /* Forward the EOF from reader to writer. */
- if (iob->rfd == -1) {
- close(iob->wfd);
- iob->wfd = -1;
- }
- }
}
}
}