summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-05-12 00:08:37 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-05-12 00:08:37 +0000
commitc93e84c2cecf2b968a069de595aff374abe89036 (patch)
treea2fd75f89b96705ccfd0cd8f85a9db5e582c2fca
parentddb4f24056225322bc97eb366cbe5b2927fd7c89 (diff)
- 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().
-rw-r--r--ChangeLog8
-rw-r--r--clientloop.c27
-rw-r--r--defines.h4
-rw-r--r--misc.c29
-rw-r--r--misc.h5
5 files changed, 58 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 7fe38932..3833f303 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+20010512
+ - OpenBSD CVS Sync
+ - 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().
+
20010511
- OpenBSD CVS Sync
- markus@cvs.openbsd.org 2001/05/09 22:51:57
@@ -5394,4 +5400,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
-$Id: ChangeLog,v 1.1216 2001/05/10 23:26:11 mouring Exp $
+$Id: ChangeLog,v 1.1217 2001/05/12 00:08:37 mouring Exp $
diff --git a/clientloop.c b/clientloop.c
index b2b7debc..ba957fe4 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 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
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;
}
diff --git a/defines.h b/defines.h
index ebe8812a..347aad5a 100644
--- a/defines.h
+++ b/defines.h
@@ -1,7 +1,7 @@
#ifndef _DEFINES_H
#define _DEFINES_H
-/* $Id: defines.h,v 1.63 2001/05/09 00:38:21 mouring Exp $ */
+/* $Id: defines.h,v 1.64 2001/05/12 00:08:38 mouring Exp $ */
/* Some platforms need this for the _r() functions */
#if !defined(_REENTRANT) && !defined(SNI)
@@ -418,7 +418,7 @@ struct winsize {
#endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */
#if !defined(HAVE_ATEXIT) && defined(HAVE_ON_EXIT)
-# define atexit(a) on_exit(a)
+# define atexit(a) on_exit(a, NULL)
#else
# if defined(HAVE_XATEXIT)
# define atexit(a) xatexit(a)
diff --git a/misc.c b/misc.c
index d12bcefe..b0fdbe03 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.7 2001/05/08 19:45:24 mouring Exp $ */
+/* $OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -25,7 +25,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: misc.c,v 1.7 2001/05/08 19:45:24 mouring Exp $");
+RCSID("$OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $");
#include "misc.h"
#include "log.h"
@@ -50,13 +50,14 @@ void
set_nonblock(int fd)
{
int val;
+
val = fcntl(fd, F_GETFL, 0);
if (val < 0) {
error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
return;
}
if (val & O_NONBLOCK) {
- debug("fd %d IS O_NONBLOCK", fd);
+ debug2("fd %d is O_NONBLOCK", fd);
return;
}
debug("fd %d setting O_NONBLOCK", fd);
@@ -67,6 +68,28 @@ set_nonblock(int fd)
fd, strerror(errno));
}
+void
+unset_nonblock(int fd)
+{
+ int val;
+
+ val = fcntl(fd, F_GETFL, 0);
+ if (val < 0) {
+ error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
+ return;
+ }
+ if (!(val & O_NONBLOCK)) {
+ debug2("fd %d is not O_NONBLOCK", fd);
+ return;
+ }
+ debug("fd %d setting O_NONBLOCK", fd);
+ val &= ~O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, val) == -1)
+ if (errno != ENODEV)
+ error("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
+ fd, strerror(errno));
+}
+
/* Characters considered whitespace in strsep calls. */
#define WHITESPACE " \t\r\n"
diff --git a/misc.h b/misc.h
index b30fe488..01a736c0 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.6 2001/05/08 19:45:24 mouring Exp $ */
+/* $OpenBSD: misc.h,v 1.7 2001/05/11 14:59:56 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -17,8 +17,9 @@ char *chop(char *s);
/* return next token in configuration line */
char *strdelim(char **s);
-/* set filedescriptor to non-blocking */
+/* set/unset filedescriptor to non-blocking */
void set_nonblock(int fd);
+void unset_nonblock(int fd);
struct passwd * pwcopy(struct passwd *pw);