diff options
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r-- | monitor_fdpass.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c index cab538bc9..4b9a066bc 100644 --- a/monitor_fdpass.c +++ b/monitor_fdpass.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: monitor_fdpass.c,v 1.17 2008/03/24 16:11:07 deraadt Exp $ */ | 1 | /* $OpenBSD: monitor_fdpass.c,v 1.18 2008/11/30 11:59:26 dtucker 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. |
@@ -45,17 +45,16 @@ mm_send_fd(int sock, int fd) | |||
45 | { | 45 | { |
46 | #if defined(HAVE_SENDMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) | 46 | #if defined(HAVE_SENDMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) |
47 | struct msghdr msg; | 47 | struct msghdr msg; |
48 | struct iovec vec; | ||
49 | char ch = '\0'; | ||
50 | ssize_t n; | ||
51 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR | 48 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR |
52 | union { | 49 | union { |
53 | struct cmsghdr hdr; | 50 | struct cmsghdr hdr; |
54 | char tmp[CMSG_SPACE(sizeof(int))]; | ||
55 | char buf[CMSG_SPACE(sizeof(int))]; | 51 | char buf[CMSG_SPACE(sizeof(int))]; |
56 | } cmsgbuf; | 52 | } cmsgbuf; |
57 | struct cmsghdr *cmsg; | 53 | struct cmsghdr *cmsg; |
58 | #endif | 54 | #endif |
55 | struct iovec vec; | ||
56 | char ch = '\0'; | ||
57 | ssize_t n; | ||
59 | 58 | ||
60 | memset(&msg, 0, sizeof(msg)); | 59 | memset(&msg, 0, sizeof(msg)); |
61 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR | 60 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR |
@@ -76,7 +75,10 @@ mm_send_fd(int sock, int fd) | |||
76 | msg.msg_iov = &vec; | 75 | msg.msg_iov = &vec; |
77 | msg.msg_iovlen = 1; | 76 | msg.msg_iovlen = 1; |
78 | 77 | ||
79 | if ((n = sendmsg(sock, &msg, 0)) == -1) { | 78 | while ((n = sendmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || |
79 | errno == EINTR)) | ||
80 | debug3("%s: sendmsg(%d): %s", __func__, fd, strerror(errno)); | ||
81 | if (n == -1) { | ||
80 | error("%s: sendmsg(%d): %s", __func__, fd, | 82 | error("%s: sendmsg(%d): %s", __func__, fd, |
81 | strerror(errno)); | 83 | strerror(errno)); |
82 | return -1; | 84 | return -1; |
@@ -99,10 +101,6 @@ mm_receive_fd(int sock) | |||
99 | { | 101 | { |
100 | #if defined(HAVE_RECVMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) | 102 | #if defined(HAVE_RECVMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) |
101 | struct msghdr msg; | 103 | struct msghdr msg; |
102 | struct iovec vec; | ||
103 | ssize_t n; | ||
104 | char ch; | ||
105 | int fd; | ||
106 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR | 104 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR |
107 | union { | 105 | union { |
108 | struct cmsghdr hdr; | 106 | struct cmsghdr hdr; |
@@ -110,6 +108,10 @@ mm_receive_fd(int sock) | |||
110 | } cmsgbuf; | 108 | } cmsgbuf; |
111 | struct cmsghdr *cmsg; | 109 | struct cmsghdr *cmsg; |
112 | #endif | 110 | #endif |
111 | struct iovec vec; | ||
112 | ssize_t n; | ||
113 | char ch; | ||
114 | int fd; | ||
113 | 115 | ||
114 | memset(&msg, 0, sizeof(msg)); | 116 | memset(&msg, 0, sizeof(msg)); |
115 | vec.iov_base = &ch; | 117 | vec.iov_base = &ch; |
@@ -124,10 +126,14 @@ mm_receive_fd(int sock) | |||
124 | msg.msg_controllen = sizeof(cmsgbuf.buf); | 126 | msg.msg_controllen = sizeof(cmsgbuf.buf); |
125 | #endif | 127 | #endif |
126 | 128 | ||
127 | if ((n = recvmsg(sock, &msg, 0)) == -1) { | 129 | while ((n = recvmsg(sock, &msg, 0)) == -1 && (errno == EAGAIN || |
130 | errno == EINTR)) | ||
131 | debug3("%s: recvmsg: %s", __func__, strerror(errno)); | ||
132 | if (n == -1) { | ||
128 | error("%s: recvmsg: %s", __func__, strerror(errno)); | 133 | error("%s: recvmsg: %s", __func__, strerror(errno)); |
129 | return -1; | 134 | return -1; |
130 | } | 135 | } |
136 | |||
131 | if (n != 1) { | 137 | if (n != 1) { |
132 | error("%s: recvmsg: expected received 1 got %ld", | 138 | error("%s: recvmsg: expected received 1 got %ld", |
133 | __func__, (long)n); | 139 | __func__, (long)n); |
@@ -145,6 +151,7 @@ mm_receive_fd(int sock) | |||
145 | error("%s: no message header", __func__); | 151 | error("%s: no message header", __func__); |
146 | return -1; | 152 | return -1; |
147 | } | 153 | } |
154 | |||
148 | #ifndef BROKEN_CMSG_TYPE | 155 | #ifndef BROKEN_CMSG_TYPE |
149 | if (cmsg->cmsg_type != SCM_RIGHTS) { | 156 | if (cmsg->cmsg_type != SCM_RIGHTS) { |
150 | error("%s: expected type %d got %d", __func__, | 157 | error("%s: expected type %d got %d", __func__, |