OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ | 5 #ifndef BASE_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ |
6 #define BASE_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ | 6 #define BASE_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ |
7 | 7 |
8 // This code exists to shuffle file descriptors, which is commonly needed when | 8 // This code exists to shuffle file descriptors, which is commonly needed when |
9 // forking subprocesses. The naive approach (just call dup2 to set up the | 9 // forking subprocesses. The naive approach (just call dup2 to set up the |
10 // desired descriptors) is very simple, but wrong: it won't handle edge cases | 10 // desired descriptors) is very simple, but wrong: it won't handle edge cases |
(...skipping 30 matching lines...) Expand all Loading... |
41 // Delete an element of the domain. | 41 // Delete an element of the domain. |
42 virtual void Close(int fd) = 0; | 42 virtual void Close(int fd) = 0; |
43 | 43 |
44 protected: | 44 protected: |
45 virtual ~InjectionDelegate() {} | 45 virtual ~InjectionDelegate() {} |
46 }; | 46 }; |
47 | 47 |
48 // An implementation of the InjectionDelegate interface using the file | 48 // An implementation of the InjectionDelegate interface using the file |
49 // descriptor table of the current process as the domain. | 49 // descriptor table of the current process as the domain. |
50 class BASE_EXPORT FileDescriptorTableInjection : public InjectionDelegate { | 50 class BASE_EXPORT FileDescriptorTableInjection : public InjectionDelegate { |
51 virtual bool Duplicate(int* result, int fd) OVERRIDE; | 51 bool Duplicate(int* result, int fd) override; |
52 virtual bool Move(int src, int dest) OVERRIDE; | 52 bool Move(int src, int dest) override; |
53 virtual void Close(int fd) OVERRIDE; | 53 void Close(int fd) override; |
54 }; | 54 }; |
55 | 55 |
56 // A single arc of the directed graph which describes an injective multimapping. | 56 // A single arc of the directed graph which describes an injective multimapping. |
57 struct InjectionArc { | 57 struct InjectionArc { |
58 InjectionArc(int in_source, int in_dest, bool in_close) | 58 InjectionArc(int in_source, int in_dest, bool in_close) |
59 : source(in_source), | 59 : source(in_source), |
60 dest(in_dest), | 60 dest(in_dest), |
61 close(in_close) { | 61 close(in_close) { |
62 } | 62 } |
63 | 63 |
(...skipping 14 matching lines...) Expand all Loading... |
78 | 78 |
79 // This function will not call malloc but will mutate |map| | 79 // This function will not call malloc but will mutate |map| |
80 static inline bool ShuffleFileDescriptors(InjectiveMultimap* map) { | 80 static inline bool ShuffleFileDescriptors(InjectiveMultimap* map) { |
81 FileDescriptorTableInjection delegate; | 81 FileDescriptorTableInjection delegate; |
82 return PerformInjectiveMultimapDestructive(map, &delegate); | 82 return PerformInjectiveMultimapDestructive(map, &delegate); |
83 } | 83 } |
84 | 84 |
85 } // namespace base | 85 } // namespace base |
86 | 86 |
87 #endif // BASE_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ | 87 #endif // BASE_POSIX_FILE_DESCRIPTOR_SHUFFLE_H_ |
OLD | NEW |