diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-17 19:02:35 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-17 19:02:35 +0000 |
commit | 42f558fdef03f1ec2261f554151d8a4d168919e4 (patch) | |
tree | a2f2403061c945c8983524036bc73550098de6b7 /chrome/browser/chromeos/system | |
parent | cb8d22b096bf5698bcf58725d6e4d7534e235a0a (diff) | |
download | chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.zip chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.gz chromium_src-42f558fdef03f1ec2261f554151d8a4d168919e4.tar.bz2 |
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).
Reland of https://codereview.chromium.org/191673003/
R=agl, viettrungluu
Review URL: https://codereview.chromium.org/202113004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/system')
-rw-r--r-- | chrome/browser/chromeos/system/automatic_reboot_manager.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/system/automatic_reboot_manager.cc b/chrome/browser/chromeos/system/automatic_reboot_manager.cc index 1e00316..2ca1409 100644 --- a/chrome/browser/chromeos/system/automatic_reboot_manager.cc +++ b/chrome/browser/chromeos/system/automatic_reboot_manager.cc @@ -18,6 +18,7 @@ #include "base/callback.h" #include "base/file_util.h" #include "base/files/file_path.h" +#include "base/files/scoped_file.h" #include "base/location.h" #include "base/logging.h" #include "base/memory/ref_counted.h" @@ -56,15 +57,15 @@ const int kOneKilobyte = 1 << 10; // 1 kB in bytes. base::TimeDelta ReadTimeDeltaFromFile(const base::FilePath& path) { base::ThreadRestrictions::AssertIOAllowed(); - int fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY | O_NOFOLLOW)); - if (fd < 0) + base::ScopedFD fd( + HANDLE_EINTR(open(path.value().c_str(), O_RDONLY | O_NOFOLLOW))); + if (!fd.is_valid()) return base::TimeDelta(); - file_util::ScopedFD fd_closer(&fd); std::string contents; char buffer[kOneKilobyte]; ssize_t length; - while ((length = read(fd, buffer, sizeof(buffer))) > 0) + while ((length = read(fd.get(), buffer, sizeof(buffer))) > 0) contents.append(buffer, length); double seconds; @@ -108,16 +109,16 @@ void SaveUpdateRebootNeededUptime() { if (uptime == kZeroTimeDelta) return; - int fd = HANDLE_EINTR(open(update_reboot_needed_uptime_file.value().c_str(), - O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW, - 0666)); - if (fd < 0) + base::ScopedFD fd(HANDLE_EINTR( + open(update_reboot_needed_uptime_file.value().c_str(), + O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW, + 0666))); + if (!fd.is_valid()) return; - file_util::ScopedFD fd_closer(&fd); std::string update_reboot_needed_uptime = base::DoubleToString(uptime.InSecondsF()); - base::WriteFileDescriptor(fd, update_reboot_needed_uptime.c_str(), + base::WriteFileDescriptor(fd.get(), update_reboot_needed_uptime.c_str(), update_reboot_needed_uptime.size()); } |