forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ScopedFD in terms of ScopedGeneric.
Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later. I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified. I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition). BUG= R=agl@chromium.org, viettrungluu@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=257001 Review URL: https://codereview.chromium.org/191673003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257179 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
brettw@chromium.org
committed
Mar 14, 2014
1 parent
5fcc99e
commit c0e895e
Showing
42 changed files
with
332 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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. | ||
|
||
#include "base/files/scoped_file.h" | ||
|
||
#include "base/logging.h" | ||
|
||
#if defined(OS_POSIX) | ||
#include <unistd.h> | ||
|
||
#include "base/posix/eintr_wrapper.h" | ||
#endif | ||
|
||
namespace base { | ||
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 | ||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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. | ||
|
||
#ifndef BASE_FILES_SCOPED_FILE_H_ | ||
#define BASE_FILES_SCOPED_FILE_H_ | ||
|
||
#include <stdio.h> | ||
|
||
#include "base/base_export.h" | ||
#include "base/logging.h" | ||
#include "base/scoped_generic.h" | ||
#include "build/build_config.h" | ||
|
||
namespace base { | ||
|
||
namespace internal { | ||
|
||
#if defined(OS_POSIX) | ||
struct BASE_EXPORT ScopedFDCloseTraits { | ||
static int InvalidValue() { | ||
return -1; | ||
} | ||
static void Free(int fd); | ||
}; | ||
#endif | ||
|
||
} // namespace internal | ||
|
||
#if defined(OS_POSIX) | ||
// A low-level Posix file descriptor closer class. Use this when writing | ||
// platform-specific code, especially that does non-file-like things with the | ||
// FD (like sockets). | ||
// | ||
// If you're writing low-level Windows code, see base/win/scoped_handle.h | ||
// which provides some additional functionality. | ||
// | ||
// If you're writing cross-platform code that deals with actual files, you | ||
// should generally use base::File instead which can be constructed with a | ||
// handle, and in addition to handling ownership, has convenient cross-platform | ||
// file manipulation functions on it. | ||
typedef ScopedGeneric<int, internal::ScopedFDCloseTraits> ScopedFD; | ||
#endif | ||
|
||
} // namespace base | ||
|
||
#endif // BASE_FILES_SCOPED_FILE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.