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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/test/posix/close_multiple.h" | 15 #include "util/test/posix/close_multiple.h" |
16 | 16 |
17 #include <dirent.h> | 17 #include <dirent.h> |
18 #include <errno.h> | 18 #include <errno.h> |
19 #include <fcntl.h> | 19 #include <fcntl.h> |
20 #include <limits.h> | 20 #include <limits.h> |
21 #include <stdlib.h> | 21 #include <stdlib.h> |
22 #include <string.h> | 22 #include <string.h> |
23 #include <unistd.h> | 23 #include <unistd.h> |
24 | 24 |
25 #include <algorithm> | 25 #include <algorithm> |
26 | 26 |
| 27 #include "base/basictypes.h" |
27 #include "base/logging.h" | 28 #include "base/logging.h" |
28 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
29 #include "base/posix/eintr_wrapper.h" | 30 #include "base/posix/eintr_wrapper.h" |
30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
31 #include "util/numeric/safe_assignment.h" | 32 #include "util/numeric/safe_assignment.h" |
32 | 33 |
33 // Everything in this file is expected to execute between fork() and exec(), | 34 // Everything in this file is expected to execute between fork() and exec(), |
34 // so everything called here must be acceptable in this context. However, | 35 // so everything called here must be acceptable in this context. However, |
35 // logging code that is not expected to execute under normal circumstances is | 36 // logging code that is not expected to execute under normal circumstances is |
36 // currently permitted. | 37 // currently permitted. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 138 } |
138 | 139 |
139 // Fallback: close every file descriptor starting at |fd| and ending at the | 140 // Fallback: close every file descriptor starting at |fd| and ending at the |
140 // system’s file descriptor limit. Check a few values and use the highest as | 141 // system’s file descriptor limit. Check a few values and use the highest as |
141 // the limit, because these may be based on the file descriptor limit set by | 142 // the limit, because these may be based on the file descriptor limit set by |
142 // setrlimit(), and higher-numbered file descriptors may have been opened | 143 // setrlimit(), and higher-numbered file descriptors may have been opened |
143 // prior to the limit being lowered. For Mac OS X, see 10.9.2 | 144 // prior to the limit being lowered. For Mac OS X, see 10.9.2 |
144 // Libc-997.90.3/gen/FreeBSD/sysconf.c sysconf() and 10.9.4 | 145 // Libc-997.90.3/gen/FreeBSD/sysconf.c sysconf() and 10.9.4 |
145 // xnu-2422.110.17/bsd/kern/kern_descrip.c getdtablesize(), which both return | 146 // xnu-2422.110.17/bsd/kern/kern_descrip.c getdtablesize(), which both return |
146 // the current RLIMIT_NOFILE value, not the maximum possible file descriptor. | 147 // the current RLIMIT_NOFILE value, not the maximum possible file descriptor. |
147 int max_fd = std::max(static_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX); | 148 int max_fd = std::max(implicit_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX); |
148 max_fd = std::max(max_fd, getdtablesize()); | 149 max_fd = std::max(max_fd, getdtablesize()); |
149 | 150 |
150 for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) { | 151 for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) { |
151 if (entry_fd != preserve_fd) { | 152 if (entry_fd != preserve_fd) { |
152 CloseNowOrOnExec(entry_fd, true); | 153 CloseNowOrOnExec(entry_fd, true); |
153 } | 154 } |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 } // namespace crashpad | 158 } // namespace crashpad |
OLD | NEW |