diff options
author | Damien Miller <djm@mindrot.org> | 2005-05-26 12:23:44 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2005-05-26 12:23:44 +1000 |
commit | b253cc42136649e3eac80e02667f8fbc1e43baaa (patch) | |
tree | e3824a905c7b12e4901e60e87ecdc968228e645e /monitor_wrap.c | |
parent | 02e754f1f01470c11a175a0d07381361afe37fff (diff) |
- avsm@cvs.openbsd.org 2005/05/24 17:32:44
[atomicio.c atomicio.h authfd.c monitor_wrap.c msg.c scp.c sftp-client.c]
[ssh-keyscan.c sshconnect.c]
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 'monitor_wrap.c')
-rw-r--r-- | monitor_wrap.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/monitor_wrap.c b/monitor_wrap.c index e1b6512b4..afa612f4e 100644 --- a/monitor_wrap.c +++ b/monitor_wrap.c | |||
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "includes.h" | 27 | #include "includes.h" |
28 | RCSID("$OpenBSD: monitor_wrap.c,v 1.39 2004/07/17 05:31:41 dtucker Exp $"); | 28 | RCSID("$OpenBSD: monitor_wrap.c,v 1.40 2005/05/24 17:32:43 avsm Exp $"); |
29 | 29 | ||
30 | #include <openssl/bn.h> | 30 | #include <openssl/bn.h> |
31 | #include <openssl/dh.h> | 31 | #include <openssl/dh.h> |
@@ -95,9 +95,9 @@ mm_request_send(int sock, enum monitor_reqtype type, Buffer *m) | |||
95 | PUT_32BIT(buf, mlen + 1); | 95 | PUT_32BIT(buf, mlen + 1); |
96 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ | 96 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ |
97 | if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) | 97 | if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) |
98 | fatal("%s: write", __func__); | 98 | fatal("%s: write: %s", __func__, strerror(errno)); |
99 | if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen) | 99 | if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen) |
100 | fatal("%s: write", __func__); | 100 | fatal("%s: write: %s", __func__, strerror(errno)); |
101 | } | 101 | } |
102 | 102 | ||
103 | void | 103 | void |
@@ -105,24 +105,21 @@ mm_request_receive(int sock, Buffer *m) | |||
105 | { | 105 | { |
106 | u_char buf[4]; | 106 | u_char buf[4]; |
107 | u_int msg_len; | 107 | u_int msg_len; |
108 | ssize_t res; | ||
109 | 108 | ||
110 | debug3("%s entering", __func__); | 109 | debug3("%s entering", __func__); |
111 | 110 | ||
112 | res = atomicio(read, sock, buf, sizeof(buf)); | 111 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { |
113 | if (res != sizeof(buf)) { | 112 | if (errno == EPIPE) |
114 | if (res == 0) | ||
115 | cleanup_exit(255); | 113 | cleanup_exit(255); |
116 | fatal("%s: read: %ld", __func__, (long)res); | 114 | fatal("%s: read: %s", __func__, strerror(errno)); |
117 | } | 115 | } |
118 | msg_len = GET_32BIT(buf); | 116 | msg_len = GET_32BIT(buf); |
119 | if (msg_len > 256 * 1024) | 117 | if (msg_len > 256 * 1024) |
120 | fatal("%s: read: bad msg_len %d", __func__, msg_len); | 118 | fatal("%s: read: bad msg_len %d", __func__, msg_len); |
121 | buffer_clear(m); | 119 | buffer_clear(m); |
122 | buffer_append_space(m, msg_len); | 120 | buffer_append_space(m, msg_len); |
123 | res = atomicio(read, sock, buffer_ptr(m), msg_len); | 121 | if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len) |
124 | if (res != msg_len) | 122 | fatal("%s: read: %s", __func__, strerror(errno)); |
125 | fatal("%s: read: %ld != msg_len", __func__, (long)res); | ||
126 | } | 123 | } |
127 | 124 | ||
128 | void | 125 | void |