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

Side by Side Diff: content/browser/zygote_host/zygote_host_impl_linux.cc

Issue 148443006: Linux: tear down Zygote at browser shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « content/browser/zygote_host/zygote_host_impl_linux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 ZygoteHostImpl::ZygoteHostImpl() 53 ZygoteHostImpl::ZygoteHostImpl()
54 : control_fd_(-1), 54 : control_fd_(-1),
55 pid_(-1), 55 pid_(-1),
56 init_(false), 56 init_(false),
57 using_suid_sandbox_(false), 57 using_suid_sandbox_(false),
58 have_read_sandbox_status_word_(false), 58 have_read_sandbox_status_word_(false),
59 sandbox_status_(0) {} 59 sandbox_status_(0) {}
60 60
61 ZygoteHostImpl::~ZygoteHostImpl() { 61 ZygoteHostImpl::~ZygoteHostImpl() {
62 if (init_) 62 TearDown();
63 close(control_fd_);
64 } 63 }
65 64
66 // static 65 // static
67 ZygoteHostImpl* ZygoteHostImpl::GetInstance() { 66 ZygoteHostImpl* ZygoteHostImpl::GetInstance() {
68 return Singleton<ZygoteHostImpl>::get(); 67 return Singleton<ZygoteHostImpl>::get();
69 } 68 }
70 69
71 void ZygoteHostImpl::Init(const std::string& sandbox_cmd) { 70 void ZygoteHostImpl::Init(const std::string& sandbox_cmd) {
72 DCHECK(!init_); 71 DCHECK(!init_);
73 init_ = true; 72 init_ = true;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 close(fds[1]); 209 close(fds[1]);
211 control_fd_ = fds[0]; 210 control_fd_ = fds[0];
212 211
213 Pickle pickle; 212 Pickle pickle;
214 pickle.WriteInt(kZygoteCommandGetSandboxStatus); 213 pickle.WriteInt(kZygoteCommandGetSandboxStatus);
215 if (!SendMessage(pickle, NULL)) 214 if (!SendMessage(pickle, NULL))
216 LOG(FATAL) << "Cannot communicate with zygote"; 215 LOG(FATAL) << "Cannot communicate with zygote";
217 // We don't wait for the reply. We'll read it in ReadReply. 216 // We don't wait for the reply. We'll read it in ReadReply.
218 } 217 }
219 218
219 void ZygoteHostImpl::TearDown() {
220 if (init_) {
221 // Closing the IPC channel will act as a notification to exit
222 // to the Zygote.
223 if (IGNORE_EINTR(close(control_fd_))) {
224 PLOG(ERROR) << "Could not close Zygote control channel.";
225 NOTREACHED();
226 }
piman 2014/01/28 02:20:44 nit: maybe reset control_fd_ to -1 for added defen
jln (very slow on Chromium) 2014/01/28 02:52:45 Done. I hadn't done it because "init_" is checked
227 init_ = false;
228 }
229 }
230
220 bool ZygoteHostImpl::SendMessage(const Pickle& data, 231 bool ZygoteHostImpl::SendMessage(const Pickle& data,
221 const std::vector<int>* fds) { 232 const std::vector<int>* fds) {
222 CHECK(data.size() <= kZygoteMaxMessageLength) 233 CHECK(data.size() <= kZygoteMaxMessageLength)
223 << "Trying to send too-large message to zygote (sending " << data.size() 234 << "Trying to send too-large message to zygote (sending " << data.size()
224 << " bytes, max is " << kZygoteMaxMessageLength << ")"; 235 << " bytes, max is " << kZygoteMaxMessageLength << ")";
225 CHECK(!fds || fds->size() <= UnixDomainSocket::kMaxFileDescriptors) 236 CHECK(!fds || fds->size() <= UnixDomainSocket::kMaxFileDescriptors)
226 << "Trying to send message with too many file descriptors to zygote " 237 << "Trying to send message with too many file descriptors to zygote "
227 << "(sending " << fds->size() << ", max is " 238 << "(sending " << fds->size() << ", max is "
228 << UnixDomainSocket::kMaxFileDescriptors << ")"; 239 << UnixDomainSocket::kMaxFileDescriptors << ")";
229 240
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 return RenderSandboxHostLinux::GetInstance()->pid(); 483 return RenderSandboxHostLinux::GetInstance()->pid();
473 } 484 }
474 485
475 int ZygoteHostImpl::GetSandboxStatus() const { 486 int ZygoteHostImpl::GetSandboxStatus() const {
476 if (have_read_sandbox_status_word_) 487 if (have_read_sandbox_status_word_)
477 return sandbox_status_; 488 return sandbox_status_;
478 return 0; 489 return 0;
479 } 490 }
480 491
481 } // namespace content 492 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/zygote_host/zygote_host_impl_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698