Chromium Code Reviews| 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 <sys/socket.h> | 7 #include <sys/socket.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
| 15 #include "base/environment.h" | 15 #include "base/environment.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/linux_util.h" | 17 #include "base/linux_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/linked_ptr.h" | |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 22 #include "base/pickle.h" | 23 #include "base/pickle.h" |
| 23 #include "base/posix/unix_domain_socket.h" | 24 #include "base/posix/unix_domain_socket.h" |
| 24 #include "base/process_util.h" | 25 #include "base/process_util.h" |
| 25 #include "base/string_number_conversions.h" | 26 #include "base/string_number_conversions.h" |
| 26 #include "base/string_util.h" | 27 #include "base/string_util.h" |
| 27 #include "base/time.h" | 28 #include "base/time.h" |
| 28 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 return -1; | 232 return -1; |
| 232 } | 233 } |
| 233 have_read_sandbox_status_word_ = true; | 234 have_read_sandbox_status_word_ = true; |
| 234 } | 235 } |
| 235 | 236 |
| 236 return HANDLE_EINTR(read(control_fd_, buf, buf_len)); | 237 return HANDLE_EINTR(read(control_fd_, buf, buf_len)); |
| 237 } | 238 } |
| 238 | 239 |
| 239 pid_t ZygoteHostImpl::ForkRequest( | 240 pid_t ZygoteHostImpl::ForkRequest( |
| 240 const std::vector<std::string>& argv, | 241 const std::vector<std::string>& argv, |
| 241 const base::GlobalDescriptors::Mapping& mapping, | 242 const std::vector<content::FileDescriptorInfo>& mapping, |
| 242 const std::string& process_type) { | 243 const std::string& process_type) { |
| 243 DCHECK(init_); | 244 DCHECK(init_); |
| 244 Pickle pickle; | 245 Pickle pickle; |
| 245 | 246 |
| 246 pickle.WriteInt(content::kZygoteCommandFork); | 247 pickle.WriteInt(content::kZygoteCommandFork); |
| 247 pickle.WriteString(process_type); | 248 pickle.WriteString(process_type); |
| 248 pickle.WriteInt(argv.size()); | 249 pickle.WriteInt(argv.size()); |
| 249 for (std::vector<std::string>::const_iterator | 250 for (std::vector<std::string>::const_iterator |
| 250 i = argv.begin(); i != argv.end(); ++i) | 251 i = argv.begin(); i != argv.end(); ++i) |
| 251 pickle.WriteString(*i); | 252 pickle.WriteString(*i); |
| 252 | 253 |
| 253 pickle.WriteInt(mapping.size()); | 254 pickle.WriteInt(mapping.size()); |
| 254 | 255 |
| 255 std::vector<int> fds; | 256 std::vector<int> fds; |
| 256 for (base::GlobalDescriptors::Mapping::const_iterator | 257 // Scoped pointers cannot be stored in containers, so we have to use a |
| 258 // link_ptr. | |
|
Markus (顧孟勤)
2012/09/24 21:17:34
s/link/linked/
| |
| 259 std::vector<linked_ptr<file_util::ScopedFD> > autodelete_fds; | |
| 260 for (std::vector<content::FileDescriptorInfo>::const_iterator | |
| 257 i = mapping.begin(); i != mapping.end(); ++i) { | 261 i = mapping.begin(); i != mapping.end(); ++i) { |
| 258 pickle.WriteUInt32(i->first); | 262 pickle.WriteUInt32(i->id); |
| 259 fds.push_back(i->second); | 263 fds.push_back(i->fd.fd); |
| 264 if (i->fd.auto_close) { | |
| 265 linked_ptr<file_util::ScopedFD> ptr( | |
| 266 new file_util::ScopedFD(&(fds.back()))); | |
| 267 autodelete_fds.push_back(ptr); | |
|
Markus (顧孟勤)
2012/09/24 21:17:34
I think I understand what you are doing here, but
| |
| 268 } | |
| 260 } | 269 } |
| 261 | 270 |
| 262 pid_t pid; | 271 pid_t pid; |
| 263 { | 272 { |
| 264 base::AutoLock lock(control_lock_); | 273 base::AutoLock lock(control_lock_); |
| 265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), | 274 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), |
| 266 fds)) | 275 fds)) |
| 267 return base::kNullProcessHandle; | 276 return base::kNullProcessHandle; |
| 268 | 277 |
| 269 // Read the reply, which pickles the PID and an optional UMA enumeration. | 278 // Read the reply, which pickles the PID and an optional UMA enumeration. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 | 490 |
| 482 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { | 491 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { |
| 483 return RenderSandboxHostLinux::GetInstance()->pid(); | 492 return RenderSandboxHostLinux::GetInstance()->pid(); |
| 484 } | 493 } |
| 485 | 494 |
| 486 int ZygoteHostImpl::GetSandboxStatus() const { | 495 int ZygoteHostImpl::GetSandboxStatus() const { |
| 487 if (have_read_sandbox_status_word_) | 496 if (have_read_sandbox_status_word_) |
| 488 return sandbox_status_; | 497 return sandbox_status_; |
| 489 return 0; | 498 return 0; |
| 490 } | 499 } |
| OLD | NEW |