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 #ifndef BASE_FILE_DESCRIPTOR_SHUFFLE_H_ | 5 #ifndef BASE_FILE_DESCRIPTOR_SHUFFLE_H_ |
6 #define BASE_FILE_DESCRIPTOR_SHUFFLE_H_ | 6 #define BASE_FILE_DESCRIPTOR_SHUFFLE_H_ |
7 | 7 |
8 // This code exists to perform the shuffling of file descriptors which is | 8 // This code exists to perform the shuffling of file descriptors which is |
9 // commonly needed when forking subprocesses. The naive approve is very simple, | 9 // commonly needed when forking subprocesses. The naive approve is very simple, |
10 // just call dup2 to setup the desired descriptors, but wrong. It's tough to | 10 // just call dup2 to setup the desired descriptors, but wrong. It's tough to |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 int dest; | 62 int dest; |
63 bool close; // if true, delete the source element after performing the | 63 bool close; // if true, delete the source element after performing the |
64 // mapping. | 64 // mapping. |
65 }; | 65 }; |
66 | 66 |
67 typedef std::vector<InjectionArc> InjectiveMultimap; | 67 typedef std::vector<InjectionArc> InjectiveMultimap; |
68 | 68 |
69 bool PerformInjectiveMultimap(const InjectiveMultimap& map, | 69 bool PerformInjectiveMultimap(const InjectiveMultimap& map, |
70 InjectionDelegate* delegate); | 70 InjectionDelegate* delegate); |
71 | 71 |
72 static inline bool ShuffleFileDescriptors(const InjectiveMultimap& map) { | 72 bool PerformInjectiveMultimapDestructive(InjectiveMultimap* map, |
| 73 InjectionDelegate* delegate); |
| 74 |
| 75 // This function will not call malloc but will mutate |map| |
| 76 static inline bool ShuffleFileDescriptors(InjectiveMultimap* map) { |
73 FileDescriptorTableInjection delegate; | 77 FileDescriptorTableInjection delegate; |
74 return PerformInjectiveMultimap(map, &delegate); | 78 return PerformInjectiveMultimapDestructive(map, &delegate); |
75 } | 79 } |
76 | 80 |
77 } // namespace base | 81 } // namespace base |
78 | 82 |
79 #endif // BASE_FILE_DESCRIPTOR_SHUFFLE_H_ | 83 #endif // BASE_FILE_DESCRIPTOR_SHUFFLE_H_ |
OLD | NEW |