- 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@
This commit is contained in:
Darren Tucker 2010-01-12 19:43:12 +11:00
parent 69c01b1c4a
commit e371a13238
2 changed files with 20 additions and 5 deletions

View File

@ -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]

View File

@ -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;