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

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

Issue 2950153002: Improve process launch handle sharing API. (Closed)
Patch Set: Fix Mojo launcher, review comments Created 3 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_communication_linux.h" 5 #include "content/browser/zygote_host/zygote_communication_linux.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 have_read_sandbox_status_word_ = true; 78 have_read_sandbox_status_word_ = true;
79 UMA_HISTOGRAM_SPARSE_SLOWLY("Linux.SandboxStatus", sandbox_status_); 79 UMA_HISTOGRAM_SPARSE_SLOWLY("Linux.SandboxStatus", sandbox_status_);
80 } 80 }
81 81
82 return HANDLE_EINTR(read(control_fd_.get(), buf, buf_len)); 82 return HANDLE_EINTR(read(control_fd_.get(), buf, buf_len));
83 } 83 }
84 84
85 pid_t ZygoteCommunication::ForkRequest( 85 pid_t ZygoteCommunication::ForkRequest(
86 const std::vector<std::string>& argv, 86 const std::vector<std::string>& argv,
87 std::unique_ptr<FileDescriptorInfo> mapping, 87 std::unique_ptr<PosixFileDescriptorInfo> mapping,
88 const std::string& process_type) { 88 const std::string& process_type) {
89 DCHECK(init_); 89 DCHECK(init_);
90 90
91 base::Pickle pickle; 91 base::Pickle pickle;
92 int raw_socks[2]; 92 int raw_socks[2];
93 PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, raw_socks)); 93 PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, raw_socks));
94 base::ScopedFD my_sock(raw_socks[0]); 94 base::ScopedFD my_sock(raw_socks[0]);
95 base::ScopedFD peer_sock(raw_socks[1]); 95 base::ScopedFD peer_sock(raw_socks[1]);
96 CHECK(base::UnixDomainSocket::EnableReceiveProcessId(my_sock.get())); 96 CHECK(base::UnixDomainSocket::EnableReceiveProcessId(my_sock.get()));
97 97
98 pickle.WriteInt(kZygoteCommandFork); 98 pickle.WriteInt(kZygoteCommandFork);
99 pickle.WriteString(process_type); 99 pickle.WriteString(process_type);
100 pickle.WriteInt(argv.size()); 100 pickle.WriteInt(argv.size());
101 for (std::vector<std::string>::const_iterator i = argv.begin(); 101 for (std::vector<std::string>::const_iterator i = argv.begin();
102 i != argv.end(); ++i) 102 i != argv.end(); ++i)
103 pickle.WriteString(*i); 103 pickle.WriteString(*i);
104 104
105 // Fork requests contain one file descriptor for the PID oracle, and one 105 // Fork requests contain one file descriptor for the PID oracle, and one
106 // more for each file descriptor mapping for the child process. 106 // more for each file descriptor mapping for the child process.
107 const size_t num_fds_to_send = 1 + mapping->GetMappingSize(); 107 const size_t num_fds_to_send = 1 + mapping->GetMappingSize();
108 pickle.WriteInt(num_fds_to_send); 108 pickle.WriteInt(num_fds_to_send);
109 109
110 std::vector<int> fds; 110 std::vector<int> fds;
111 111
112 // First FD to send is peer_sock. 112 // First FD to send is peer_sock.
113 // TODO(morrita): Ideally, this should be part of the mapping so that 113 // TODO(morrita): Ideally, this should be part of the mapping so that
114 // FileDescriptorInfo can manages its lifetime. 114 // PosixFileDescriptorInfo can manages its lifetime.
115 fds.push_back(peer_sock.get()); 115 fds.push_back(peer_sock.get());
116 116
117 // The rest come from mapping. 117 // The rest come from mapping.
118 for (size_t i = 0; i < mapping->GetMappingSize(); ++i) { 118 for (size_t i = 0; i < mapping->GetMappingSize(); ++i) {
119 pickle.WriteUInt32(mapping->GetIDAt(i)); 119 pickle.WriteUInt32(mapping->GetIDAt(i));
120 fds.push_back(mapping->GetFDAt(i)); 120 fds.push_back(mapping->GetFDAt(i));
121 } 121 }
122 122
123 // Sanity check that we've populated |fds| correctly. 123 // Sanity check that we've populated |fds| correctly.
124 DCHECK_EQ(num_fds_to_send, fds.size()); 124 DCHECK_EQ(num_fds_to_send, fds.size());
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 333 }
334 if (ReadSandboxStatus() == -1) { 334 if (ReadSandboxStatus() == -1) {
335 return 0; 335 return 0;
336 } 336 }
337 have_read_sandbox_status_word_ = true; 337 have_read_sandbox_status_word_ = true;
338 UMA_HISTOGRAM_SPARSE_SLOWLY("Linux.SandboxStatus", sandbox_status_); 338 UMA_HISTOGRAM_SPARSE_SLOWLY("Linux.SandboxStatus", sandbox_status_);
339 return sandbox_status_; 339 return sandbox_status_;
340 } 340 }
341 341
342 } // namespace content 342 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698