OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 struct ScopedDIRCloser { | 65 struct ScopedDIRCloser { |
66 void operator()(DIR* dir) const { | 66 void operator()(DIR* dir) const { |
67 if (dir) { | 67 if (dir) { |
68 if (closedir(dir) < 0) { | 68 if (closedir(dir) < 0) { |
69 PLOG(ERROR) << "closedir"; | 69 PLOG(ERROR) << "closedir"; |
70 } | 70 } |
71 } | 71 } |
72 } | 72 } |
73 }; | 73 }; |
74 | 74 |
75 typedef scoped_ptr<DIR, ScopedDIRCloser> ScopedDIR; | 75 using ScopedDIR = scoped_ptr<DIR, ScopedDIRCloser>; |
76 | 76 |
77 // This function implements CloseMultipleNowOrOnExec() using an operating | 77 // This function implements CloseMultipleNowOrOnExec() using an operating |
78 // system-specific FD directory to determine which file descriptors are open. | 78 // system-specific FD directory to determine which file descriptors are open. |
79 // This is an advantage over looping over all possible file descriptors, because | 79 // This is an advantage over looping over all possible file descriptors, because |
80 // no attempt needs to be made to close file descriptors that are not open. | 80 // no attempt needs to be made to close file descriptors that are not open. |
81 bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) { | 81 bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) { |
82 #if defined(OS_MACOSX) | 82 #if defined(OS_MACOSX) |
83 const char kFDDir[] = "/dev/fd"; | 83 const char kFDDir[] = "/dev/fd"; |
84 #elif defined(OS_LINUX) | 84 #elif defined(OS_LINUX) |
85 const char kFDDir[] = "/proc/self/fd"; | 85 const char kFDDir[] = "/proc/self/fd"; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 max_fd = std::max(max_fd, getdtablesize()); | 148 max_fd = std::max(max_fd, getdtablesize()); |
149 | 149 |
150 for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) { | 150 for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) { |
151 if (entry_fd != preserve_fd) { | 151 if (entry_fd != preserve_fd) { |
152 CloseNowOrOnExec(entry_fd, true); | 152 CloseNowOrOnExec(entry_fd, true); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 } // namespace crashpad | 157 } // namespace crashpad |
OLD | NEW |