state->child_in_buf_avail = ret;
}
+ if (state->child_stdin == -1) {
+ fcntl(state->child_stdout, F_SETFL, 0);
+ __archive_check_child(state->child_stdin, state->child_stdout);
+ goto restart_read;
+ }
+
do {
ret = write(state->child_stdin, state->child_in_buf,
state->child_in_buf_avail);
if (ret == -1 && errno != EAGAIN)
return (-1);
+ if (state->child_stdout == -1) {
+ fcntl(state->child_stdin, F_SETFL, 0);
+ __archive_check_child(state->child_stdin, state->child_stdout);
+ goto restart_write;
+ }
+
do {
ret = read(state->child_stdout,
state->child_buf + state->child_buf_avail,
{
#if defined(HAVE_POLL)
struct pollfd fds[2];
+ int idx;
- fds[0].fd = in;
- fds[0].events = POLLOUT;
- fds[1].fd = out;
- fds[1].events = POLLIN;
+ idx = 0;
+ if (in != -1) {
+ fds[idx].fd = in;
+ fds[idx].events = POLLOUT;
+ ++idx;
+ }
+ if (out != -1) {
+ fds[idx].fd = out;
+ fds[idx].events = POLLIN;
+ ++idx;
+ }
- poll(fds, 2, -1); /* -1 == INFTIM, wait forever */
+ poll(fds, idx, -1); /* -1 == INFTIM, wait forever */
#elif defined(HAVE_SELECT)
fd_set fds_in, fds_out, fds_error;
FD_ZERO(&fds_in);
- FD_SET(out, &fds_in);
FD_ZERO(&fds_out);
- FD_SET(in, &fds_out);
FD_ZERO(&fds_error);
- FD_SET(in, &fds_error);
- FD_SET(out, &fds_error);
+ if (out != -1) {
+ FD_SET(out, &fds_in);
+ FD_SET(out, &fds_error);
+ }
+ if (in != -1) {
+ FD_SET(in, &fds_out);
+ FD_SET(in, &fds_error);
+ }
select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL);
#else
sleep(1);