/src/brpc/src/butil/files/scoped_file.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2014 The Chromium Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. |
4 | | |
5 | | #include "butil/files/scoped_file.h" |
6 | | |
7 | | #include "butil/logging.h" |
8 | | |
9 | | #if defined(OS_POSIX) |
10 | | #include <unistd.h> |
11 | | |
12 | | #include "butil/posix/eintr_wrapper.h" |
13 | | #endif |
14 | | |
15 | | namespace butil { |
16 | | namespace internal { |
17 | | |
18 | | #if defined(OS_POSIX) |
19 | | |
20 | | // static |
21 | 0 | void ScopedFDCloseTraits::Free(int fd) { |
22 | | // It's important to crash here. |
23 | | // There are security implications to not closing a file descriptor |
24 | | // properly. As file descriptors are "capabilities", keeping them open |
25 | | // would make the current process keep access to a resource. Much of |
26 | | // Chrome relies on being able to "drop" such access. |
27 | | // It's especially problematic on Linux with the setuid sandbox, where |
28 | | // a single open directory would bypass the entire security model. |
29 | 0 | PCHECK(0 == IGNORE_EINTR(close(fd))); |
30 | 0 | } |
31 | | |
32 | | #endif // OS_POSIX |
33 | | |
34 | | } // namespace internal |
35 | | } // namespace butil |