OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #ifndef CRASHPAD_UTIL_TEST_POSIX_CLOSE_MULTIPLE_H_ | |
16 #define CRASHPAD_UTIL_TEST_POSIX_CLOSE_MULTIPLE_H_ | |
17 | |
18 namespace crashpad { | |
19 | |
20 //! \brief Close multiple file descriptors or mark them close-on-exec. | |
21 //! | |
22 //! This is similar to the BSD/Solaris-style `closefrom()` routine, which closes | |
23 //! all open file descriptors equal to or higher than its \a fd argument. This | |
24 //! function must not be called while other threads are active. It is intended | |
25 //! to be used in a child process created by `fork()`, prior to calling an | |
26 //! `exec()`-family function. This guarantees that a (possibly untrustworthy) | |
27 //! child process does not inherit file descriptors that it has no need for. | |
28 //! | |
29 //! Unlike the BSD function, this function may not close file descriptors | |
30 //! immediately, but may instead mark them as close-on-exec. The actual behavior | |
31 //! chosen is specific to the operating system. On Mac OS X, file descriptors | |
32 //! are marked close-on-exec instead of being closed outright in order to avoid | |
33 //! raising `EXC_GUARD` exceptions for guarded file descriptors that are | |
34 //! protected against `close()`. | |
35 //! | |
36 //! \param[in] fd The lowest file descriptor to close or set as close-on-exec. | |
37 //! \param[in] preserve_fd A file descriptor to preserve and not close (or set | |
38 //! as close-on-exec), even if it is open and its value is greater than \a | |
39 //! fd. To not preserve any file descriptor, pass `-1` for this parameter. | |
40 void CloseMultipleNowOrOnExec(int fd, int preserve_fd); | |
41 | |
42 } // namespace crashpad | |
43 | |
44 #endif // CRASHPAD_UTIL_TEST_POSIX_CLOSE_MULTIPLE_H_ | |
OLD | NEW |