summaryrefslogtreecommitdiffstats
path: root/tools/android
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-23 18:21:23 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-23 18:21:23 +0000
commitc1a04512be0d81b9971f7bfea404c0072a86071d (patch)
treebaeb258a62dfef4e6386ca6efe9826ae6452c3c5 /tools/android
parentc4435c5e4bcd78cf6c535ae89dd9d1c09b5ce5fa (diff)
downloadchromium_src-c1a04512be0d81b9971f7bfea404c0072a86071d.zip
chromium_src-c1a04512be0d81b9971f7bfea404c0072a86071d.tar.gz
chromium_src-c1a04512be0d81b9971f7bfea404c0072a86071d.tar.bz2
Use file_util::ScopedFD in forwarder2's Daemon.
Review URL: https://chromiumcodereview.appspot.com/11348213 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/forwarder2/daemon.cc31
1 files changed, 4 insertions, 27 deletions
diff --git a/tools/android/forwarder2/daemon.cc b/tools/android/forwarder2/daemon.cc
index 5bdf936..4704e13 100644
--- a/tools/android/forwarder2/daemon.cc
+++ b/tools/android/forwarder2/daemon.cc
@@ -34,29 +34,6 @@ namespace {
const int kBufferSize = 256;
-class FileDescriptorAutoCloser {
- public:
- explicit FileDescriptorAutoCloser(int fd) : fd_(fd) {
- DCHECK(fd_ >= 0);
- }
-
- ~FileDescriptorAutoCloser() {
- if (fd_ > -1)
- CloseFD(fd_);
- }
-
- int Release() {
- const int fd = fd_;
- fd_ = -1;
- return fd;
- }
-
- private:
- int fd_;
-
- DISALLOW_COPY_AND_ASSIGN(FileDescriptorAutoCloser);
-};
-
void InitLoggingForDaemon(const std::string& log_file) {
CHECK(
logging::InitLogging(
@@ -177,13 +154,13 @@ class Daemon::PIDFile {
public:
static scoped_ptr<PIDFile> Create(const std::string& path) {
scoped_ptr<PIDFile> pid_file;
- const int pid_file_fd = HANDLE_EINTR(
+ int pid_file_fd = HANDLE_EINTR(
open(path.c_str(), O_CREAT | O_WRONLY, 0600));
if (pid_file_fd < 0) {
PError("open()");
return pid_file.Pass();
}
- FileDescriptorAutoCloser fd_closer(pid_file_fd);
+ file_util::ScopedFD fd_closer(&pid_file_fd);
struct flock lock_info = {};
lock_info.l_type = F_WRLCK;
lock_info.l_whence = SEEK_CUR;
@@ -198,7 +175,7 @@ class Daemon::PIDFile {
const std::string pid_string = base::StringPrintf("%d\n", getpid());
CHECK(HANDLE_EINTR(write(pid_file_fd, pid_string.c_str(),
pid_string.length())));
- pid_file.reset(new PIDFile(fd_closer.Release(), path));
+ pid_file.reset(new PIDFile(*fd_closer.release(), path));
return pid_file.Pass();
}
@@ -328,7 +305,7 @@ bool Daemon::Kill() {
<< safe_strerror(errno);
return false;
}
- const FileDescriptorAutoCloser fd_closer(pid_file_fd);
+ const file_util::ScopedFD fd_closer(&pid_file_fd);
pid_t lock_owner_pid;
if (!GetFileLockOwnerPid(pid_file_fd, &lock_owner_pid))
return false;