]> andersk Git - openssh.git/commitdiff
- djm@cvs.openbsd.org 2010/01/12 00:58:25
authordtucker <dtucker>
Tue, 12 Jan 2010 08:43:12 +0000 (08:43 +0000)
committerdtucker <dtucker>
Tue, 12 Jan 2010 08:43:12 +0000 (08:43 +0000)
     [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@

ChangeLog
monitor_fdpass.c

index 688e8c109f819baec91a12c2f93cb12354de16f5..a6b547198cb63d7817ac81e1204ba312970d1151 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
      [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]
index 4b9a066bcf0f376f3479c7e34a976f251dd51218..56d3afdf35bb2ca5b64d7d8a6a0af1edd00b2f7a 100644 (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;
This page took 0.077292 seconds and 5 git commands to generate.