Go back to reseting io_buffer offset and length (and now also the

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.
This commit is contained in:
Todd C. Miller
2010-05-05 16:11:13 -04:00
parent 0af98f2e9d
commit 3cbbf27e9d

View File

@@ -674,6 +674,16 @@ script_execve(struct command_details *details, char *argv[], char *envp[],
FD_SET(sv[0], fdsr); FD_SET(sv[0], fdsr);
for (iob = iobufs; iob; iob = iob->next) { 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. */ /* Don't read/write /dev/tty if we are not in the foreground. */
if (iob->rfd != -1 && if (iob->rfd != -1 &&
(ttymode == TERM_RAW || iob->rfd != script_fds[SFD_USERTTY])) { (ttymode == TERM_RAW || iob->rfd != script_fds[SFD_USERTTY])) {
@@ -786,14 +796,6 @@ script_execve(struct command_details *details, char *argv[], char *envp[],
} else { } else {
iob->off += n; 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;
}
}
} }
} }
} }