OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/posix/unix_domain_socket_linux.h" | 5 #include "base/posix/unix_domain_socket_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/uio.h> | 9 #include <sys/uio.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 errno = EMSGSIZE; | 145 errno = EMSGSIZE; |
146 return -1; | 146 return -1; |
147 } | 147 } |
148 | 148 |
149 if (wire_fds) { | 149 if (wire_fds) { |
150 for (unsigned i = 0; i < wire_fds_len; ++i) | 150 for (unsigned i = 0; i < wire_fds_len; ++i) |
151 fds->push_back(new base::ScopedFD(wire_fds[i])); | 151 fds->push_back(new base::ScopedFD(wire_fds[i])); |
152 } | 152 } |
153 | 153 |
154 if (out_pid) { | 154 if (out_pid) { |
155 DCHECK(pid != -1); | 155 // |pid| will legitimately be -1 if we read EOF, so only DCHECK if we |
| 156 // actually received a message. Unfortunately, Linux allows sending zero |
| 157 // length messages, which are indistinguishable from EOF, so this check |
| 158 // has false negatives. |
| 159 if (r > 0 || msg.msg_controllen > 0) |
| 160 DCHECK_GE(pid, 0); |
| 161 |
156 *out_pid = pid; | 162 *out_pid = pid; |
157 } | 163 } |
158 | 164 |
159 return r; | 165 return r; |
160 } | 166 } |
161 | 167 |
162 // static | 168 // static |
163 ssize_t UnixDomainSocket::SendRecvMsg(int fd, | 169 ssize_t UnixDomainSocket::SendRecvMsg(int fd, |
164 uint8_t* reply, | 170 uint8_t* reply, |
165 unsigned max_reply_len, | 171 unsigned max_reply_len, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (recv_fds.size() > (result_fd != NULL ? 1 : 0)) { | 215 if (recv_fds.size() > (result_fd != NULL ? 1 : 0)) { |
210 NOTREACHED(); | 216 NOTREACHED(); |
211 return -1; | 217 return -1; |
212 } | 218 } |
213 | 219 |
214 if (result_fd) | 220 if (result_fd) |
215 *result_fd = recv_fds.empty() ? -1 : recv_fds[0]->release(); | 221 *result_fd = recv_fds.empty() ? -1 : recv_fds[0]->release(); |
216 | 222 |
217 return reply_len; | 223 return reply_len; |
218 } | 224 } |
OLD | NEW |