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/renderer_host/render_sandbox_host_linux.h" | 5 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| 11 #include "content/browser/renderer_host/sandbox_ipc_linux.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 // Runs on the main thread at startup. | 15 // Runs on the main thread at startup. |
15 RenderSandboxHostLinux::RenderSandboxHostLinux() | 16 RenderSandboxHostLinux::RenderSandboxHostLinux() |
16 : initialized_(false), renderer_socket_(0) { | 17 : initialized_(false), |
| 18 renderer_socket_(0), |
| 19 childs_lifeline_fd_(0), |
| 20 pid_(0) { |
17 } | 21 } |
18 | 22 |
19 // static | 23 // static |
20 RenderSandboxHostLinux* RenderSandboxHostLinux::GetInstance() { | 24 RenderSandboxHostLinux* RenderSandboxHostLinux::GetInstance() { |
21 return Singleton<RenderSandboxHostLinux>::get(); | 25 return Singleton<RenderSandboxHostLinux>::get(); |
22 } | 26 } |
23 | 27 |
24 void RenderSandboxHostLinux::Init(const std::string& sandbox_path) { | 28 void RenderSandboxHostLinux::Init(const std::string& sandbox_path) { |
25 DCHECK(!initialized_); | 29 DCHECK(!initialized_); |
26 initialized_ = true; | 30 initialized_ = true; |
(...skipping 10 matching lines...) Expand all Loading... |
37 renderer_socket_ = fds[0]; | 41 renderer_socket_ = fds[0]; |
38 // The SandboxIPC client is not expected to read from |renderer_socket_|. | 42 // The SandboxIPC client is not expected to read from |renderer_socket_|. |
39 // Instead, it reads from a temporary socket sent with the request. | 43 // Instead, it reads from a temporary socket sent with the request. |
40 PCHECK(0 == shutdown(renderer_socket_, SHUT_RD)) << "shutdown"; | 44 PCHECK(0 == shutdown(renderer_socket_, SHUT_RD)) << "shutdown"; |
41 | 45 |
42 const int browser_socket = fds[1]; | 46 const int browser_socket = fds[1]; |
43 // The SandboxIPC handler is not expected to write to |browser_socket|. | 47 // The SandboxIPC handler is not expected to write to |browser_socket|. |
44 // Instead, it replies on a temporary socket provided by the caller. | 48 // Instead, it replies on a temporary socket provided by the caller. |
45 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown"; | 49 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown"; |
46 | 50 |
47 ipc_handler_.reset(new SandboxIPCHandler(browser_socket, sandbox_path)); | 51 int pipefds[2]; |
48 ipc_thread_.reset( | 52 CHECK(0 == pipe(pipefds)); |
49 new base::DelegateSimpleThread(ipc_handler_.get(), "sandbox_ipc_thread")); | 53 const int child_lifeline_fd = pipefds[0]; |
50 ipc_thread_->Start(); | 54 childs_lifeline_fd_ = pipefds[1]; |
| 55 |
| 56 // We need to be monothreaded before we fork(). |
| 57 #if !defined(THREAD_SANITIZER) |
| 58 DCHECK_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); |
| 59 #endif // !defined(THREAD_SANITIZER) |
| 60 pid_ = fork(); |
| 61 if (pid_ == 0) { |
| 62 if (IGNORE_EINTR(close(fds[0])) < 0) |
| 63 DPLOG(ERROR) << "close"; |
| 64 if (IGNORE_EINTR(close(pipefds[1])) < 0) |
| 65 DPLOG(ERROR) << "close"; |
| 66 |
| 67 SandboxIPCProcess handler(child_lifeline_fd, browser_socket, sandbox_path); |
| 68 handler.Run(); |
| 69 _exit(0); |
| 70 } |
51 } | 71 } |
52 | 72 |
53 RenderSandboxHostLinux::~RenderSandboxHostLinux() { | 73 RenderSandboxHostLinux::~RenderSandboxHostLinux() { |
54 if (initialized_) { | 74 if (initialized_) { |
55 if (IGNORE_EINTR(close(renderer_socket_)) < 0) | 75 if (IGNORE_EINTR(close(renderer_socket_)) < 0) |
56 PLOG(ERROR) << "close"; | 76 PLOG(ERROR) << "close"; |
57 | 77 if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0) |
58 ipc_thread_->Join(); | 78 PLOG(ERROR) << "close"; |
59 } | 79 } |
60 } | 80 } |
61 | 81 |
62 } // namespace content | 82 } // namespace content |
OLD | NEW |