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

Side by Side Diff: content/browser/renderer_host/render_sandbox_host_linux.cc

Issue 286903021: Make SandboxIPCProcess a thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Close FDs in ::~SandboxIPCHandler(). Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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"
12 11
13 namespace content { 12 namespace content {
14 13
15 // Runs on the main thread at startup. 14 // Runs on the main thread at startup.
16 RenderSandboxHostLinux::RenderSandboxHostLinux() 15 RenderSandboxHostLinux::RenderSandboxHostLinux()
17 : initialized_(false), 16 : initialized_(false), renderer_socket_(0), childs_lifeline_fd_(0) {
18 renderer_socket_(0),
19 childs_lifeline_fd_(0),
20 pid_(0) {
21 } 17 }
22 18
23 // static 19 // static
24 RenderSandboxHostLinux* RenderSandboxHostLinux::GetInstance() { 20 RenderSandboxHostLinux* RenderSandboxHostLinux::GetInstance() {
25 return Singleton<RenderSandboxHostLinux>::get(); 21 return Singleton<RenderSandboxHostLinux>::get();
26 } 22 }
27 23
28 void RenderSandboxHostLinux::Init() { 24 void RenderSandboxHostLinux::Init() {
29 DCHECK(!initialized_); 25 DCHECK(!initialized_);
30 initialized_ = true; 26 initialized_ = true;
(...skipping 15 matching lines...) Expand all
46 const int browser_socket = fds[1]; 42 const int browser_socket = fds[1];
47 // The SandboxIPC handler is not expected to write to |browser_socket|. 43 // The SandboxIPC handler is not expected to write to |browser_socket|.
48 // Instead, it replies on a temporary socket provided by the caller. 44 // Instead, it replies on a temporary socket provided by the caller.
49 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown"; 45 PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown";
50 46
51 int pipefds[2]; 47 int pipefds[2];
52 CHECK(0 == pipe(pipefds)); 48 CHECK(0 == pipe(pipefds));
53 const int child_lifeline_fd = pipefds[0]; 49 const int child_lifeline_fd = pipefds[0];
54 childs_lifeline_fd_ = pipefds[1]; 50 childs_lifeline_fd_ = pipefds[1];
55 51
56 // We need to be monothreaded before we fork(). 52 ipc_handler_.reset(
57 #if !defined(THREAD_SANITIZER) 53 new SandboxIPCHandler(child_lifeline_fd, browser_socket));
58 DCHECK_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); 54 ipc_thread_.reset(
59 #endif // !defined(THREAD_SANITIZER) 55 new base::DelegateSimpleThread(ipc_handler_.get(), "sandbox_ipc_thread"));
60 pid_ = fork(); 56 ipc_thread_->Start();
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);
68 handler.Run();
69 _exit(0);
70 }
71 } 57 }
72 58
73 bool RenderSandboxHostLinux::ShutdownIPCChannel() { 59 bool RenderSandboxHostLinux::ShutdownIPCChannel() {
74 return IGNORE_EINTR(close(childs_lifeline_fd_)) == 0; 60 return IGNORE_EINTR(close(childs_lifeline_fd_)) == 0;
75 } 61 }
76 62
77 RenderSandboxHostLinux::~RenderSandboxHostLinux() { 63 RenderSandboxHostLinux::~RenderSandboxHostLinux() {
78 if (initialized_) { 64 if (initialized_) {
79 if (!ShutdownIPCChannel()) 65 if (!ShutdownIPCChannel())
80 LOG(ERROR) << "ShutdownIPCChannel failed"; 66 LOG(ERROR) << "ShutdownIPCChannel failed";
81 if (IGNORE_EINTR(close(renderer_socket_)) < 0) 67 if (IGNORE_EINTR(close(renderer_socket_)) < 0)
82 PLOG(ERROR) << "close"; 68 PLOG(ERROR) << "close";
69
70 ipc_thread_->Join();
83 } 71 }
84 } 72 }
85 73
86 } // namespace content 74 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_sandbox_host_linux.h ('k') | content/browser/renderer_host/sandbox_ipc_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698