summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2010-03-31 00:48:57 +0100
committerColin Watson <cjwatson@debian.org>2010-03-31 00:48:57 +0100
commitd1a87e462e1db89f19cd960588d0c6b287cb5ccc (patch)
treef0d13e1687800f36a3c4322b94ac5230ad17bdbf /monitor_fdpass.c
parent964476f91b66c475d5b8fa1e8b28d39a97a1b56e (diff)
parent004a7fb9c6a00b13dc98f56599918a54a3506d10 (diff)
merge 5.4p1
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r--monitor_fdpass.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index 4b9a066bc..7eb6f5c6e 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,9 @@
34#endif 34#endif
35 35
36#include <errno.h> 36#include <errno.h>
37#ifdef HAVE_POLL_H
38#include <poll.h>
39#endif
37#include <string.h> 40#include <string.h>
38#include <stdarg.h> 41#include <stdarg.h>
39 42
@@ -55,6 +58,7 @@ mm_send_fd(int sock, int fd)
55 struct iovec vec; 58 struct iovec vec;
56 char ch = '\0'; 59 char ch = '\0';
57 ssize_t n; 60 ssize_t n;
61 struct pollfd pfd;
58 62
59 memset(&msg, 0, sizeof(msg)); 63 memset(&msg, 0, sizeof(msg));
60#ifdef HAVE_ACCRIGHTS_IN_MSGHDR 64#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
@@ -75,9 +79,13 @@ mm_send_fd(int sock, int fd)
75 msg.msg_iov = &vec; 79 msg.msg_iov = &vec;
76 msg.msg_iovlen = 1; 80 msg.msg_iovlen = 1;
77 81
78 while ((n = sendmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || 82 pfd.fd = sock;
79 errno == EINTR)) 83 pfd.events = POLLOUT;
84 while ((n = sendmsg(sock, &msg, 0)) == -1 &&
85 (errno == EAGAIN || errno == EINTR)) {
80 debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno)); 86 debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno));
87 (void)poll(&pfd, 1, -1);
88 }
81 if (n == -1) { 89 if (n == -1) {
82 error("%s: sendmsg(%d): %s", __func__, fd, 90 error("%s: sendmsg(%d): %s", __func__, fd,
83 strerror(errno)); 91 strerror(errno));
@@ -112,6 +120,7 @@ mm_receive_fd(int sock)
112 ssize_t n; 120 ssize_t n;
113 char ch; 121 char ch;
114 int fd; 122 int fd;
123 struct pollfd pfd;
115 124
116 memset(&msg, 0, sizeof(msg)); 125 memset(&msg, 0, sizeof(msg));
117 vec.iov_base = &ch; 126 vec.iov_base = &ch;
@@ -126,9 +135,13 @@ mm_receive_fd(int sock)
126 msg.msg_controllen = sizeof(cmsgbuf.buf); 135 msg.msg_controllen = sizeof(cmsgbuf.buf);
127#endif 136#endif
128 137
129 while ((n = recvmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || 138 pfd.fd = sock;
130 errno == EINTR)) 139 pfd.events = POLLIN;
140 while ((n = recvmsg(sock, &msg, 0)) == -1 &&
141 (errno == EAGAIN || errno == EINTR)) {
131 debug3("%s: recvmsg: %s", __func__, strerror(errno)); 142 debug3("%s: recvmsg: %s", __func__, strerror(errno));
143 (void)poll(&pfd, 1, -1);
144 }
132 if (n == -1) { 145 if (n == -1) {
133 error("%s: recvmsg: %s", __func__, strerror(errno)); 146 error("%s: recvmsg: %s", __func__, strerror(errno));
134 return -1; 147 return -1;