Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: content/browser/zygote_host/zygote_host_impl_linux.cc

Issue 585203002: Turn FileDescriptorInfo a collection class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/zygote_host/zygote_host_impl_linux.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
317 // TODO(morrita): Ideally, this should be part of the mapping so that
318 // FileDescriptorInfo can manages its lifetime.
319 fds.push_back(peer_sock.get()); 319 fds.push_back(peer_sock.get());
320 autoclose_fds.push_back(new base::ScopedFD(peer_sock.Pass()));
321 320
322 // The rest come from mapping. 321 // The rest come from mapping.
323 for (std::vector<FileDescriptorInfo>::const_iterator 322 for (size_t i = 0; i < mapping->GetMappingSize(); ++i) {
324 i = mapping.begin(); i != mapping.end(); ++i) { 323 pickle.WriteUInt32(mapping->GetIDAt(i));
325 pickle.WriteUInt32(i->id); 324 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 } 325 }
333 326
334 // Sanity check that we've populated |fds| correctly. 327 // Sanity check that we've populated |fds| correctly.
335 DCHECK_EQ(num_fds_to_send, fds.size()); 328 DCHECK_EQ(num_fds_to_send, fds.size());
336 329
337 pid_t pid; 330 pid_t pid;
338 { 331 {
339 base::AutoLock lock(control_lock_); 332 base::AutoLock lock(control_lock_);
340 if (!SendMessage(pickle, &fds)) 333 if (!SendMessage(pickle, &fds))
341 return base::kNullProcessHandle; 334 return base::kNullProcessHandle;
342 autoclose_fds.clear(); 335 mapping.reset();
336 peer_sock.reset();
343 337
344 { 338 {
345 char buf[sizeof(kZygoteChildPingMessage) + 1]; 339 char buf[sizeof(kZygoteChildPingMessage) + 1];
346 ScopedVector<base::ScopedFD> recv_fds; 340 ScopedVector<base::ScopedFD> recv_fds;
347 base::ProcessId real_pid; 341 base::ProcessId real_pid;
348 342
349 ssize_t n = UnixDomainSocket::RecvMsgWithPid( 343 ssize_t n = UnixDomainSocket::RecvMsgWithPid(
350 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid); 344 my_sock.get(), buf, sizeof(buf), &recv_fds, &real_pid);
351 if (n != sizeof(kZygoteChildPingMessage) || 345 if (n != sizeof(kZygoteChildPingMessage) ||
352 0 != memcmp(buf, 346 0 != memcmp(buf,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 return pid_; 553 return pid_;
560 } 554 }
561 555
562 int ZygoteHostImpl::GetSandboxStatus() const { 556 int ZygoteHostImpl::GetSandboxStatus() const {
563 if (have_read_sandbox_status_word_) 557 if (have_read_sandbox_status_word_)
564 return sandbox_status_; 558 return sandbox_status_;
565 return 0; 559 return 0;
566 } 560 }
567 561
568 } // namespace content 562 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/zygote_host/zygote_host_impl_linux.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698