- markus@cvs.openbsd.org 2001/05/11 14:59:56
     [clientloop.c misc.c misc.h]
     add unset_nonblock for stdout/err flushing in client_loop().
diff --git a/clientloop.c b/clientloop.c
index b2b7deb..ba957fe 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -59,7 +59,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.69 2001/05/08 19:17:31 markus Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.70 2001/05/11 14:59:55 markus Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -935,22 +935,35 @@
 		snprintf(buf, sizeof buf, "Connection to %.64s closed.\r\n", host);
 		buffer_append(&stderr_buffer, buf, strlen(buf));
 	}
+
+	/* restore blocking io */
+	if (!isatty(fileno(stdin)))
+		unset_nonblock(fileno(stdin));
+	if (!isatty(fileno(stdout)))
+		unset_nonblock(fileno(stdout));
+	if (!isatty(fileno(stderr)))
+		unset_nonblock(fileno(stderr));
+
 	/* Output any buffered data for stdout. */
-	if (buffer_len(&stdout_buffer) > 0) {
-		len = atomicio(write, fileno(stdout), buffer_ptr(&stdout_buffer),
+	while (buffer_len(&stdout_buffer) > 0) {
+		len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
 		    buffer_len(&stdout_buffer));
-		if (len != buffer_len(&stdout_buffer))
+		if (len <= 0) {
 			error("Write failed flushing stdout buffer.");
+			break;
+		}
 		buffer_consume(&stdout_buffer, len);
 		stdout_bytes += len;
 	}
 
 	/* Output any buffered data for stderr. */
-	if (buffer_len(&stderr_buffer) > 0) {
-		len = atomicio(write, fileno(stderr), buffer_ptr(&stderr_buffer),
+	while (buffer_len(&stderr_buffer) > 0) {
+		len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
 		    buffer_len(&stderr_buffer));
-		if (len != buffer_len(&stderr_buffer))
+		if (len <= 0) {
 			error("Write failed flushing stderr buffer.");
+			break;
+		}
 		buffer_consume(&stderr_buffer, len);
 		stderr_bytes += len;
 	}