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/environment.h" | 14 #include "base/environment.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
18 #include "base/linux_util.h" | 18 #include "base/linux_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/memory/linked_ptr.h" | 20 #include "base/memory/linked_ptr.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/memory/scoped_vector.h" |
22 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
24 #include "base/posix/eintr_wrapper.h" | 25 #include "base/posix/eintr_wrapper.h" |
25 #include "base/posix/unix_domain_socket_linux.h" | 26 #include "base/posix/unix_domain_socket_linux.h" |
26 #include "base/process/launch.h" | 27 #include "base/process/launch.h" |
27 #include "base/process/memory.h" | 28 #include "base/process/memory.h" |
28 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
29 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
30 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 base::ProcessHandle process = -1; | 143 base::ProcessHandle process = -1; |
143 options.fds_to_remap = &fds_to_map; | 144 options.fds_to_remap = &fds_to_map; |
144 base::LaunchProcess(cmd_line.argv(), options, &process); | 145 base::LaunchProcess(cmd_line.argv(), options, &process); |
145 CHECK(process != -1) << "Failed to launch zygote process"; | 146 CHECK(process != -1) << "Failed to launch zygote process"; |
146 | 147 |
147 if (using_suid_sandbox_) { | 148 if (using_suid_sandbox_) { |
148 // In the SUID sandbox, the real zygote is forked from the sandbox. | 149 // In the SUID sandbox, the real zygote is forked from the sandbox. |
149 // We need to look for it. | 150 // We need to look for it. |
150 // But first, wait for the zygote to tell us it's running. | 151 // But first, wait for the zygote to tell us it's running. |
151 // The sending code is in content/browser/zygote_main_linux.cc. | 152 // The sending code is in content/browser/zygote_main_linux.cc. |
152 std::vector<int> fds_vec; | 153 ScopedVector<base::ScopedFD> fds_vec; |
153 const int kExpectedLength = sizeof(kZygoteHelloMessage); | 154 const int kExpectedLength = sizeof(kZygoteHelloMessage); |
154 char buf[kExpectedLength]; | 155 char buf[kExpectedLength]; |
155 const ssize_t len = UnixDomainSocket::RecvMsg(fds[0], buf, sizeof(buf), | 156 const ssize_t len = UnixDomainSocket::RecvMsg(fds[0], buf, sizeof(buf), |
156 &fds_vec); | 157 &fds_vec); |
157 CHECK_EQ(kExpectedLength, len) << "Incorrect zygote magic length"; | 158 CHECK_EQ(kExpectedLength, len) << "Incorrect zygote magic length"; |
158 CHECK(0 == strcmp(buf, kZygoteHelloMessage)) << "Incorrect zygote hello"; | 159 CHECK(0 == strcmp(buf, kZygoteHelloMessage)) << "Incorrect zygote hello"; |
159 | 160 |
160 std::string inode_output; | 161 std::string inode_output; |
161 ino_t inode = 0; | 162 ino_t inode = 0; |
162 // Figure out the inode for |dummy_fd|, close |dummy_fd| on our end, | 163 // Figure out the inode for |dummy_fd|, close |dummy_fd| on our end, |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 return RenderSandboxHostLinux::GetInstance()->pid(); | 507 return RenderSandboxHostLinux::GetInstance()->pid(); |
507 } | 508 } |
508 | 509 |
509 int ZygoteHostImpl::GetSandboxStatus() const { | 510 int ZygoteHostImpl::GetSandboxStatus() const { |
510 if (have_read_sandbox_status_word_) | 511 if (have_read_sandbox_status_word_) |
511 return sandbox_status_; | 512 return sandbox_status_; |
512 return 0; | 513 return 0; |
513 } | 514 } |
514 | 515 |
515 } // namespace content | 516 } // namespace content |
OLD | NEW |