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

Side by Side Diff: base/file_descriptor_shuffle.cc

Issue 115773: Prototype implementation of zygotes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | « base/command_line.cc ('k') | base/file_util_posix.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/file_descriptor_shuffle.h" 5 #include "base/file_descriptor_shuffle.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 bool PerformInjectiveMultimap(const InjectiveMultimap& m_in, 15 bool PerformInjectiveMultimap(const InjectiveMultimap& m_in,
16 InjectionDelegate* delegate) { 16 InjectionDelegate* delegate) {
17 InjectiveMultimap m(m_in); 17 InjectiveMultimap m(m_in);
18 std::vector<int> extra_fds; 18 std::vector<int> extra_fds;
19 19
20 for (InjectiveMultimap::iterator i = m.begin(); i != m.end(); ++i) { 20 for (InjectiveMultimap::iterator i = m.begin(); i != m.end(); ++i) {
21 int temp_fd = -1; 21 int temp_fd = -1;
22 22
23 // We DCHECK the injectiveness of the mapping. 23 // We DCHECK the injectiveness of the mapping.
24 for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) 24 for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) {
25 DCHECK(i->dest != j->dest); 25 DCHECK(i->dest != j->dest) << "Both fd " << i->source
26 << " and " << j->source << " map to " << i->dest;
27 }
26 28
27 const bool is_identity = i->source == i->dest; 29 const bool is_identity = i->source == i->dest;
28 30
29 for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) { 31 for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) {
30 if (!is_identity && i->dest == j->source) { 32 if (!is_identity && i->dest == j->source) {
31 if (temp_fd == -1) { 33 if (temp_fd == -1) {
32 if (!delegate->Duplicate(&temp_fd, i->dest)) 34 if (!delegate->Duplicate(&temp_fd, i->dest))
33 return false; 35 return false;
34 extra_fds.push_back(temp_fd); 36 extra_fds.push_back(temp_fd);
35 } 37 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 73
72 bool FileDescriptorTableInjection::Move(int src, int dest) { 74 bool FileDescriptorTableInjection::Move(int src, int dest) {
73 return HANDLE_EINTR(dup2(src, dest)) != -1; 75 return HANDLE_EINTR(dup2(src, dest)) != -1;
74 } 76 }
75 77
76 void FileDescriptorTableInjection::Close(int fd) { 78 void FileDescriptorTableInjection::Close(int fd) {
77 HANDLE_EINTR(close(fd)); 79 HANDLE_EINTR(close(fd));
78 } 80 }
79 81
80 } // namespace base 82 } // namespace base
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698