summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/monitor_fdpass.c
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2010-01-12 00:58:25 +0000
committerdjm <djm@openbsd.org>2010-01-12 00:58:25 +0000
commit606307a1c9761ff55a62512ab483390da29a1ad3 (patch)
tree10b87ebc16b695c0b3fb33847bba5fa1fb45b568 /usr.bin/ssh/monitor_fdpass.c
parentDo not check malloc return value against NULL, as M_WAITOK is used. (diff)
downloadwireguard-openbsd-606307a1c9761ff55a62512ab483390da29a1ad3.tar.xz
wireguard-openbsd-606307a1c9761ff55a62512ab483390da29a1ad3.zip
avoid spinning when fd passing on nonblocking sockets by calling poll()
in the EINTR/EAGAIN path, much like we do in atomicio; ok dtucker@
Diffstat (limited to 'usr.bin/ssh/monitor_fdpass.c')
-rw-r--r--usr.bin/ssh/monitor_fdpass.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/usr.bin/ssh/monitor_fdpass.c b/usr.bin/ssh/monitor_fdpass.c
index d6da36b5385..ea05feb5f8f 100644
--- a/usr.bin/ssh/monitor_fdpass.c
+++ b/usr.bin/ssh/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.
@@ -29,6 +29,7 @@
#include <sys/uio.h>
#include <errno.h>
+#include <poll.h>
#include <string.h>
#include <stdarg.h>
@@ -47,6 +48,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));
msg.msg_control = (caddr_t)&cmsgbuf.buf;
@@ -62,9 +64,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));
@@ -92,6 +98,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;
@@ -101,9 +108,13 @@ mm_receive_fd(int sock)
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
- 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;