summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2000-05-17 08:20:17 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2000-05-17 08:20:17 +0000
commitf52cd8d3171054eccbebe0630a19752f1272eb1b (patch)
treee7816e6e9410f346e6e330da1ba8da205406cc58
parent9ec00b9fdfe93fe410f6932f84033553e51b74e2 (diff)
enable nonblocking IO for sshd w/ proto 1, too; split out common code
-rw-r--r--usr.bin/ssh/aux.c34
-rw-r--r--usr.bin/ssh/channels.c19
-rw-r--r--usr.bin/ssh/lib/Makefile2
-rw-r--r--usr.bin/ssh/serverloop.c44
-rw-r--r--usr.bin/ssh/ssh.h8
-rw-r--r--usr.bin/ssh/sshconnect.c17
-rw-r--r--usr.bin/ssh/sshd.c17
7 files changed, 71 insertions, 70 deletions
diff --git a/usr.bin/ssh/aux.c b/usr.bin/ssh/aux.c
new file mode 100644
index 00000000000..04f71dcd9f7
--- /dev/null
+++ b/usr.bin/ssh/aux.c
@@ -0,0 +1,34 @@
+#include "includes.h"
+RCSID("$OpenBSD: aux.c,v 1.1 2000/05/17 08:20:15 markus Exp $");
+
+char *
+chop(char *s)
+{
+ char *t = s;
+ while (*t) {
+ if(*t == '\n' || *t == '\r') {
+ *t = '\0';
+ return s;
+ }
+ t++;
+ }
+ return s;
+
+}
+
+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)
+ return;
+ debug("fd %d setting O_NONBLOCK", fd);
+ val |= O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, val) == -1)
+ error("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd, strerror(errno));
+}
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c
index 5bf1e5b7aea..f7f21731bcb 100644
--- a/usr.bin/ssh/channels.c
+++ b/usr.bin/ssh/channels.c
@@ -17,7 +17,7 @@
*/
#include "includes.h"
-RCSID("$Id: channels.c,v 1.57 2000/05/08 17:42:24 markus Exp $");
+RCSID("$Id: channels.c,v 1.58 2000/05/17 08:20:15 markus Exp $");
#include "ssh.h"
#include "packet.h"
@@ -147,23 +147,6 @@ channel_lookup(int id)
return c;
}
-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)
- return;
- debug("fd %d setting O_NONBLOCK", fd);
- val |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, val) == -1)
- error("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd, strerror(errno));
-}
-
/*
* Register filedescriptors for a channel, used when allocating a channel or
* when the channel consumer/producer is ready, e.g. shell exec'd
diff --git a/usr.bin/ssh/lib/Makefile b/usr.bin/ssh/lib/Makefile
index 35de105b496..aae1677ec7e 100644
--- a/usr.bin/ssh/lib/Makefile
+++ b/usr.bin/ssh/lib/Makefile
@@ -5,7 +5,7 @@ SRCS= authfd.c authfile.c bufaux.c buffer.c canohost.c channels.c \
cipher.c compat.c compress.c crc32.c deattack.c fingerprint.c \
hostfile.c log.c match.c mpaux.c nchan.c packet.c readpass.c \
rsa.c tildexpand.c ttymodes.c uidswap.c xmalloc.c atomicio.c \
- key.c dispatch.c dsa.c kex.c hmac.c uuencode.c
+ key.c dispatch.c dsa.c kex.c hmac.c uuencode.c aux.c
NOPROFILE= yes
NOPIC= yes
diff --git a/usr.bin/ssh/serverloop.c b/usr.bin/ssh/serverloop.c
index 9bf31275bea..a36cb0d96d5 100644
--- a/usr.bin/ssh/serverloop.c
+++ b/usr.bin/ssh/serverloop.c
@@ -250,20 +250,15 @@ process_input(fd_set * readset)
if (len == 0) {
verbose("Connection closed by remote host.");
fatal_cleanup();
+ } else if (len < 0) {
+ if (errno != EINTR && errno != EAGAIN) {
+ verbose("Read error from remote host: %.100s", strerror(errno));
+ fatal_cleanup();
+ }
+ } else {
+ /* Buffer any received data. */
+ packet_process_incoming(buf, len);
}
- /*
- * There is a kernel bug on Solaris that causes select to
- * sometimes wake up even though there is no data available.
- */
- if (len < 0 && errno == EAGAIN)
- len = 0;
-
- if (len < 0) {
- verbose("Read error from remote host: %.100s", strerror(errno));
- fatal_cleanup();
- }
- /* Buffer any received data. */
- packet_process_incoming(buf, len);
}
if (compat20)
return;
@@ -271,9 +266,11 @@ process_input(fd_set * readset)
/* Read and buffer any available stdout data from the program. */
if (!fdout_eof && FD_ISSET(fdout, readset)) {
len = read(fdout, buf, sizeof(buf));
- if (len <= 0)
+ if (len < 0 && (errno == EINTR || errno == EAGAIN)) {
+ /* do nothing */
+ } else if (len <= 0) {
fdout_eof = 1;
- else {
+ } else {
buffer_append(&stdout_buffer, buf, len);
fdout_bytes += len;
}
@@ -281,10 +278,13 @@ process_input(fd_set * readset)
/* Read and buffer any available stderr data from the program. */
if (!fderr_eof && FD_ISSET(fderr, readset)) {
len = read(fderr, buf, sizeof(buf));
- if (len <= 0)
+ if (len < 0 && (errno == EINTR || errno == EAGAIN)) {
+ /* do nothing */
+ } else if (len <= 0) {
fderr_eof = 1;
- else
+ } else {
buffer_append(&stderr_buffer, buf, len);
+ }
}
}
@@ -300,7 +300,9 @@ process_output(fd_set * writeset)
if (!compat20 && fdin != -1 && FD_ISSET(fdin, writeset)) {
len = write(fdin, buffer_ptr(&stdin_buffer),
buffer_len(&stdin_buffer));
- if (len <= 0) {
+ if (len < 0 && (errno == EINTR || errno == EAGAIN)) {
+ /* do nothing */
+ } else if (len <= 0) {
#ifdef USE_PIPES
close(fdin);
#else
@@ -386,6 +388,12 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
fdin = fdin_arg;
fdout = fdout_arg;
fderr = fderr_arg;
+
+ /* nonblocking IO */
+ set_nonblock(fdin);
+ set_nonblock(fdout);
+ set_nonblock(fderr);
+
connection_in = packet_get_connection_in();
connection_out = packet_get_connection_out();
diff --git a/usr.bin/ssh/ssh.h b/usr.bin/ssh/ssh.h
index 0762c964ca2..8f6d1e7d1d9 100644
--- a/usr.bin/ssh/ssh.h
+++ b/usr.bin/ssh/ssh.h
@@ -13,7 +13,7 @@
*
*/
-/* RCSID("$Id: ssh.h,v 1.45 2000/05/08 17:12:16 markus Exp $"); */
+/* RCSID("$Id: ssh.h,v 1.46 2000/05/17 08:20:15 markus Exp $"); */
#ifndef SSH_H
#define SSH_H
@@ -447,6 +447,12 @@ void fatal_remove_cleanup(void (*proc) (void *context), void *context);
*/
char *tilde_expand_filename(const char *filename, uid_t my_uid);
+/* remove newline at end of string */
+char *chop(char *s);
+
+/* set filedescriptor to non-blocking */
+void set_nonblock(int fd);
+
/*
* Performs the interactive session. This handles data transmission between
* the client and the program. Note that the notion of stdin, stdout, and
diff --git a/usr.bin/ssh/sshconnect.c b/usr.bin/ssh/sshconnect.c
index 80beac30680..4325eae747b 100644
--- a/usr.bin/ssh/sshconnect.c
+++ b/usr.bin/ssh/sshconnect.c
@@ -8,7 +8,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshconnect.c,v 1.72 2000/05/04 09:50:22 markus Exp $");
+RCSID("$OpenBSD: sshconnect.c,v 1.73 2000/05/17 08:20:15 markus Exp $");
#include <openssl/bn.h>
#include <openssl/dsa.h>
@@ -297,21 +297,6 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
return 1;
}
-char *
-chop(char *s)
-{
- char *t = s;
- while (*t) {
- if(*t == '\n' || *t == '\r') {
- *t = '\0';
- return s;
- }
- t++;
- }
- return s;
-
-}
-
/*
* Waits for the server identification string, and sends our own
* identification string.
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 0d62320a118..e2a393b8328 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -14,7 +14,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.115 2000/05/03 10:21:49 markus Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.116 2000/05/17 08:20:16 markus Exp $");
#include "xmalloc.h"
#include "rsa.h"
@@ -258,21 +258,6 @@ key_regeneration_alarm(int sig)
errno = save_errno;
}
-char *
-chop(char *s)
-{
- char *t = s;
- while (*t) {
- if(*t == '\n' || *t == '\r') {
- *t = '\0';
- return s;
- }
- t++;
- }
- return s;
-
-}
-
void
sshd_exchange_identification(int sock_in, int sock_out)
{