changeset 955:36eacc322e00

Make sure the check_close() handler runs when a server child process exits
author Matt Johnston <matt@ucc.asn.au>
date Mon, 28 Jul 2014 23:23:49 +0800
parents 356a25a108a3
children 46a0b2ebc22c c4f138dae2fd 1bf92da7a2a0 f92394f3f332
files common-channel.c session.h svr-chansession.c
diffstat 3 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common-channel.c	Mon Jul 28 22:59:16 2014 +0800
+++ b/common-channel.c	Mon Jul 28 23:23:49 2014 +0800
@@ -258,6 +258,12 @@
 			writechannel(channel, channel->errfd, channel->extrabuf);
 			do_check_close = 1;
 		}
+
+		if (ses.channel_signal_pending) {
+			/* SIGCHLD can change channel state for server sessions */
+			do_check_close = 1;
+			ses.channel_signal_pending = 0;
+		}
 	
 		/* handle any channel closing etc */
 		if (do_check_close) {
--- a/session.h	Mon Jul 28 22:59:16 2014 +0800
+++ b/session.h	Mon Jul 28 23:23:49 2014 +0800
@@ -187,6 +187,7 @@
 	unsigned int chansize; /* the number of Channel*s allocated for channels */
 	unsigned int chancount; /* the number of Channel*s in use */
 	const struct ChanType **chantypes; /* The valid channel types */
+	int channel_signal_pending; /* Flag set by sigchld handler */
 
 	/* TCP priority level for the main "port 22" tcp socket */
 	enum dropbear_prio socket_prio;
--- a/svr-chansession.c	Mon Jul 28 22:59:16 2014 +0800
+++ b/svr-chansession.c	Mon Jul 28 23:23:49 2014 +0800
@@ -89,6 +89,9 @@
 
 	const int saved_errno = errno;
 
+	/* Make channel handling code look for closed channels */
+	ses.channel_signal_pending = 1;
+
 	TRACE(("enter sigchld handler"))
 	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
 		TRACE(("sigchld handler: pid %d", pid))