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 #pragma once | 7 #pragma once |
8 | 8 |
9 // This code exists to perform the shuffling of file descriptors which is | 9 // This code exists to perform the shuffling of file descriptors which is |
10 // commonly needed when forking subprocesses. The naive approve is very simple, | 10 // commonly needed when forking subprocesses. The naive approve is very simple, |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Delete an element of the domain. | 39 // Delete an element of the domain. |
40 virtual void Close(int fd) = 0; | 40 virtual void Close(int fd) = 0; |
41 | 41 |
42 protected: | 42 protected: |
43 virtual ~InjectionDelegate() {} | 43 virtual ~InjectionDelegate() {} |
44 }; | 44 }; |
45 | 45 |
46 // An implementation of the InjectionDelegate interface using the file | 46 // An implementation of the InjectionDelegate interface using the file |
47 // descriptor table of the current process as the domain. | 47 // descriptor table of the current process as the domain. |
48 class FileDescriptorTableInjection : public InjectionDelegate { | 48 class FileDescriptorTableInjection : public InjectionDelegate { |
49 bool Duplicate(int* result, int fd); | 49 virtual bool Duplicate(int* result, int fd); |
50 bool Move(int src, int dest); | 50 virtual bool Move(int src, int dest); |
51 void Close(int fd); | 51 virtual void Close(int fd); |
52 }; | 52 }; |
53 | 53 |
54 // A single arc of the directed graph which describes an injective multimapping. | 54 // A single arc of the directed graph which describes an injective multimapping. |
55 struct InjectionArc { | 55 struct InjectionArc { |
56 InjectionArc(int in_source, int in_dest, bool in_close) | 56 InjectionArc(int in_source, int in_dest, bool in_close) |
57 : source(in_source), | 57 : source(in_source), |
58 dest(in_dest), | 58 dest(in_dest), |
59 close(in_close) { | 59 close(in_close) { |
60 } | 60 } |
61 | 61 |
(...skipping 13 matching lines...) Expand all Loading... |
75 | 75 |
76 // This function will not call malloc but will mutate |map| | 76 // This function will not call malloc but will mutate |map| |
77 static inline bool ShuffleFileDescriptors(InjectiveMultimap* map) { | 77 static inline bool ShuffleFileDescriptors(InjectiveMultimap* map) { |
78 FileDescriptorTableInjection delegate; | 78 FileDescriptorTableInjection delegate; |
79 return PerformInjectiveMultimapDestructive(map, &delegate); | 79 return PerformInjectiveMultimapDestructive(map, &delegate); |
80 } | 80 } |
81 | 81 |
82 } // namespace base | 82 } // namespace base |
83 | 83 |
84 #endif // BASE_FILE_DESCRIPTOR_SHUFFLE_H_ | 84 #endif // BASE_FILE_DESCRIPTOR_SHUFFLE_H_ |
OLD | NEW |