diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2005-05-24 17:32:45 +0000 |
commit | 8d70480c583a93f537beb6ba10177b405033e6d2 (patch) | |
tree | af6655f91ee72626175bd38e315fcdef4cb74ff3 /usr.bin/ssh/ssh-keyscan.c | |
parent | e4259f82cd9c63cff5f23fc9d63da9a4a294e389 (diff) |
Switch atomicio to use a simpler interface; it now returns a size_t
(containing number of bytes read/written), and indicates error by
returning 0. EOF is signalled by errno==EPIPE.
Typical use now becomes:
if (atomicio(read, ..., len) != len)
err(1,"read");
ok deraadt@, cloder@, djm@
Diffstat (limited to 'usr.bin/ssh/ssh-keyscan.c')
-rw-r--r-- | usr.bin/ssh/ssh-keyscan.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c index 15dfb9c46e7..6dcc4a52483 100644 --- a/usr.bin/ssh/ssh-keyscan.c +++ b/usr.bin/ssh/ssh-keyscan.c @@ -7,7 +7,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-keyscan.c,v 1.53 2005/04/28 10:17:56 moritz Exp $"); +RCSID("$OpenBSD: ssh-keyscan.c,v 1.54 2005/05/24 17:32:44 avsm Exp $"); #include <sys/queue.h> #include <errno.h> @@ -484,10 +484,10 @@ conrecycle(int s) static void congreet(int s) { - int remote_major = 0, remote_minor = 0, n = 0; + int remote_major = 0, remote_minor = 0; char buf[256], *cp; char remote_version[sizeof buf]; - size_t bufsiz; + size_t bufsiz, n = 0; con *c = &fdcon[s]; bufsiz = sizeof(buf); @@ -497,14 +497,17 @@ congreet(int s) *cp = '\n'; cp++; } - if (n < 0) { - if (errno != ECONNREFUSED) - error("read (%s): %s", c->c_name, strerror(errno)); - conrecycle(s); - return; - } if (n == 0) { - error("%s: Connection closed by remote host", c->c_name); + switch (errno) { + case EPIPE: + error("%s: Connection closed by remote host", c->c_name); + break; + case ECONNREFUSED: + break; + default: + error("read (%s): %s", c->c_name, strerror(errno)); + break; + } conrecycle(s); return; } @@ -557,14 +560,14 @@ static void conread(int s) { con *c = &fdcon[s]; - int n; + size_t n; if (c->c_status == CS_CON) { congreet(s); return; } n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off); - if (n < 0) { + if (n == 0) { error("read (%s): %s", c->c_name, strerror(errno)); confree(s); return; |