summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 @@
19 [authfile.c] 19 [authfile.c]
20 Fix bug introduced in r1.78 (incorrect brace location) that broke key auth. 20 Fix bug introduced in r1.78 (incorrect brace location) that broke key auth.
21 Patch from joachim joachimschipper nl. 21 Patch from joachim joachimschipper nl.
22 - djm@cvs.openbsd.org 2010/01/12 00:58:25
23 [monitor_fdpass.c]
24 avoid spinning when fd passing on nonblocking sockets by calling poll()
25 in the EINTR/EAGAIN path, much like we do in atomicio; ok dtucker@
22 26
2320100110 2720100110
24 - (dtucker) [configure.ac misc.c readconf.c servconf.c ssh-keyscan.c] 28 - (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 @@
1/* $OpenBSD: monitor_fdpass.c,v 1.18 2008/11/30 11:59:26 dtucker Exp $ */ 1/* $OpenBSD: monitor_fdpass.c,v 1.19 2010/01/12 00:58:25 djm Exp $ */
2/* 2/*
3 * Copyright 2001 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2001 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
@@ -34,6 +34,7 @@
34#endif 34#endif
35 35
36#include <errno.h> 36#include <errno.h>
37#include <poll.h>
37#include <string.h> 38#include <string.h>
38#include <stdarg.h> 39#include <stdarg.h>
39 40
@@ -55,6 +56,7 @@ mm_send_fd(int sock, int fd)
55 struct iovec vec; 56 struct iovec vec;
56 char ch = '\0'; 57 char ch = '\0';
57 ssize_t n; 58 ssize_t n;
59 struct pollfd pfd;
58 60
59 memset(&msg, 0, sizeof(msg)); 61 memset(&msg, 0, sizeof(msg));
60#ifdef HAVE_ACCRIGHTS_IN_MSGHDR 62#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
@@ -75,9 +77,13 @@ mm_send_fd(int sock, int fd)
75 msg.msg_iov = &vec; 77 msg.msg_iov = &vec;
76 msg.msg_iovlen = 1; 78 msg.msg_iovlen = 1;
77 79
78 while ((n = sendmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || 80 pfd.fd = sock;
79 errno == EINTR)) 81 pfd.events = POLLOUT;
82 while ((n = sendmsg(sock, &msg, 0)) == -1 &&
83 (errno == EAGAIN || errno == EINTR)) {
80 debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno)); 84 debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno));
85 (void)poll(&pfd, 1, -1);
86 }
81 if (n == -1) { 87 if (n == -1) {
82 error("%s: sendmsg(%d): %s", __func__, fd, 88 error("%s: sendmsg(%d): %s", __func__, fd,
83 strerror(errno)); 89 strerror(errno));
@@ -112,6 +118,7 @@ mm_receive_fd(int sock)
112 ssize_t n; 118 ssize_t n;
113 char ch; 119 char ch;
114 int fd; 120 int fd;
121 struct pollfd pfd;
115 122
116 memset(&msg, 0, sizeof(msg)); 123 memset(&msg, 0, sizeof(msg));
117 vec.iov_base = &ch; 124 vec.iov_base = &ch;
@@ -126,9 +133,13 @@ mm_receive_fd(int sock)
126 msg.msg_controllen = sizeof(cmsgbuf.buf); 133 msg.msg_controllen = sizeof(cmsgbuf.buf);
127#endif 134#endif
128 135
129 while ((n = recvmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || 136 pfd.fd = sock;
130 errno == EINTR)) 137 pfd.events = POLLIN;
138 while ((n = recvmsg(sock, &msg, 0)) == -1 &&
139 (errno == EAGAIN || errno == EINTR)) {
131 debug3("%s: recvmsg: %s", __func__, strerror(errno)); 140 debug3("%s: recvmsg: %s", __func__, strerror(errno));
141 (void)poll(&pfd, 1, -1);
142 }
132 if (n == -1) { 143 if (n == -1) {
133 error("%s: recvmsg: %s", __func__, strerror(errno)); 144 error("%s: recvmsg: %s", __func__, strerror(errno));
134 return -1; 145 return -1;