diff svr-chansession.c @ 416:a01c0c8e543a channel-fix

Improve behaviour when flushing out after a process has exited.
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2007 10:43:16 +0000
parents 173a5f89666c
children b2b67cfcd66e
line wrap: on
line diff
--- a/svr-chansession.c	Tue Feb 06 16:00:18 2007 +0000
+++ b/svr-chansession.c	Fri Feb 09 10:43:16 2007 +0000
@@ -120,9 +120,21 @@
 			/* we use this to determine how pid exited */
 			exit->exitsignal = -1;
 		}
+		
+		/* Make sure that the main select() loop wakes up */
+		while (1) {
+			/* EAGAIN means the pipe's full, so don't need to write anything */
+			/* isserver is just a random byte to write */
+			if (write(ses.signal_pipe[1], &ses.isserver, 1) == 1 || errno == EAGAIN) {
+				break;
+			}
+			if (errno == EINTR) {
+				continue;
+			}
+			dropbear_exit("error writing signal pipe");
+		}
 	}
 
-	
 	sa_chld.sa_handler = sesssigchild_handler;
 	sa_chld.sa_flags = SA_NOCLDSTOP;
 	sigaction(SIGCHLD, &sa_chld, NULL);
@@ -244,16 +256,17 @@
 	unsigned int i;
 	struct logininfo *li;
 
+	TRACE(("enter closechansess"))
+
 	chansess = (struct ChanSess*)channel->typedata;
 
-	send_exitsignalstatus(channel);
-
-	TRACE(("enter closechansess"))
 	if (chansess == NULL) {
 		TRACE(("leave closechansess: chansess == NULL"))
 		return;
 	}
 
+	send_exitsignalstatus(channel);
+
 	m_free(chansess->cmd);
 	m_free(chansess->term);