comparison common-channel.c @ 261:82393badfa24

* common-channel.c: get rid of the read()-from-writefd code which caused problems when redirecting to or from /dev/null
author Matt Johnston <matt@ucc.asn.au>
date Tue, 06 Dec 2005 17:32:53 +0000
parents 84925eceeb13
children 92b9b182c615 3cea9d789cca 8ed0dce45126
comparison
equal deleted inserted replaced
259:c049490e43fe 261:82393badfa24
201 if (channel->extrabuf == NULL && 201 if (channel->extrabuf == NULL &&
202 channel->errfd >= 0 && FD_ISSET(channel->errfd, readfds)) { 202 channel->errfd >= 0 && FD_ISSET(channel->errfd, readfds)) {
203 send_msg_channel_data(channel, 1, SSH_EXTENDED_DATA_STDERR); 203 send_msg_channel_data(channel, 1, SSH_EXTENDED_DATA_STDERR);
204 } 204 }
205 205
206 /* if we can read from the writefd, it might be closed, so we try to
207 * see if it has errors */
208 if (channel->writefd >= 0 && channel->writefd != channel->readfd
209 && FD_ISSET(channel->writefd, readfds)) {
210 if (channel->initconn) {
211 /* Handling for "in progress" connection - this is needed
212 * to avoid spinning 100% CPU when we connect to a server
213 * which doesn't send anything (tcpfwding) */
214 checkinitdone(channel);
215 continue; /* Important not to use the channel after
216 checkinitdone(), as it may be NULL */
217 }
218 ret = write(channel->writefd, NULL, 0); /* Fake write */
219 if (ret < 0 && errno != EINTR && errno != EAGAIN) {
220 closewritefd(channel);
221 }
222 }
223
224 /* write to program/pipe stdin */ 206 /* write to program/pipe stdin */
225 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) { 207 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
226 if (channel->initconn) { 208 if (channel->initconn) {
227 checkinitdone(channel); 209 checkinitdone(channel);
228 continue; /* Important not to use the channel after 210 continue; /* Important not to use the channel after
443 if (channel->extrabuf == NULL && channel->errfd >= 0) { 425 if (channel->extrabuf == NULL && channel->errfd >= 0) {
444 FD_SET(channel->errfd, readfds); 426 FD_SET(channel->errfd, readfds);
445 } 427 }
446 } 428 }
447 429
448 /* For checking FD status (ie closure etc) - we don't actually 430 /* Stuff from the wire */
449 * read data from writefd */
450 TRACE(("writefd = %d, readfd %d, errfd %d, bufused %d",
451 channel->writefd, channel->readfd,
452 channel->errfd,
453 cbuf_getused(channel->writebuf) ))
454 if (channel->writefd >= 0 && channel->writefd != channel->readfd) {
455 FD_SET(channel->writefd, readfds);
456 }
457
458 /* Stuff from the wire, to local program/shell/user etc */
459 if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 ) 431 if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 )
460 || channel->initconn) { 432 || channel->initconn) {
461 433
462 FD_SET(channel->writefd, writefds); 434 FD_SET(channel->writefd, writefds);
463 } 435 }