Chromium Code Reviews| Index: tools/android/memdump/memdump.cc |
| diff --git a/tools/android/memdump/memdump.cc b/tools/android/memdump/memdump.cc |
| index 20684f69f820e6357661d5832da3b78a64b0300d..4f4dd14fd548ebc6b5dc672067c890b9ce42b62c 100644 |
| --- a/tools/android/memdump/memdump.cc |
| +++ b/tools/android/memdump/memdump.cc |
| @@ -22,6 +22,7 @@ |
| #include "base/callback_helpers.h" |
| #include "base/containers/hash_tables.h" |
| #include "base/file_util.h" |
| +#include "base/files/scoped_file.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| @@ -436,13 +437,12 @@ bool CollectProcessMemoryInformation(int page_count_fd, |
| int page_flags_fd, |
| ProcessMemory* process_memory) { |
| const pid_t pid = process_memory->pid; |
| - int pagemap_fd = open( |
| - base::StringPrintf("/proc/%d/pagemap", pid).c_str(), O_RDONLY); |
| - if (pagemap_fd < 0) { |
| + base::ScopedFD pagemap_fd(open( |
|
agl
2014/03/18 06:52:05
HANDLE_EINTR
|
| + base::StringPrintf("/proc/%d/pagemap", pid).c_str(), O_RDONLY)); |
| + if (!pagemap_fd.is_valid()) { |
| PLOG(ERROR) << "open"; |
| return false; |
| } |
| - file_util::ScopedFD auto_closer(&pagemap_fd); |
| std::vector<MemoryMap>* const process_maps = &process_memory->memory_maps; |
| if (!GetProcessMaps(pid, process_maps)) |
| return false; |
| @@ -450,7 +450,7 @@ bool CollectProcessMemoryInformation(int page_count_fd, |
| it != process_maps->end(); ++it) { |
| std::vector<PageInfo>* const committed_pages = &it->committed_pages; |
| BitSet* const pages_bits = &it->committed_pages_bits; |
| - GetPagesForMemoryMap(pagemap_fd, *it, committed_pages, pages_bits); |
| + GetPagesForMemoryMap(pagemap_fd.get(), *it, committed_pages, pages_bits); |
| SetPagesInfo(page_count_fd, page_flags_fd, committed_pages); |
| } |
| return true; |
| @@ -489,21 +489,18 @@ int main(int argc, char** argv) { |
| std::vector<ProcessMemory> processes_memory(pids.size()); |
| { |
| - int page_count_fd = open("/proc/kpagecount", O_RDONLY); |
| - if (page_count_fd < 0) { |
| + base::ScopedFD page_count_fd(open("/proc/kpagecount", O_RDONLY)); |
|
agl
2014/03/18 06:52:05
HANDLE_EINTR and on line 493.
|
| + if (!page_count_fd.is_valid()) { |
| PLOG(ERROR) << "open /proc/kpagecount"; |
| return EXIT_FAILURE; |
| } |
| - int page_flags_fd = open("/proc/kpageflags", O_RDONLY); |
| - if (page_flags_fd < 0) { |
| + base::ScopedFD page_flags_fd(open("/proc/kpageflags", O_RDONLY)); |
| + if (!page_flags_fd.is_valid()) { |
| PLOG(ERROR) << "open /proc/kpageflags"; |
| return EXIT_FAILURE; |
| } |
| - file_util::ScopedFD page_count_fd_closer(&page_count_fd); |
| - file_util::ScopedFD page_flags_fd_closer(&page_flags_fd); |
| - |
| base::ScopedClosureRunner auto_resume_processes( |
| base::Bind(&KillAll, pids, SIGCONT)); |
| KillAll(pids, SIGSTOP); |
| @@ -513,7 +510,7 @@ int main(int argc, char** argv) { |
| &processes_memory[it - pids.begin()]; |
| process_memory->pid = *it; |
| if (!CollectProcessMemoryInformation( |
| - page_count_fd, page_flags_fd, process_memory)) { |
| + page_count_fd.get(), page_flags_fd.get(), process_memory)) { |
| return EXIT_FAILURE; |
| } |
| } |