diff common-channel.c @ 1835:90ac15aeac43

Bring back recently removed channel->flushing This resolves the "sleep 10&echo hello" case which should return immediately
author Matt Johnston <matt@codeconstruct.com.au>
date Thu, 14 Oct 2021 20:55:15 +0800
parents a7cc3332d8ab
children 1d86a58fb52d
line wrap: on
line diff
--- a/common-channel.c	Tue Oct 12 23:32:10 2021 +0800
+++ b/common-channel.c	Thu Oct 14 20:55:15 2021 +0800
@@ -285,14 +285,27 @@
 
 	/* if a type-specific check_close is defined we will only exit
 	   once that has been triggered. this is only used for a server "session"
-	   channel, to ensure that the shell has exited (and the exit status 
+	   channel, to ensure that the shell has exited (and the exit status
 	   retrieved) before we close things up. */
-	if (!channel->type->check_close	
+	if (!channel->type->check_close
 		|| channel->sent_close
 		|| channel->type->check_close(channel)) {
 		close_allowed = 1;
 	}
 
+	/* In flushing mode we close FDs as soon as pipes are empty.
+	This is used to drain out FDs when the process exits, in the case
+	where the FD doesn't have EOF - "sleep 10&echo hello" case */
+	if (channel->flushing) {
+		if (channel->readfd >= 0 && !fd_read_pending(channel->readfd)) {
+			close_chan_fd(channel, channel->readfd, SHUT_RD);
+		}
+		if (ERRFD_IS_READ(channel)
+			&& channel->errfd >= 0 && !fd_read_pending(channel->errfd)) {
+			close_chan_fd(channel, channel->errfd, SHUT_RD);
+		}
+	}
+
 	if (channel->recv_close && !write_pending(channel) && close_allowed) {
 		if (!channel->sent_close) {
 			TRACE(("Sending MSG_CHANNEL_CLOSE in response to same."))