| 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> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/base_switches.h" | 13 #include "base/base_switches.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.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/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
| 18 #include "base/files/scoped_file.h" | 18 #include "base/files/scoped_file.h" |
| 19 #include "base/linux_util.h" | 19 #include "base/linux_util.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/linked_ptr.h" | 21 #include "base/memory/linked_ptr.h" |
| 22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/memory/scoped_vector.h" |
| 23 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
| 24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 25 #include "base/posix/eintr_wrapper.h" | 26 #include "base/posix/eintr_wrapper.h" |
| 26 #include "base/posix/unix_domain_socket_linux.h" | 27 #include "base/posix/unix_domain_socket_linux.h" |
| 27 #include "base/process/launch.h" | 28 #include "base/process/launch.h" |
| 28 #include "base/process/memory.h" | 29 #include "base/process/memory.h" |
| 29 #include "base/process/process_handle.h" | 30 #include "base/process/process_handle.h" |
| 30 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
| 31 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
| 32 #include "base/strings/utf_string_conversions.h" | 33 #include "base/strings/utf_string_conversions.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 base::LaunchProcess(cmd_line.argv(), options, &process); | 170 base::LaunchProcess(cmd_line.argv(), options, &process); |
| 170 CHECK(process != -1) << "Failed to launch zygote process"; | 171 CHECK(process != -1) << "Failed to launch zygote process"; |
| 171 dummy_fd.reset(); | 172 dummy_fd.reset(); |
| 172 | 173 |
| 173 if (using_suid_sandbox_) { | 174 if (using_suid_sandbox_) { |
| 174 // In the SUID sandbox, the real zygote is forked from the sandbox | 175 // In the SUID sandbox, the real zygote is forked from the sandbox |
| 175 // and will be executing in another PID namespace. | 176 // and will be executing in another PID namespace. |
| 176 // Wait for the zygote to tell us it's running, and receive its PID, | 177 // Wait for the zygote to tell us it's running, and receive its PID, |
| 177 // which the kernel will translate to our PID namespace. | 178 // which the kernel will translate to our PID namespace. |
| 178 // The sending code is in content/browser/zygote_main_linux.cc. | 179 // The sending code is in content/browser/zygote_main_linux.cc. |
| 179 std::vector<int> fds_vec; | 180 ScopedVector<base::ScopedFD> fds_vec; |
| 180 const size_t kExpectedLength = sizeof(kZygoteHelloMessage); | 181 const size_t kExpectedLength = sizeof(kZygoteHelloMessage); |
| 181 char buf[kExpectedLength]; | 182 char buf[kExpectedLength]; |
| 182 const ssize_t len = UnixDomainSocket::RecvMsgWithPid( | 183 const ssize_t len = UnixDomainSocket::RecvMsgWithPid( |
| 183 fds[0], buf, sizeof(buf), &fds_vec, &pid_); | 184 fds[0], buf, sizeof(buf), &fds_vec, &pid_); |
| 184 CHECK_EQ(kExpectedLength, static_cast<size_t>(len)) | 185 CHECK_EQ(kExpectedLength, static_cast<size_t>(len)) |
| 185 << "Incorrect zygote magic length"; | 186 << "Incorrect zygote magic length"; |
| 186 CHECK_EQ(0, memcmp(buf, kZygoteHelloMessage, kExpectedLength)) | 187 CHECK_EQ(0, memcmp(buf, kZygoteHelloMessage, kExpectedLength)) |
| 187 << "Incorrect zygote hello"; | 188 << "Incorrect zygote hello"; |
| 188 CHECK_EQ(0U, fds_vec.size()) | 189 CHECK_EQ(0U, fds_vec.size()) |
| 189 << "Zygote hello should not include file descriptors"; | 190 << "Zygote hello should not include file descriptors"; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 return RenderSandboxHostLinux::GetInstance()->pid(); | 523 return RenderSandboxHostLinux::GetInstance()->pid(); |
| 523 } | 524 } |
| 524 | 525 |
| 525 int ZygoteHostImpl::GetSandboxStatus() const { | 526 int ZygoteHostImpl::GetSandboxStatus() const { |
| 526 if (have_read_sandbox_status_word_) | 527 if (have_read_sandbox_status_word_) |
| 527 return sandbox_status_; | 528 return sandbox_status_; |
| 528 return 0; | 529 return 0; |
| 529 } | 530 } |
| 530 | 531 |
| 531 } // namespace content | 532 } // namespace content |
| OLD | NEW |