summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-12 09:43:12 +0100
committerDarren Tucker <dtucker@zip.com.au>2010-01-12 09:43:12 +0100
commite371a13238c6e5ebc0949a987830d21162f4bbac (patch)
tree41184a1d2ccefd79afe2ac7b3b3cc98731a07174
parent - dtucker@cvs.openbsd.org 2010/01/12 00:16:47 (diff)
downloadopenssh-e371a13238c6e5ebc0949a987830d21162f4bbac.tar.xz
openssh-e371a13238c6e5ebc0949a987830d21162f4bbac.zip
- djm@cvs.openbsd.org 2010/01/12 00:58:25
[monitor_fdpass.c] avoid spinning when fd passing on nonblocking sockets by calling poll() in the EINTR/EAGAIN path, much like we do in atomicio; ok dtucker@
-rw-r--r--ChangeLog4
-rw-r--r--monitor_fdpass.c21
2 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 688e8c109..a6b547198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,10 @@
[authfile.c]
Fix bug introduced in r1.78 (incorrect brace location) that broke key auth.
Patch from joachim joachimschipper nl.
+ - djm@cvs.openbsd.org 2010/01/12 00:58:25
+ [monitor_fdpass.c]
+ avoid spinning when fd passing on nonblocking sockets by calling poll()
+ in the EINTR/EAGAIN path, much like we do in atomicio; ok dtucker@
20100110
- (dtucker) [configure.ac misc.c readconf.c servconf.c ssh-keyscan.c]
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index 4b9a066bc..56d3afdf3 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor_fdpass.c,v 1.18 2008/11/30 11:59:26 dtucker Exp $ */
+/* $OpenBSD: monitor_fdpass.c,v 1.19 2010/01/12 00:58:25 djm Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -34,6 +34,7 @@
#endif
#include <errno.h>
+#include <poll.h>
#include <string.h>
#include <stdarg.h>
@@ -55,6 +56,7 @@ mm_send_fd(int sock, int fd)
struct iovec vec;
char ch = '\0';
ssize_t n;
+ struct pollfd pfd;
memset(&msg, 0, sizeof(msg));
#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
@@ -75,9 +77,13 @@ mm_send_fd(int sock, int fd)
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
- while ((n = sendmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN ||
- errno == EINTR))
+ pfd.fd = sock;
+ pfd.events = POLLOUT;
+ while ((n = sendmsg(sock, &msg, 0)) == -1 &&
+ (errno == EAGAIN || errno == EINTR)) {
debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno));
+ (void)poll(&pfd, 1, -1);
+ }
if (n == -1) {
error("%s: sendmsg(%d): %s", __func__, fd,
strerror(errno));
@@ -112,6 +118,7 @@ mm_receive_fd(int sock)
ssize_t n;
char ch;
int fd;
+ struct pollfd pfd;
memset(&msg, 0, sizeof(msg));
vec.iov_base = &ch;
@@ -126,9 +133,13 @@ mm_receive_fd(int sock)
msg.msg_controllen = sizeof(cmsgbuf.buf);
#endif
- while ((n = recvmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN ||
- errno == EINTR))
+ pfd.fd = sock;
+ pfd.events = POLLIN;
+ while ((n = recvmsg(sock, &msg, 0)) == -1 &&
+ (errno == EAGAIN || errno == EINTR)) {
debug3("%s: recvmsg: %s", __func__, strerror(errno));
+ (void)poll(&pfd, 1, -1);
+ }
if (n == -1) {
error("%s: recvmsg: %s", __func__, strerror(errno));
return -1;