scoped_file.cc 994 Bytes
Newer Older
gejun's avatar
gejun committed
1 2 3 4
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "butil/files/scoped_file.h"
gejun's avatar
gejun committed
6

7
#include "butil/logging.h"
gejun's avatar
gejun committed
8 9 10 11

#if defined(OS_POSIX)
#include <unistd.h>

12
#include "butil/posix/eintr_wrapper.h"
gejun's avatar
gejun committed
13 14
#endif

15
namespace butil {
gejun's avatar
gejun committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
namespace internal {

#if defined(OS_POSIX)

// static
void ScopedFDCloseTraits::Free(int fd) {
  // It's important to crash here.
  // There are security implications to not closing a file descriptor
  // properly. As file descriptors are "capabilities", keeping them open
  // would make the current process keep access to a resource. Much of
  // Chrome relies on being able to "drop" such access.
  // It's especially problematic on Linux with the setuid sandbox, where
  // a single open directory would bypass the entire security model.
  PCHECK(0 == IGNORE_EINTR(close(fd)));
}

#endif  // OS_POSIX

}  // namespace internal
35
}  // namespace butil