Call for testing: OpenSSH-6.5

Darren Tucker dtucker at zip.com.au
Sat Jan 25 15:14:57 EST 2014


Maybe there's something wrapping write() on your system too?  Try adding
this to the start of atomicio.c:atomicio6():

printf(stderr, "read %x write %x argument %x\n", read, vwrite, f);

then compile it and run a small scp:

$ ./scp testfile localhost:/tmp/
read b73eced0 write b73ecf50 argument b73eced0

The patch below makes the first argument to atomicio an int rather than
a function pointer.

On the plus side: it also allows the removal of some hacks around
vwrite/writev.  On the minus side: it's a large change albeit mostly
mechanical.

Index: atomicio.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/atomicio.c,v
retrieving revision 1.40
diff -u -p -r1.40 atomicio.c
--- atomicio.c	24 Sep 2010 12:15:11 -0000	1.40
+++ atomicio.c	25 Jan 2014 04:04:41 -0000
@@ -45,10 +45,10 @@
 #include "atomicio.h"
 
 /*
- * ensure all of data on socket comes through. f==read || f==vwrite
+ * ensure all of data on socket comes through.
  */
 size_t
-atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
+atomicio6(int operation, int fd, void *_s, size_t n,
     int (*cb)(void *, size_t), void *cb_arg)
 {
 	char *s = _s;
@@ -57,9 +57,12 @@ atomicio6(ssize_t (*f) (int, void *, siz
 	struct pollfd pfd;
 
 	pfd.fd = fd;
-	pfd.events = f == read ? POLLIN : POLLOUT;
+	pfd.events = operation == ATOMICIO_READ ? POLLIN : POLLOUT;
 	while (n > pos) {
-		res = (f) (fd, s + pos, n - pos);
+		if (operation == ATOMICIO_READ)
+			res = read(fd, s + pos, n - pos);
+		else
+			res = write(fd, s + pos, n - pos);
 		switch (res) {
 		case -1:
 			if (errno == EINTR)
@@ -84,17 +87,16 @@ atomicio6(ssize_t (*f) (int, void *, siz
 }
 
 size_t
-atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
+atomicio(int operation, int fd, void *_s, size_t n)
 {
-	return atomicio6(f, fd, _s, n, NULL, NULL);
+	return atomicio6(operation, fd, _s, n, NULL, NULL);
 }
 
 /*
- * ensure all of data on socket comes through. f==readv || f==writev
+ * ensure all of data on socket comes through.
  */
 size_t
-atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
-    const struct iovec *_iov, int iovcnt,
+atomiciov6(int operation, int fd, const struct iovec *_iov, int iovcnt,
     int (*cb)(void *, size_t), void *cb_arg)
 {
 	size_t pos = 0, rem;
@@ -109,20 +111,20 @@ atomiciov6(ssize_t (*f) (int, const stru
 	/* Make a copy of the iov array because we may modify it below */
 	memcpy(iov, _iov, iovcnt * sizeof(*_iov));
 
-#ifndef BROKEN_READV_COMPARISON
 	pfd.fd = fd;
-	pfd.events = f == readv ? POLLIN : POLLOUT;
-#endif
+	pfd.events = operation == ATOMICIO_READ ? POLLIN : POLLOUT;
+
 	for (; iovcnt > 0 && iov[0].iov_len > 0;) {
-		res = (f) (fd, iov, iovcnt);
+		if (operation == ATOMICIO_READ)
+			res = readv(fd, iov, iovcnt);
+		else
+			res = writev(fd, iov, iovcnt);
 		switch (res) {
 		case -1:
 			if (errno == EINTR)
 				continue;
 			if (errno == EAGAIN || errno == EWOULDBLOCK) {
-#ifndef BROKEN_READV_COMPARISON
 				(void)poll(&pfd, 1, -1);
-#endif
 				continue;
 			}
 			return 0;
@@ -158,8 +160,8 @@ atomiciov6(ssize_t (*f) (int, const stru
 }
 
 size_t
-atomiciov(ssize_t (*f) (int, const struct iovec *, int), int fd,
+atomiciov(int operation, int fd,
     const struct iovec *_iov, int iovcnt)
 {
-	return atomiciov6(f, fd, _iov, iovcnt, NULL, NULL);
+	return atomiciov6(operation, fd, _iov, iovcnt, NULL, NULL);
 }
Index: atomicio.h
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/atomicio.h,v
retrieving revision 1.11
diff -u -p -r1.11 atomicio.h
--- atomicio.h	24 Sep 2010 12:15:11 -0000	1.11
+++ atomicio.h	25 Jan 2014 03:54:08 -0000
@@ -29,23 +29,21 @@
 #ifndef _ATOMICIO_H
 #define _ATOMICIO_H
 
+#define ATOMICIO_READ	0
+#define ATOMICIO_WRITE	1
+
 /*
  * Ensure all of data on socket comes through. f==read || f==vwrite
  */
-size_t
-atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
+size_t atomicio6(int operation, int fd, void *_s, size_t n,
     int (*cb)(void *, size_t), void *);
-size_t	atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
-
-#define vwrite (ssize_t (*)(int, void *, size_t))write
+size_t	atomicio(int operation, int, void *, size_t);
 
 /*
  * ensure all of data on socket comes through. f==readv || f==writev
  */
-size_t
-atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
+size_t atomiciov6(int operation, int fd,
     const struct iovec *_iov, int iovcnt, int (*cb)(void *, size_t), void *);
-size_t	atomiciov(ssize_t (*)(int, const struct iovec *, int),
-    int, const struct iovec *, int);
+size_t	atomiciov(int operation, int, const struct iovec *, int);
 
 #endif /* _ATOMICIO_H */
Index: auth2.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/auth2.c,v
retrieving revision 1.159
diff -u -p -r1.159 auth2.c
--- auth2.c	1 Jun 2013 21:41:51 -0000	1.159
+++ auth2.c	25 Jan 2014 03:54:07 -0000
@@ -126,7 +126,7 @@ auth2_read_banner(void)
 
 	len = (size_t)st.st_size;		/* truncate */
 	banner = xmalloc(len + 1);
-	n = atomicio(read, fd, banner, len);
+	n = atomicio(ATOMICIO_READ, fd, banner, len);
 	close(fd);
 
 	if (n != len) {
Index: authfd.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/authfd.c,v
retrieving revision 1.88
diff -u -p -r1.88 authfd.c
--- authfd.c	29 Dec 2013 06:49:56 -0000	1.88
+++ authfd.c	25 Jan 2014 03:54:11 -0000
@@ -134,8 +134,8 @@ ssh_request_reply(AuthenticationConnecti
 	put_u32(buf, len);
 
 	/* Send the length and then the packet to the agent. */
-	if (atomicio(vwrite, auth->fd, buf, 4) != 4 ||
-	    atomicio(vwrite, auth->fd, buffer_ptr(request),
+	if (atomicio(ATOMICIO_WRITE, auth->fd, buf, 4) != 4 ||
+	    atomicio(ATOMICIO_WRITE, auth->fd, buffer_ptr(request),
 	    buffer_len(request)) != buffer_len(request)) {
 		error("Error writing to authentication socket.");
 		return 0;
@@ -144,7 +144,7 @@ ssh_request_reply(AuthenticationConnecti
 	 * Wait for response from the agent.  First read the length of the
 	 * response packet.
 	 */
-	if (atomicio(read, auth->fd, buf, 4) != 4) {
+	if (atomicio(ATOMICIO_READ, auth->fd, buf, 4) != 4) {
 	    error("Error reading response length from authentication socket.");
 	    return 0;
 	}
@@ -160,7 +160,7 @@ ssh_request_reply(AuthenticationConnecti
 		l = len;
 		if (l > sizeof(buf))
 			l = sizeof(buf);
-		if (atomicio(read, auth->fd, buf, l) != l) {
+		if (atomicio(ATOMICIO_READ, auth->fd, buf, l) != l) {
 			error("Error reading response from authentication socket.");
 			return 0;
 		}
Index: authfile.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/authfile.c,v
retrieving revision 1.106
diff -u -p -r1.106 authfile.c
--- authfile.c	29 Dec 2013 06:50:15 -0000	1.106
+++ authfile.c	25 Jan 2014 03:54:12 -0000
@@ -568,7 +568,7 @@ key_save_private_blob(Buffer *keybuf, co
 		error("open %s failed: %s.", filename, strerror(errno));
 		return 0;
 	}
-	if (atomicio(vwrite, fd, buffer_ptr(keybuf),
+	if (atomicio(ATOMICIO_WRITE, fd, buffer_ptr(keybuf),
 	    buffer_len(keybuf)) != buffer_len(keybuf)) {
 		error("write to key file %s failed: %s", filename,
 		    strerror(errno));
@@ -696,7 +696,7 @@ key_load_file(int fd, const char *filena
 	}
 	buffer_clear(blob);
 	for (;;) {
-		if ((len = atomicio(read, fd, buf, sizeof(buf))) == 0) {
+		if ((len = atomicio(ATOMICIO_READ, fd, buf, sizeof(buf))) == 0) {
 			if (errno == EPIPE)
 				break;
 			debug("%s: read from key file %.200s%sfailed: %.100s",
Index: clientloop.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/clientloop.c,v
retrieving revision 1.245
diff -u -p -r1.245 clientloop.c
--- clientloop.c	21 Nov 2013 02:57:15 -0000	1.245
+++ clientloop.c	25 Jan 2014 03:54:08 -0000
@@ -687,10 +687,10 @@ client_suspend_self(Buffer *bin, Buffer 
 {
 	/* Flush stdout and stderr buffers. */
 	if (buffer_len(bout) > 0)
-		atomicio(vwrite, fileno(stdout), buffer_ptr(bout),
+		atomicio(ATOMICIO_WRITE, fileno(stdout), buffer_ptr(bout),
 		    buffer_len(bout));
 	if (buffer_len(berr) > 0)
-		atomicio(vwrite, fileno(stderr), buffer_ptr(berr),
+		atomicio(ATOMICIO_WRITE, fileno(stderr), buffer_ptr(berr),
 		    buffer_len(berr));
 
 	leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE);
@@ -1714,7 +1714,7 @@ client_loop(int have_pty, int escape_cha
 
 	/* Output any buffered data for stdout. */
 	if (buffer_len(&stdout_buffer) > 0) {
-		len = atomicio(vwrite, fileno(stdout),
+		len = atomicio(ATOMICIO_WRITE, fileno(stdout),
 		    buffer_ptr(&stdout_buffer), buffer_len(&stdout_buffer));
 		if (len < 0 || (u_int)len != buffer_len(&stdout_buffer))
 			error("Write failed flushing stdout buffer.");
@@ -1724,7 +1724,7 @@ client_loop(int have_pty, int escape_cha
 
 	/* Output any buffered data for stderr. */
 	if (buffer_len(&stderr_buffer) > 0) {
-		len = atomicio(vwrite, fileno(stderr),
+		len = atomicio(ATOMICIO_WRITE, fileno(stderr),
 		    buffer_ptr(&stderr_buffer), buffer_len(&stderr_buffer));
 		if (len < 0 || (u_int)len != buffer_len(&stderr_buffer))
 			error("Write failed flushing stderr buffer.");
Index: entropy.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/entropy.c,v
retrieving revision 1.63
diff -u -p -r1.63 entropy.c
--- entropy.c	30 Mar 2012 00:34:27 -0000	1.63
+++ entropy.c	25 Jan 2014 03:54:07 -0000
@@ -130,7 +130,7 @@ reopen:
 	msg[0] = 0x02;
 	msg[1] = len;
 
-	if (atomicio(vwrite, fd, msg, sizeof(msg)) != sizeof(msg)) {
+	if (atomicio(ATOMICIO_WRITE, fd, msg, sizeof(msg)) != sizeof(msg)) {
 		if (errno == EPIPE && errors < 10) {
 			close(fd);
 			errors++;
@@ -141,7 +141,7 @@ reopen:
 		goto done;
 	}
 
-	if (atomicio(read, fd, buf, len) != (size_t)len) {
+	if (atomicio(ATOMICIO_READ, fd, buf, len) != (size_t)len) {
 		if (errno == EPIPE && errors < 10) {
 			close(fd);
 			errors++;
Index: loginrec.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/loginrec.c,v
retrieving revision 1.94
diff -u -p -r1.94 loginrec.c
--- loginrec.c	17 Jan 2014 01:23:24 -0000	1.94
+++ loginrec.c	25 Jan 2014 03:54:08 -0000
@@ -886,7 +886,7 @@ utmp_write_direct(struct logininfo *li, 
 		 * If the new ut_line is empty but the old one is not
 		 * and ut_line and ut_name match, preserve the old ut_line.
 		 */
-		if (atomicio(read, fd, &old_ut, sizeof(old_ut)) == sizeof(old_ut) &&
+		if (atomicio(ATOMICIO_READ, fd, &old_ut, sizeof(old_ut)) == sizeof(old_ut) &&
 		    (ut->ut_host[0] == '\0') && (old_ut.ut_host[0] != '\0') &&
 		    (strncmp(old_ut.ut_line, ut->ut_line, sizeof(ut->ut_line)) == 0) &&
 		    (strncmp(old_ut.ut_name, ut->ut_name, sizeof(ut->ut_name)) == 0))
@@ -903,7 +903,7 @@ utmp_write_direct(struct logininfo *li, 
 			close(fd);
 			return (0);
 		}
-		if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
+		if (atomicio(ATOMICIO_WRITE, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
 			logit("%s: error writing %s: %s", __func__,
 			    UTMP_FILE, strerror(errno));
 			close(fd);
@@ -1097,7 +1097,7 @@ wtmp_write(struct logininfo *li, struct 
 		return (0);
 	}
 	if (fstat(fd, &buf) == 0)
-		if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
+		if (atomicio(ATOMICIO_WRITE, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
 			ftruncate(fd, buf.st_size);
 			logit("%s: problem writing %s: %s", __func__,
 			    WTMP_FILE, strerror(errno));
@@ -1205,7 +1205,7 @@ wtmp_get_entry(struct logininfo *li)
 	}
 
 	while (!found) {
-		if (atomicio(read, fd, &ut, sizeof(ut)) != sizeof(ut)) {
+		if (atomicio(ATOMICIO_READ, fd, &ut, sizeof(ut)) != sizeof(ut)) {
 			logit("%s: read of %s failed: %s", __func__,
 			    WTMP_FILE, strerror(errno));
 			close (fd);
@@ -1270,7 +1270,7 @@ wtmpx_write(struct logininfo *li, struct
 	}
 
 	if (fstat(fd, &buf) == 0)
-		if (atomicio(vwrite, fd, utx, sizeof(*utx)) != sizeof(*utx)) {
+		if (atomicio(ATOMICIO_WRITE, fd, utx, sizeof(*utx)) != sizeof(*utx)) {
 			ftruncate(fd, buf.st_size);
 			logit("%s: problem writing %s: %s", __func__,
 			    WTMPX_FILE, strerror(errno));
@@ -1370,7 +1370,7 @@ wtmpx_get_entry(struct logininfo *li)
 	}
 
 	while (!found) {
-		if (atomicio(read, fd, &utx, sizeof(utx)) != sizeof(utx)) {
+		if (atomicio(ATOMICIO_READ, fd, &utx, sizeof(utx)) != sizeof(utx)) {
 			logit("%s: read of %s failed: %s", __func__,
 			    WTMPX_FILE, strerror(errno));
 			close (fd);
@@ -1548,7 +1548,7 @@ lastlog_write_entry(struct logininfo *li
 			return (0);
 	
 		/* write the entry */
-		if (atomicio(vwrite, fd, &last, sizeof(last)) != sizeof(last)) {
+		if (atomicio(ATOMICIO_WRITE, fd, &last, sizeof(last)) != sizeof(last)) {
 			close(fd);
 			logit("%s: Error writing to %s: %s", __func__,
 			    LASTLOG_FILE, strerror(errno));
@@ -1591,7 +1591,7 @@ lastlog_get_entry(struct logininfo *li)
 	if (!lastlog_openseek(li, &fd, O_RDONLY))
 		return (0);
 
-	ret = atomicio(read, fd, &last, sizeof(last));
+	ret = atomicio(ATOMICIO_READ, fd, &last, sizeof(last));
 	close(fd);
 
 	switch (ret) {
@@ -1716,7 +1716,7 @@ record_failed_login(const char *username
 #endif
 	}
 
-	if (atomicio(vwrite, fd, &ut, sizeof(ut)) != sizeof(ut))
+	if (atomicio(ATOMICIO_WRITE, fd, &ut, sizeof(ut)) != sizeof(ut))
 		error("Failed to write to %s: %s", _PATH_BTMP,
 		    strerror(errno));
 
Index: monitor.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/monitor.c,v
retrieving revision 1.166
diff -u -p -r1.166 monitor.c
--- monitor.c	7 Nov 2013 02:32:52 -0000	1.166
+++ monitor.c	25 Jan 2014 03:54:07 -0000
@@ -520,7 +520,7 @@ monitor_read_log(struct monitor *pmonito
 
 	/* Read length */
 	buffer_append_space(&logmsg, 4);
-	if (atomicio(read, pmonitor->m_log_recvfd,
+	if (atomicio(ATOMICIO_READ, pmonitor->m_log_recvfd,
 	    buffer_ptr(&logmsg), buffer_len(&logmsg)) != buffer_len(&logmsg)) {
 		if (errno == EPIPE) {
 			buffer_free(&logmsg);
@@ -538,7 +538,7 @@ monitor_read_log(struct monitor *pmonito
 	/* Read severity, message */
 	buffer_clear(&logmsg);
 	buffer_append_space(&logmsg, len);
-	if (atomicio(read, pmonitor->m_log_recvfd,
+	if (atomicio(ATOMICIO_READ, pmonitor->m_log_recvfd,
 	    buffer_ptr(&logmsg), buffer_len(&logmsg)) != buffer_len(&logmsg))
 		fatal("%s: log fd read: %s", __func__, strerror(errno));
 
Index: monitor_wrap.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/monitor_wrap.c,v
retrieving revision 1.95
diff -u -p -r1.95 monitor_wrap.c
--- monitor_wrap.c	7 Nov 2013 02:35:39 -0000	1.95
+++ monitor_wrap.c	25 Jan 2014 03:54:12 -0000
@@ -108,7 +108,7 @@ mm_log_handler(LogLevel level, const cha
 	buffer_put_int(&log_msg, level);
 	buffer_put_cstring(&log_msg, msg);
 	put_u32(buffer_ptr(&log_msg), buffer_len(&log_msg) - 4);
-	if (atomicio(vwrite, mon->m_log_sendfd, buffer_ptr(&log_msg),
+	if (atomicio(ATOMICIO_WRITE, mon->m_log_sendfd, buffer_ptr(&log_msg),
 	    buffer_len(&log_msg)) != buffer_len(&log_msg))
 		fatal("%s: write: %s", __func__, strerror(errno));
 	buffer_free(&log_msg);
@@ -134,9 +134,9 @@ mm_request_send(int sock, enum monitor_r
 
 	put_u32(buf, mlen + 1);
 	buf[4] = (u_char) type;		/* 1st byte of payload is mesg-type */
-	if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
+	if (atomicio(ATOMICIO_WRITE, sock, buf, sizeof(buf)) != sizeof(buf))
 		fatal("%s: write: %s", __func__, strerror(errno));
-	if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen)
+	if (atomicio(ATOMICIO_WRITE, sock, buffer_ptr(m), mlen) != mlen)
 		fatal("%s: write: %s", __func__, strerror(errno));
 }
 
@@ -148,7 +148,7 @@ mm_request_receive(int sock, Buffer *m)
 
 	debug3("%s entering", __func__);
 
-	if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) {
+	if (atomicio(ATOMICIO_READ, sock, buf, sizeof(buf)) != sizeof(buf)) {
 		if (errno == EPIPE)
 			cleanup_exit(255);
 		fatal("%s: read: %s", __func__, strerror(errno));
@@ -158,7 +158,7 @@ mm_request_receive(int sock, Buffer *m)
 		fatal("%s: read: bad msg_len %d", __func__, msg_len);
 	buffer_clear(m);
 	buffer_append_space(m, msg_len);
-	if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len)
+	if (atomicio(ATOMICIO_READ, sock, buffer_ptr(m), msg_len) != msg_len)
 		fatal("%s: read: %s", __func__, strerror(errno));
 }
 
Index: msg.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/msg.c,v
retrieving revision 1.16
diff -u -p -r1.16 msg.c
--- msg.c	5 Aug 2006 02:39:40 -0000	1.16
+++ msg.c	25 Jan 2014 03:54:06 -0000
@@ -50,11 +50,11 @@ ssh_msg_send(int fd, u_char type, Buffer
 
 	put_u32(buf, mlen + 1);
 	buf[4] = type;		/* 1st byte of payload is mesg-type */
-	if (atomicio(vwrite, fd, buf, sizeof(buf)) != sizeof(buf)) {
+	if (atomicio(ATOMICIO_WRITE, fd, buf, sizeof(buf)) != sizeof(buf)) {
 		error("ssh_msg_send: write");
 		return (-1);
 	}
-	if (atomicio(vwrite, fd, buffer_ptr(m), mlen) != mlen) {
+	if (atomicio(ATOMICIO_WRITE, fd, buffer_ptr(m), mlen) != mlen) {
 		error("ssh_msg_send: write");
 		return (-1);
 	}
@@ -69,7 +69,7 @@ ssh_msg_recv(int fd, Buffer *m)
 
 	debug3("ssh_msg_recv entering");
 
-	if (atomicio(read, fd, buf, sizeof(buf)) != sizeof(buf)) {
+	if (atomicio(ATOMICIO_READ, fd, buf, sizeof(buf)) != sizeof(buf)) {
 		if (errno != EPIPE)
 			error("ssh_msg_recv: read: header");
 		return (-1);
@@ -81,7 +81,7 @@ ssh_msg_recv(int fd, Buffer *m)
 	}
 	buffer_clear(m);
 	buffer_append_space(m, msg_len);
-	if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) {
+	if (atomicio(ATOMICIO_READ, fd, buffer_ptr(m), msg_len) != msg_len) {
 		error("ssh_msg_recv: read: %s", strerror(errno));
 		return (-1);
 	}
Index: progressmeter.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/progressmeter.c,v
retrieving revision 1.41
diff -u -p -r1.41 progressmeter.c
--- progressmeter.c	9 Oct 2013 23:25:10 -0000	1.41
+++ progressmeter.c	25 Jan 2014 03:54:09 -0000
@@ -223,7 +223,7 @@ refresh_progress_meter(void)
 			strlcat(buf, "    ", win_size);
 	}
 
-	atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);
+	atomicio(ATOMICIO_WRITE, STDOUT_FILENO, buf, win_size - 1);
 	last_update = now;
 }
 
@@ -280,7 +280,7 @@ stop_progress_meter(void)
 	if (cur_pos != end_pos)
 		refresh_progress_meter();
 
-	atomicio(vwrite, STDOUT_FILENO, "\n", 1);
+	atomicio(ATOMICIO_WRITE, STDOUT_FILENO, "\n", 1);
 }
 
 /*ARGSUSED*/
Index: roaming.h
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/roaming.h,v
retrieving revision 1.5
diff -u -p -r1.5 roaming.h
--- roaming.h	18 Dec 2011 23:52:52 -0000	1.5
+++ roaming.h	25 Jan 2014 03:54:06 -0000
@@ -34,7 +34,7 @@ void	roaming_reply(int, u_int32_t, void 
 void	set_out_buffer_size(size_t);
 ssize_t	roaming_write(int, const void *, size_t, int *);
 ssize_t	roaming_read(int, void *, size_t, int *);
-size_t	roaming_atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
+size_t	roaming_atomicio(int, int, void *, size_t);
 u_int64_t	get_recv_bytes(void);
 u_int64_t	get_sent_bytes(void);
 void	roam_set_bytes(u_int64_t, u_int64_t);
Index: roaming_common.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/roaming_common.c,v
retrieving revision 1.11
diff -u -p -r1.11 roaming_common.c
--- roaming_common.c	9 Jan 2014 23:58:53 -0000	1.11
+++ roaming_common.c	25 Jan 2014 03:54:12 -0000
@@ -183,14 +183,14 @@ roaming_read(int fd, void *buf, size_t c
 }
 
 size_t
-roaming_atomicio(ssize_t(*f)(int, void*, size_t), int fd, void *buf,
+roaming_atomicio(int op, int fd, void *buf,
     size_t count)
 {
-	size_t ret = atomicio(f, fd, buf, count);
+	size_t ret = atomicio(op, fd, buf, count);
 
-	if (f == vwrite && ret > 0 && !resume_in_progress) {
+	if (op == ATOMICIO_WRITE && ret > 0 && !resume_in_progress) {
 		write_bytes += ret;
-	} else if (f == read && ret > 0 && !resume_in_progress) {
+	} else if (op == ATOMICIO_WRITE && ret > 0 && !resume_in_progress) {
 		read_bytes += ret;
 	}
 	return ret;
@@ -212,11 +212,11 @@ resend_bytes(int fd, u_int64_t *offset)
 		fatal("Needed to resend more data than in the cache");
 	if (out_last < needed) {
 		int chunkend = needed - out_last;
-		atomicio(vwrite, fd, out_buf + out_buf_size - chunkend,
+		atomicio(ATOMICIO_WRITE, fd, out_buf + out_buf_size - chunkend,
 		    chunkend);
-		atomicio(vwrite, fd, out_buf, out_last);
+		atomicio(ATOMICIO_WRITE, fd, out_buf, out_last);
 	} else {
-		atomicio(vwrite, fd, out_buf + (out_last - needed), needed);
+		atomicio(ATOMICIO_WRITE, fd, out_buf + (out_last - needed), needed);
 	}
 }
 
Index: scp.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/scp.c,v
retrieving revision 1.198
diff -u -p -r1.198 scp.c
--- scp.c	21 Nov 2013 02:56:49 -0000	1.198
+++ scp.c	25 Jan 2014 03:54:06 -0000
@@ -564,7 +564,7 @@ do_times(int fd, int verb, const struct 
 		    (long long)sb->st_mtime, (long long)sb->st_atime);
 		fprintf(stderr, "Sending file timestamps: %s", buf);
 	}
-	(void) atomicio(vwrite, fd, buf, strlen(buf));
+	(void) atomicio(ATOMICIO_WRITE, fd, buf, strlen(buf));
 	return (response());
 }
 
@@ -802,7 +802,7 @@ syserr:			run_err("%s: %s", name, strerr
 		if (verbose_mode) {
 			fprintf(stderr, "Sending file modes: %s", buf);
 		}
-		(void) atomicio(vwrite, remout, buf, strlen(buf));
+		(void) atomicio(ATOMICIO_WRITE, remout, buf, strlen(buf));
 		if (response() < 0)
 			goto next;
 		if ((bp = allocbuf(&buffer, fd, COPY_BUFLEN)) == NULL) {
@@ -820,16 +820,16 @@ next:			if (fd != -1) {
 			if (i + (off_t)amt > stb.st_size)
 				amt = stb.st_size - i;
 			if (!haderr) {
-				if (atomicio(read, fd, bp->buf, amt) != amt)
+				if (atomicio(ATOMICIO_READ, fd, bp->buf, amt) != amt)
 					haderr = errno;
 			}
 			/* Keep writing after error to retain sync */
 			if (haderr) {
-				(void)atomicio(vwrite, remout, bp->buf, amt);
+				(void)atomicio(ATOMICIO_WRITE, remout, bp->buf, amt);
 				continue;
 			}
-			if (atomicio6(vwrite, remout, bp->buf, amt, scpio,
-			    &statbytes) != amt)
+			if (atomicio6(ATOMICIO_WRITE, remout, bp->buf, amt,
+			    scpio, &statbytes) != amt)
 				haderr = errno;
 		}
 		unset_nonblock(remout);
@@ -842,7 +842,7 @@ next:			if (fd != -1) {
 			fd = -1;
 		}
 		if (!haderr)
-			(void) atomicio(vwrite, remout, "", 1);
+			(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 		else
 			run_err("%s: %s", name, strerror(haderr));
 		(void) response();
@@ -875,7 +875,7 @@ rsource(char *name, struct stat *statp)
 	    (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
 	if (verbose_mode)
 		fprintf(stderr, "Entering directory: %s", path);
-	(void) atomicio(vwrite, remout, path, strlen(path));
+	(void) atomicio(ATOMICIO_WRITE, remout, path, strlen(path));
 	if (response() < 0) {
 		closedir(dirp);
 		return;
@@ -894,7 +894,7 @@ rsource(char *name, struct stat *statp)
 		source(1, vect);
 	}
 	(void) closedir(dirp);
-	(void) atomicio(vwrite, remout, "E\n", 2);
+	(void) atomicio(ATOMICIO_WRITE, remout, "E\n", 2);
 	(void) response();
 }
 
@@ -933,17 +933,17 @@ sink(int argc, char **argv)
 	if (targetshouldbedirectory)
 		verifydir(targ);
 
-	(void) atomicio(vwrite, remout, "", 1);
+	(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 	if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
 		targisdir = 1;
 	for (first = 1;; first = 0) {
 		cp = buf;
-		if (atomicio(read, remin, cp, 1) != 1)
+		if (atomicio(ATOMICIO_READ, remin, cp, 1) != 1)
 			return;
 		if (*cp++ == '\n')
 			SCREWUP("unexpected <newline>");
 		do {
-			if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
+			if (atomicio(ATOMICIO_READ, remin, &ch, sizeof(ch)) != sizeof(ch))
 				SCREWUP("lost connection");
 			*cp++ = ch;
 		} while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
@@ -953,7 +953,7 @@ sink(int argc, char **argv)
 
 		if (buf[0] == '\01' || buf[0] == '\02') {
 			if (iamremote == 0)
-				(void) atomicio(vwrite, STDERR_FILENO,
+				(void) atomicio(ATOMICIO_WRITE, STDERR_FILENO,
 				    buf + 1, strlen(buf + 1));
 			if (buf[0] == '\02')
 				exit(1);
@@ -961,7 +961,7 @@ sink(int argc, char **argv)
 			continue;
 		}
 		if (buf[0] == 'E') {
-			(void) atomicio(vwrite, remout, "", 1);
+			(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 			return;
 		}
 		if (ch == '\n')
@@ -997,7 +997,7 @@ sink(int argc, char **argv)
 			if (!cp || *cp++ != '\0' || atime.tv_usec < 0 ||
 			    atime.tv_usec > 999999)
 				SCREWUP("atime.usec not delimited");
-			(void) atomicio(vwrite, remout, "", 1);
+			(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 			continue;
 		}
 		if (*cp != 'C' && *cp != 'D') {
@@ -1086,7 +1086,7 @@ sink(int argc, char **argv)
 bad:			run_err("%s: %s", np, strerror(errno));
 			continue;
 		}
-		(void) atomicio(vwrite, remout, "", 1);
+		(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 		if ((bp = allocbuf(&buffer, ofd, COPY_BUFLEN)) == NULL) {
 			(void) close(ofd);
 			continue;
@@ -1104,7 +1104,7 @@ bad:			run_err("%s: %s", np, strerror(er
 				amt = size - i;
 			count += amt;
 			do {
-				j = atomicio6(read, remin, cp, amt,
+				j = atomicio6(ATOMICIO_READ, remin, cp, amt,
 				    scpio, &statbytes);
 				if (j == 0) {
 					run_err("%s", j != EPIPE ?
@@ -1119,7 +1119,7 @@ bad:			run_err("%s: %s", np, strerror(er
 			if (count == bp->cnt) {
 				/* Keep reading so we stay sync'd up. */
 				if (wrerr == NO) {
-					if (atomicio(vwrite, ofd, bp->buf,
+					if (atomicio(ATOMICIO_WRITE, ofd, bp->buf,
 					    count) != count) {
 						wrerr = YES;
 						wrerrno = errno;
@@ -1133,7 +1133,7 @@ bad:			run_err("%s: %s", np, strerror(er
 		if (showprogress)
 			stop_progress_meter();
 		if (count != 0 && wrerr == NO &&
-		    atomicio(vwrite, ofd, bp->buf, count) != count) {
+		    atomicio(ATOMICIO_WRITE, ofd, bp->buf, count) != count) {
 			wrerr = YES;
 			wrerrno = errno;
 		}
@@ -1183,7 +1183,7 @@ bad:			run_err("%s: %s", np, strerror(er
 			run_err("%s: %s", np, strerror(wrerrno));
 			break;
 		case NO:
-			(void) atomicio(vwrite, remout, "", 1);
+			(void) atomicio(ATOMICIO_WRITE, remout, "", 1);
 			break;
 		case DISPLAYED:
 			break;
@@ -1199,7 +1199,7 @@ response(void)
 {
 	char ch, *cp, resp, rbuf[2048];
 
-	if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
+	if (atomicio(ATOMICIO_READ, remin, &resp, sizeof(resp)) != sizeof(resp))
 		lostconn(0);
 
 	cp = rbuf;
@@ -1212,13 +1212,13 @@ response(void)
 	case 1:		/* error, followed by error msg */
 	case 2:		/* fatal error, "" */
 		do {
-			if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
+			if (atomicio(ATOMICIO_READ, remin, &ch, sizeof(ch)) != sizeof(ch))
 				lostconn(0);
 			*cp++ = ch;
 		} while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
 
 		if (!iamremote)
-			(void) atomicio(vwrite, STDERR_FILENO, rbuf, cp - rbuf);
+			(void) atomicio(ATOMICIO_WRITE, STDERR_FILENO, rbuf, cp - rbuf);
 		++errs;
 		if (resp == 1)
 			return (-1);
Index: sftp-client.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/sftp-client.c,v
retrieving revision 1.126
diff -u -p -r1.126 sftp-client.c
--- sftp-client.c	17 Jan 2014 05:29:46 -0000	1.126
+++ sftp-client.c	25 Jan 2014 03:57:54 -0000
@@ -113,7 +113,7 @@ send_msg(struct sftp_conn *conn, Buffer 
 	iov[1].iov_base = buffer_ptr(m);
 	iov[1].iov_len = buffer_len(m);
 
-	if (atomiciov6(writev, conn->fd_out, iov, 2,
+	if (atomiciov6(ATOMICIO_WRITE, conn->fd_out, iov, 2,
 	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_out) !=
 	    buffer_len(m) + sizeof(mlen))
 		fatal("Couldn't send packet: %s", strerror(errno));
@@ -127,7 +127,7 @@ get_msg(struct sftp_conn *conn, Buffer *
 	u_int msg_len;
 
 	buffer_append_space(m, 4);
-	if (atomicio6(read, conn->fd_in, buffer_ptr(m), 4,
+	if (atomicio6(ATOMICIO_READ, conn->fd_in, buffer_ptr(m), 4,
 	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) != 4) {
 		if (errno == EPIPE)
 			fatal("Connection closed");
@@ -140,7 +140,7 @@ get_msg(struct sftp_conn *conn, Buffer *
 		fatal("Received message too long %u", msg_len);
 
 	buffer_append_space(m, msg_len);
-	if (atomicio6(read, conn->fd_in, buffer_ptr(m), msg_len,
+	if (atomicio6(ATOMICIO_READ, conn->fd_in, buffer_ptr(m), msg_len,
 	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in)
 	    != msg_len) {
 		if (errno == EPIPE)
@@ -1194,7 +1194,7 @@ do_download(struct sftp_conn *conn, char
 				fatal("Received more data than asked for "
 				    "%u > %u", len, req->len);
 			if ((lseek(local_fd, req->offset, SEEK_SET) == -1 ||
-			    atomicio(vwrite, local_fd, data, len) != len) &&
+			    atomicio(ATOMICIO_WRITE, local_fd, data, len) != len) &&
 			    !write_error) {
 				write_errno = errno;
 				write_error = 1;
Index: ssh-keygen.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/ssh-keygen.c,v
retrieving revision 1.258
diff -u -p -r1.258 ssh-keygen.c
--- ssh-keygen.c	7 Dec 2013 00:24:02 -0000	1.258
+++ ssh-keygen.c	25 Jan 2014 03:54:06 -0000
@@ -2109,7 +2109,7 @@ do_gen_krl(struct passwd *pw, int updati
 		fatal("Couldn't generate KRL");
 	if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
 		fatal("open %s: %s", identity_file, strerror(errno));
-	if (atomicio(vwrite, fd, buffer_ptr(&kbuf), buffer_len(&kbuf)) !=
+	if (atomicio(ATOMICIO_WRITE, fd, buffer_ptr(&kbuf), buffer_len(&kbuf)) !=
 	    buffer_len(&kbuf))
 		fatal("write %s: %s", identity_file, strerror(errno));
 	close(fd);
Index: ssh-keyscan.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/ssh-keyscan.c,v
retrieving revision 1.110
diff -u -p -r1.110 ssh-keyscan.c
--- ssh-keyscan.c	7 Dec 2013 00:24:02 -0000	1.110
+++ ssh-keyscan.c	25 Jan 2014 03:54:07 -0000
@@ -412,7 +412,7 @@ congreet(int s)
 		bufsiz = sizeof(buf);
 		cp = buf;
 		while (bufsiz-- &&
-		    (n = atomicio(read, s, cp, 1)) == 1 && *cp != '\n') {
+		    (n = atomicio(ATOMICIO_READ, s, cp, 1)) == 1 && *cp != '\n') {
 			if (*cp == '\r')
 				*cp = '\n';
 			cp++;
@@ -465,7 +465,7 @@ congreet(int s)
 		confree(s);
 		return;
 	}
-	if (atomicio(vwrite, s, buf, n) != (size_t)n) {
+	if (atomicio(ATOMICIO_WRITE, s, buf, n) != (size_t)n) {
 		error("write (%s): %s", c->c_name, strerror(errno));
 		confree(s);
 		return;
@@ -489,7 +489,7 @@ conread(int s)
 		congreet(s);
 		return;
 	}
-	n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);
+	n = atomicio(ATOMICIO_READ, s, c->c_data + c->c_off, c->c_len - c->c_off);
 	if (n == 0) {
 		error("read (%s): %s", c->c_name, strerror(errno));
 		confree(s);
Index: ssh-pkcs11-client.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/ssh-pkcs11-client.c,v
retrieving revision 1.6
diff -u -p -r1.6 ssh-pkcs11-client.c
--- ssh-pkcs11-client.c	1 Jun 2013 21:31:19 -0000	1.6
+++ ssh-pkcs11-client.c	25 Jan 2014 03:54:08 -0000
@@ -52,8 +52,8 @@ send_msg(Buffer *m)
 	int mlen = buffer_len(m);
 
 	put_u32(buf, mlen);
-	if (atomicio(vwrite, fd, buf, 4) != 4 ||
-	    atomicio(vwrite, fd, buffer_ptr(m),
+	if (atomicio(ATOMICIO_WRITE, fd, buf, 4) != 4 ||
+	    atomicio(ATOMICIO_WRITE, fd, buffer_ptr(m),
 	    buffer_len(m)) != buffer_len(m))
 		error("write to helper failed");
 	buffer_consume(m, mlen);
@@ -65,7 +65,7 @@ recv_msg(Buffer *m)
 	u_int l, len;
 	u_char buf[1024];
 
-	if ((len = atomicio(read, fd, buf, 4)) != 4) {
+	if ((len = atomicio(ATOMICIO_READ, fd, buf, 4)) != 4) {
 		error("read from helper failed: %u", len);
 		return (0); /* XXX */
 	}
@@ -78,7 +78,7 @@ recv_msg(Buffer *m)
 		l = len;
 		if (l > sizeof(buf))
 			l = sizeof(buf);
-		if (atomicio(read, fd, buf, l) != l) {
+		if (atomicio(ATOMICIO_READ, fd, buf, l) != l) {
 			error("response from helper failed.");
 			return (0); /* XXX */
 		}
Index: sshconnect.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/sshconnect.c,v
retrieving revision 1.217
diff -u -p -r1.217 sshconnect.c
--- sshconnect.c	9 Jan 2014 23:59:24 -0000	1.217
+++ sshconnect.c	25 Jan 2014 03:54:12 -0000
@@ -522,7 +522,7 @@ send_client_banner(int connection_out, i
 		xasprintf(&client_version_string, "SSH-%d.%d-%.100s\n",
 		    PROTOCOL_MAJOR_1, minor1, SSH_VERSION);
 	}
-	if (roaming_atomicio(vwrite, connection_out, client_version_string,
+	if (roaming_atomicio(ATOMICIO_WRITE, connection_out, client_version_string,
 	    strlen(client_version_string)) != strlen(client_version_string))
 		fatal("write: %.100s", strerror(errno));
 	chop(client_version_string);
@@ -582,7 +582,7 @@ ssh_exchange_identification(int timeout_
 				}
 			}
 
-			len = roaming_atomicio(read, connection_in, &buf[i], 1);
+			len = roaming_atomicio(ATOMICIO_READ, connection_in, &buf[i], 1);
 
 			if (len != 1 && errno == EPIPE)
 				fatal("ssh_exchange_identification: "
Index: sshd.c
===================================================================
RCS file: /home/dtucker/openssh/cvs/openssh/sshd.c,v
retrieving revision 1.441
diff -u -p -r1.441 sshd.c
--- sshd.c	17 Jan 2014 05:47:04 -0000	1.441
+++ sshd.c	25 Jan 2014 03:54:06 -0000
@@ -441,7 +441,7 @@ sshd_exchange_identification(int sock_in
 	    options.version_addendum, newline);
 
 	/* Send our protocol version identification. */
-	if (roaming_atomicio(vwrite, sock_out, server_version_string,
+	if (roaming_atomicio(ATOMICIO_WRITE, sock_out, server_version_string,
 	    strlen(server_version_string))
 	    != strlen(server_version_string)) {
 		logit("Could not write ident string to %s", get_remote_ipaddr());
@@ -451,7 +451,7 @@ sshd_exchange_identification(int sock_in
 	/* Read other sides version identification. */
 	memset(buf, 0, sizeof(buf));
 	for (i = 0; i < sizeof(buf) - 1; i++) {
-		if (roaming_atomicio(read, sock_in, &buf[i], 1) != 1) {
+		if (roaming_atomicio(ATOMICIO_READ, sock_in, &buf[i], 1) != 1) {
 			logit("Did not receive identification string from %s",
 			    get_remote_ipaddr());
 			cleanup_exit(255);
@@ -479,7 +479,7 @@ sshd_exchange_identification(int sock_in
 	if (sscanf(client_version_string, "SSH-%d.%d-%[^\n]\n",
 	    &remote_major, &remote_minor, remote_version) != 3) {
 		s = "Protocol mismatch.\n";
-		(void) atomicio(vwrite, sock_out, s, strlen(s));
+		(void) atomicio(ATOMICIO_WRITE, sock_out, s, strlen(s));
 		logit("Bad protocol version identification '%.100s' "
 		    "from %s port %d", client_version_string,
 		    get_remote_ipaddr(), get_remote_port());
@@ -548,7 +548,7 @@ sshd_exchange_identification(int sock_in
 
 	if (mismatch) {
 		s = "Protocol major versions differ.\n";
-		(void) atomicio(vwrite, sock_out, s, strlen(s));
+		(void) atomicio(ATOMICIO_WRITE, sock_out, s, strlen(s));
 		close(sock_in);
 		close(sock_out);
 		logit("Protocol major versions differ for %s: %.200s vs. %.200s",

-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.


More information about the openssh-unix-dev mailing list