OLD | NEW |
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_wrappers.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
14 bool PerformInjectiveMultimap(const InjectiveMultimap& m_in, | 15 bool PerformInjectiveMultimap(const InjectiveMultimap& m_in, |
15 InjectionDelegate* delegate) { | 16 InjectionDelegate* delegate) { |
16 InjectiveMultimap m(m_in); | 17 InjectiveMultimap m(m_in); |
17 std::vector<int> extra_fds; | 18 std::vector<int> extra_fds; |
18 | 19 |
19 for (InjectiveMultimap::iterator i = m.begin(); i != m.end(); ++i) { | 20 for (InjectiveMultimap::iterator i = m.begin(); i != m.end(); ++i) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 for (std::vector<int>::const_iterator | 59 for (std::vector<int>::const_iterator |
59 i = extra_fds.begin(); i != extra_fds.end(); ++i) { | 60 i = extra_fds.begin(); i != extra_fds.end(); ++i) { |
60 delegate->Close(*i); | 61 delegate->Close(*i); |
61 } | 62 } |
62 | 63 |
63 return true; | 64 return true; |
64 } | 65 } |
65 | 66 |
66 bool FileDescriptorTableInjection::Duplicate(int* result, int fd) { | 67 bool FileDescriptorTableInjection::Duplicate(int* result, int fd) { |
67 do { | 68 *result = HANDLE_EINTR(dup(fd)); |
68 *result = dup(fd); | |
69 } while(*result == -1 && errno == EINTR); | |
70 | |
71 return *result >= 0; | 69 return *result >= 0; |
72 } | 70 } |
73 | 71 |
74 bool FileDescriptorTableInjection::Move(int src, int dest) { | 72 bool FileDescriptorTableInjection::Move(int src, int dest) { |
75 int result; | 73 return HANDLE_EINTR(dup2(src, dest)) != -1; |
76 | |
77 do { | |
78 result = dup2(src, dest); | |
79 } while (result == -1 && errno == EINTR); | |
80 | |
81 return result != -1; | |
82 } | 74 } |
83 | 75 |
84 void FileDescriptorTableInjection::Close(int fd) { | 76 void FileDescriptorTableInjection::Close(int fd) { |
85 int result; | 77 HANDLE_EINTR(close(fd)); |
86 | |
87 do { | |
88 result = close(fd); | |
89 } while (result == -1 && errno == EINTR); | |
90 } | 78 } |
91 | 79 |
92 } // namespace base | 80 } // namespace base |
OLD | NEW |