comparison common-channel.c @ 1829:a7cc3332d8ab

Replace ChanType.sepfds with Channel.bidir_fd This handles the case where a svrchansess has separate FDs for nopty, but a single FD for pty mode. The use of sepfds was also previously incorrect for X11 and agent forwarding
author Matt Johnston <matt@ucc.asn.au>
date Mon, 11 Oct 2021 15:42:14 +0800
parents 3f0ac6bc58a1
children 90ac15aeac43
comparison
equal deleted inserted replaced
1828:3f0ac6bc58a1 1829:a7cc3332d8ab
337 TRACE(("enter channel_connect_done")) 337 TRACE(("enter channel_connect_done"))
338 338
339 if (result == DROPBEAR_SUCCESS) 339 if (result == DROPBEAR_SUCCESS)
340 { 340 {
341 channel->readfd = channel->writefd = sock; 341 channel->readfd = channel->writefd = sock;
342 channel->bidir_fd = 1;
342 channel->conn_pending = NULL; 343 channel->conn_pending = NULL;
343 send_msg_channel_open_confirmation(channel, channel->recvwindow, 344 send_msg_channel_open_confirmation(channel, channel->recvwindow,
344 channel->recvmaxpacket); 345 channel->recvmaxpacket);
345 TRACE(("leave channel_connect_done: success")) 346 TRACE(("leave channel_connect_done: success"))
346 } 347 }
1037 /* close a fd, how is SHUT_RD or SHUT_WR */ 1038 /* close a fd, how is SHUT_RD or SHUT_WR */
1038 static void close_chan_fd(struct Channel *channel, int fd, int how) { 1039 static void close_chan_fd(struct Channel *channel, int fd, int how) {
1039 1040
1040 int closein = 0, closeout = 0; 1041 int closein = 0, closeout = 0;
1041 1042
1042 if (channel->type->sepfds) { 1043 if (channel->bidir_fd) {
1043 TRACE(("SHUTDOWN(%d, %d)", fd, how)) 1044 TRACE(("SHUTDOWN(%d, %d)", fd, how))
1044 shutdown(fd, how); 1045 shutdown(fd, how);
1045 if (how == 0) { 1046 if (how == 0) {
1046 closeout = 1; 1047 closeout = 1;
1047 } else { 1048 } else {
1067 channel->errfd = FD_CLOSED; 1068 channel->errfd = FD_CLOSED;
1068 } 1069 }
1069 1070
1070 /* if we called shutdown on it and all references are gone, then we 1071 /* if we called shutdown on it and all references are gone, then we
1071 * need to close() it to stop it lingering */ 1072 * need to close() it to stop it lingering */
1072 if (channel->type->sepfds && channel->readfd == FD_CLOSED 1073 if (channel->bidir_fd && channel->readfd == FD_CLOSED
1073 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) { 1074 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
1074 TRACE(("CLOSE (finally) of %d", fd)) 1075 TRACE(("CLOSE (finally) of %d", fd))
1075 m_close(fd); 1076 m_close(fd);
1076 } 1077 }
1077 } 1078 }
1100 /* set fd non-blocking */ 1101 /* set fd non-blocking */
1101 setnonblocking(fd); 1102 setnonblocking(fd);
1102 1103
1103 chan->writefd = chan->readfd = fd; 1104 chan->writefd = chan->readfd = fd;
1104 ses.maxfd = MAX(ses.maxfd, fd); 1105 ses.maxfd = MAX(ses.maxfd, fd);
1106 chan->bidir_fd = 1;
1105 1107
1106 chan->await_open = 1; 1108 chan->await_open = 1;
1107 1109
1108 /* now open the channel connection */ 1110 /* now open the channel connection */
1109 CHECKCLEARTOWRITE(); 1111 CHECKCLEARTOWRITE();