summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-12 19:43:12 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-12 19:43:12 +1100
commite371a13238c6e5ebc0949a987830d21162f4bbac (patch)
tree41184a1d2ccefd79afe2ac7b3b3cc98731a07174 /monitor_fdpass.c
parent69c01b1c4a9068478174b9cc39eb9957e78416a6 (diff)
- 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@
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r--monitor_fdpass.c21
1 files changed, 16 insertions, 5 deletions
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;