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

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

Issue 10949027: Close leaking FDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed last comments and synced. Created 8 years, 2 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') | content/content_browser.gypi » ('j') | 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>
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/eintr_wrapper.h" 14 #include "base/eintr_wrapper.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/linux_util.h" 17 #include "base/linux_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/linked_ptr.h"
19 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
20 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
21 #include "base/path_service.h" 22 #include "base/path_service.h"
22 #include "base/pickle.h" 23 #include "base/pickle.h"
23 #include "base/posix/unix_domain_socket.h" 24 #include "base/posix/unix_domain_socket.h"
24 #include "base/process_util.h" 25 #include "base/process_util.h"
25 #include "base/string_number_conversions.h" 26 #include "base/string_number_conversions.h"
26 #include "base/string_util.h" 27 #include "base/string_util.h"
27 #include "base/time.h" 28 #include "base/time.h"
28 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return -1; 232 return -1;
232 } 233 }
233 have_read_sandbox_status_word_ = true; 234 have_read_sandbox_status_word_ = true;
234 } 235 }
235 236
236 return HANDLE_EINTR(read(control_fd_, buf, buf_len)); 237 return HANDLE_EINTR(read(control_fd_, buf, buf_len));
237 } 238 }
238 239
239 pid_t ZygoteHostImpl::ForkRequest( 240 pid_t ZygoteHostImpl::ForkRequest(
240 const std::vector<std::string>& argv, 241 const std::vector<std::string>& argv,
241 const base::GlobalDescriptors::Mapping& mapping, 242 const std::vector<content::FileDescriptorInfo>& mapping,
242 const std::string& process_type) { 243 const std::string& process_type) {
243 DCHECK(init_); 244 DCHECK(init_);
244 Pickle pickle; 245 Pickle pickle;
245 246
246 pickle.WriteInt(content::kZygoteCommandFork); 247 pickle.WriteInt(content::kZygoteCommandFork);
247 pickle.WriteString(process_type); 248 pickle.WriteString(process_type);
248 pickle.WriteInt(argv.size()); 249 pickle.WriteInt(argv.size());
249 for (std::vector<std::string>::const_iterator 250 for (std::vector<std::string>::const_iterator
250 i = argv.begin(); i != argv.end(); ++i) 251 i = argv.begin(); i != argv.end(); ++i)
251 pickle.WriteString(*i); 252 pickle.WriteString(*i);
252 253
253 pickle.WriteInt(mapping.size()); 254 pickle.WriteInt(mapping.size());
254 255
255 std::vector<int> fds; 256 std::vector<int> fds;
256 for (base::GlobalDescriptors::Mapping::const_iterator 257 // Scoped pointers cannot be stored in containers, so we have to use a
258 // linked_ptr.
259 std::vector<linked_ptr<file_util::ScopedFD> > autodelete_fds;
260 for (std::vector<content::FileDescriptorInfo>::const_iterator
257 i = mapping.begin(); i != mapping.end(); ++i) { 261 i = mapping.begin(); i != mapping.end(); ++i) {
258 pickle.WriteUInt32(i->first); 262 pickle.WriteUInt32(i->id);
259 fds.push_back(i->second); 263 fds.push_back(i->fd.fd);
264 if (i->fd.auto_close) {
265 // Auto-close means we need to close the FDs after they habe been passed
266 // to the other process.
267 linked_ptr<file_util::ScopedFD> ptr(
268 new file_util::ScopedFD(&(fds.back())));
269 autodelete_fds.push_back(ptr);
270 }
260 } 271 }
261 272
262 pid_t pid; 273 pid_t pid;
263 { 274 {
264 base::AutoLock lock(control_lock_); 275 base::AutoLock lock(control_lock_);
265 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), 276 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(),
266 fds)) 277 fds))
267 return base::kNullProcessHandle; 278 return base::kNullProcessHandle;
268 279
269 // Read the reply, which pickles the PID and an optional UMA enumeration. 280 // Read the reply, which pickles the PID and an optional UMA enumeration.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 492
482 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { 493 pid_t ZygoteHostImpl::GetSandboxHelperPid() const {
483 return RenderSandboxHostLinux::GetInstance()->pid(); 494 return RenderSandboxHostLinux::GetInstance()->pid();
484 } 495 }
485 496
486 int ZygoteHostImpl::GetSandboxStatus() const { 497 int ZygoteHostImpl::GetSandboxStatus() const {
487 if (have_read_sandbox_status_word_) 498 if (have_read_sandbox_status_word_)
488 return sandbox_status_; 499 return sandbox_status_;
489 return 0; 500 return 0;
490 } 501 }
OLDNEW
« no previous file with comments | « content/browser/zygote_host/zygote_host_impl_linux.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698