OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/zygote_host/zygote_host_impl_linux.h" | 5 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 sizeof(sandbox_status_))) != | 280 sizeof(sandbox_status_))) != |
281 sizeof(sandbox_status_)) { | 281 sizeof(sandbox_status_)) { |
282 return -1; | 282 return -1; |
283 } | 283 } |
284 have_read_sandbox_status_word_ = true; | 284 have_read_sandbox_status_word_ = true; |
285 } | 285 } |
286 | 286 |
287 return HANDLE_EINTR(read(control_fd_, buf, buf_len)); | 287 return HANDLE_EINTR(read(control_fd_, buf, buf_len)); |
288 } | 288 } |
289 | 289 |
290 pid_t ZygoteHostImpl::ForkRequest( | 290 pid_t ZygoteHostImpl::ForkRequest(const std::vector<std::string>& argv, |
291 const std::vector<std::string>& argv, | 291 scoped_ptr<FileDescriptorInfo> mapping, |
292 const std::vector<FileDescriptorInfo>& mapping, | 292 const std::string& process_type) { |
293 const std::string& process_type) { | |
294 DCHECK(init_); | 293 DCHECK(init_); |
295 Pickle pickle; | 294 Pickle pickle; |
296 | 295 |
297 int raw_socks[2]; | 296 int raw_socks[2]; |
298 PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, raw_socks)); | 297 PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, raw_socks)); |
299 base::ScopedFD my_sock(raw_socks[0]); | 298 base::ScopedFD my_sock(raw_socks[0]); |
300 base::ScopedFD peer_sock(raw_socks[1]); | 299 base::ScopedFD peer_sock(raw_socks[1]); |
301 CHECK(UnixDomainSocket::EnableReceiveProcessId(my_sock.get())); | 300 CHECK(UnixDomainSocket::EnableReceiveProcessId(my_sock.get())); |
302 | 301 |
303 pickle.WriteInt(kZygoteCommandFork); | 302 pickle.WriteInt(kZygoteCommandFork); |
304 pickle.WriteString(process_type); | 303 pickle.WriteString(process_type); |
305 pickle.WriteInt(argv.size()); | 304 pickle.WriteInt(argv.size()); |
306 for (std::vector<std::string>::const_iterator | 305 for (std::vector<std::string>::const_iterator |
307 i = argv.begin(); i != argv.end(); ++i) | 306 i = argv.begin(); i != argv.end(); ++i) |
308 pickle.WriteString(*i); | 307 pickle.WriteString(*i); |
309 | 308 |
310 // Fork requests contain one file descriptor for the PID oracle, and one | 309 // Fork requests contain one file descriptor for the PID oracle, and one |
311 // more for each file descriptor mapping for the child process. | 310 // more for each file descriptor mapping for the child process. |
312 const size_t num_fds_to_send = 1 + mapping.size(); | 311 const size_t num_fds_to_send = 1 + mapping->GetMappingSize(); |
313 pickle.WriteInt(num_fds_to_send); | 312 pickle.WriteInt(num_fds_to_send); |
314 | 313 |
315 std::vector<int> fds; | 314 std::vector<int> fds; |
316 ScopedVector<base::ScopedFD> autoclose_fds; | |
317 | 315 |
318 // First FD to send is peer_sock. | 316 // First FD to send is peer_sock. |
319 fds.push_back(peer_sock.get()); | 317 fds.push_back(peer_sock.get()); |
320 autoclose_fds.push_back(new base::ScopedFD(peer_sock.Pass())); | 318 mapping->TransferWithoutMapping(peer_sock.Pass()); |
mdempsky
2014/09/24 21:16:44
This feels a little awkward to me actually. It se
Hajime Morrita
2014/09/24 23:08:56
OK.
Ideally, we should change the zygote IPC prot
| |
321 | 319 |
322 // The rest come from mapping. | 320 // The rest come from mapping. |
323 for (std::vector<FileDescriptorInfo>::const_iterator | 321 for (size_t i = 0; i < mapping->GetMappingSize(); ++i) { |
324 i = mapping.begin(); i != mapping.end(); ++i) { | 322 pickle.WriteUInt32(mapping->GetIDAt(i)); |
325 pickle.WriteUInt32(i->id); | 323 fds.push_back(mapping->GetFDAt(i)); |
326 fds.push_back(i->fd.fd); | |
327 if (i->fd.auto_close) { | |
328 // Auto-close means we need to close the FDs after they have been passed | |
329 // to the other process. | |
330 autoclose_fds.push_back(new base::ScopedFD(i->fd.fd)); | |
331 } | |
332 } | 324 } |
333 | 325 |
334 // Sanity check that we've populated |fds| correctly. | 326 // Sanity check that we've populated |fds| correctly. |
335 DCHECK_EQ(num_fds_to_send, fds.size()); | 327 DCHECK_EQ(num_fds_to_send, fds.size()); |
336 | 328 |
337 pid_t pid; | 329 pid_t pid; |
338 { | 330 { |
339 base::AutoLock lock(control_lock_); | 331 base::AutoLock lock(control_lock_); |
340 if (!SendMessage(pickle, &fds)) | 332 if (!SendMessage(pickle, &fds)) |
341 return base::kNullProcessHandle; | 333 return base::kNullProcessHandle; |
342 autoclose_fds.clear(); | 334 mapping.reset(); |
343 | 335 |
344 { | 336 { |
345 char buf[sizeof(kZygoteChildPingMessage) + 1]; | 337 char buf[sizeof(kZygoteChildPingMessage) + 1]; |
346 ScopedVector<base::ScopedFD> recv_fds; | 338 ScopedVector<base::ScopedFD> recv_fds; |
347 base::ProcessId real_pid; | 339 base::ProcessId real_pid; |
348 | 340 |
349 ssize_t n = UnixDomainSocket::RecvMsgWithPid( | 341 ssize_t n = UnixDomainSocket::RecvMsgWithPid( |
350 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid); | 342 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid); |
351 if (n != sizeof(kZygoteChildPingMessage) || | 343 if (n != sizeof(kZygoteChildPingMessage) || |
352 0 != memcmp(buf, | 344 0 != memcmp(buf, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 return pid_; | 551 return pid_; |
560 } | 552 } |
561 | 553 |
562 int ZygoteHostImpl::GetSandboxStatus() const { | 554 int ZygoteHostImpl::GetSandboxStatus() const { |
563 if (have_read_sandbox_status_word_) | 555 if (have_read_sandbox_status_word_) |
564 return sandbox_status_; | 556 return sandbox_status_; |
565 return 0; | 557 return 0; |
566 } | 558 } |
567 | 559 |
568 } // namespace content | 560 } // namespace content |
OLD | NEW |