Mercurial > dropbear
comparison common-channel.c @ 1828:3f0ac6bc58a1
- Remove "flushing" handling for exited processes, it should be
handled by normal file descriptor reads.
- Fix sesscheckclose() handling if a channel was closed before a
process was ever launched
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 11 Oct 2021 15:16:54 +0800 |
parents | 8a78cc13eb30 |
children | a7cc3332d8ab |
comparison
equal
deleted
inserted
replaced
1827:8a78cc13eb30 | 1828:3f0ac6bc58a1 |
---|---|
152 newchan->typedata = NULL; | 152 newchan->typedata = NULL; |
153 newchan->writefd = FD_UNINIT; | 153 newchan->writefd = FD_UNINIT; |
154 newchan->readfd = FD_UNINIT; | 154 newchan->readfd = FD_UNINIT; |
155 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ | 155 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ |
156 newchan->await_open = 0; | 156 newchan->await_open = 0; |
157 newchan->flushing = 0; | |
158 | 157 |
159 newchan->writebuf = cbuf_new(opts.recv_window); | 158 newchan->writebuf = cbuf_new(opts.recv_window); |
160 newchan->recvwindow = opts.recv_window; | 159 newchan->recvwindow = opts.recv_window; |
161 | 160 |
162 newchan->extrabuf = NULL; /* The user code can set it up */ | 161 newchan->extrabuf = NULL; /* The user code can set it up */ |
282 channel->errfd, channel->sent_close, channel->recv_close)) | 281 channel->errfd, channel->sent_close, channel->recv_close)) |
283 TRACE2(("writebuf size %d extrabuf size %d", | 282 TRACE2(("writebuf size %d extrabuf size %d", |
284 channel->writebuf ? cbuf_getused(channel->writebuf) : 0, | 283 channel->writebuf ? cbuf_getused(channel->writebuf) : 0, |
285 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0)) | 284 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0)) |
286 | 285 |
287 if (!channel->flushing | |
288 && !channel->sent_close | |
289 && channel->type->check_close | |
290 && channel->type->check_close(channel)) | |
291 { | |
292 channel->flushing = 1; | |
293 } | |
294 | |
295 /* if a type-specific check_close is defined we will only exit | 286 /* if a type-specific check_close is defined we will only exit |
296 once that has been triggered. this is only used for a server "session" | 287 once that has been triggered. this is only used for a server "session" |
297 channel, to ensure that the shell has exited (and the exit status | 288 channel, to ensure that the shell has exited (and the exit status |
298 retrieved) before we close things up. */ | 289 retrieved) before we close things up. */ |
299 if (!channel->type->check_close | 290 if (!channel->type->check_close |
313 | 304 |
314 if ((channel->recv_eof && !write_pending(channel)) | 305 if ((channel->recv_eof && !write_pending(channel)) |
315 /* have a server "session" and child has exited */ | 306 /* have a server "session" and child has exited */ |
316 || (channel->type->check_close && close_allowed)) { | 307 || (channel->type->check_close && close_allowed)) { |
317 close_chan_fd(channel, channel->writefd, SHUT_WR); | 308 close_chan_fd(channel, channel->writefd, SHUT_WR); |
318 } | |
319 | |
320 /* Special handling for flushing read data after an exit. We | |
321 read regardless of whether the select FD was set, | |
322 and if there isn't data available, the channel will get closed. */ | |
323 if (channel->flushing) { | |
324 TRACE(("might send data, flushing")) | |
325 if (channel->readfd >= 0 && channel->transwindow > 0) { | |
326 TRACE(("send data readfd")) | |
327 send_msg_channel_data(channel, 0); | |
328 } | |
329 if (ERRFD_IS_READ(channel) && channel->errfd >= 0 | |
330 && channel->transwindow > 0) { | |
331 TRACE(("send data errfd")) | |
332 send_msg_channel_data(channel, 1); | |
333 } | |
334 } | 309 } |
335 | 310 |
336 /* If we're not going to send any more data, send EOF */ | 311 /* If we're not going to send any more data, send EOF */ |
337 if (!channel->sent_eof | 312 if (!channel->sent_eof |
338 && channel->readfd == FD_CLOSED | 313 && channel->readfd == FD_CLOSED |
777 buf_putint(ses.writepayload, len); | 752 buf_putint(ses.writepayload, len); |
778 | 753 |
779 channel->transwindow -= len; | 754 channel->transwindow -= len; |
780 | 755 |
781 encrypt_packet(); | 756 encrypt_packet(); |
782 | |
783 /* If we receive less data than we requested when flushing, we've | |
784 reached the equivalent of EOF */ | |
785 if (channel->flushing && len < (ssize_t)maxlen) | |
786 { | |
787 TRACE(("closing from channel, flushing out.")) | |
788 close_chan_fd(channel, fd, SHUT_RD); | |
789 } | |
790 TRACE(("leave send_msg_channel_data")) | 757 TRACE(("leave send_msg_channel_data")) |
791 } | 758 } |
792 | 759 |
793 /* We receive channel data */ | 760 /* We receive channel data */ |
794 void recv_msg_channel_data() { | 761 void recv_msg_channel_data() { |