diff options
| author | Elliott Hughes <enh@google.com> | 2016-03-28 12:15:36 -0700 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2016-03-28 12:15:36 -0700 |
| commit | 2c5d1d7cd914ec8ebf76c8a59d0889ebf5b538cd (patch) | |
| tree | 727283a4b1547819f686ac25d8167fff3d0c9544 /libmemunreachable | |
| parent | 3761365735de4cbc3c8581f0a5e972ad01f8378c (diff) | |
| download | system_core-2c5d1d7cd914ec8ebf76c8a59d0889ebf5b538cd.tar.gz system_core-2c5d1d7cd914ec8ebf76c8a59d0889ebf5b538cd.tar.bz2 system_core-2c5d1d7cd914ec8ebf76c8a59d0889ebf5b538cd.zip | |
Add operator int() to unique_fd.
Change-Id: I7512559be7befbb8772d5529e06550267a2f1543
Diffstat (limited to 'libmemunreachable')
| -rw-r--r-- | libmemunreachable/ProcessMappings.cpp | 5 | ||||
| -rw-r--r-- | libmemunreachable/ThreadCapture.cpp | 7 | ||||
| -rw-r--r-- | libmemunreachable/tests/ThreadCapture_test.cpp | 2 |
3 files changed, 5 insertions, 9 deletions
diff --git a/libmemunreachable/ProcessMappings.cpp b/libmemunreachable/ProcessMappings.cpp index 7cca7c15d..57b232128 100644 --- a/libmemunreachable/ProcessMappings.cpp +++ b/libmemunreachable/ProcessMappings.cpp @@ -30,11 +30,10 @@ bool ProcessMappings(pid_t pid, allocator::vector<Mapping>& mappings) { char map_buffer[1024]; snprintf(map_buffer, sizeof(map_buffer), "/proc/%d/maps", pid); - int fd = open(map_buffer, O_RDONLY); - if (fd < 0) { + android::base::unique_fd fd(open(map_buffer, O_RDONLY)); + if (fd == -1) { return false; } - android::base::unique_fd fd_guard{fd}; LineBuffer line_buf(fd, map_buffer, sizeof(map_buffer)); char* line; diff --git a/libmemunreachable/ThreadCapture.cpp b/libmemunreachable/ThreadCapture.cpp index e8a8392cc..9155c2928 100644 --- a/libmemunreachable/ThreadCapture.cpp +++ b/libmemunreachable/ThreadCapture.cpp @@ -108,12 +108,11 @@ bool ThreadCaptureImpl::ListThreads(TidList& tids) { strlcat(path, pid_str, sizeof(path)); strlcat(path, "/task", sizeof(path)); - int fd = open(path, O_CLOEXEC | O_DIRECTORY | O_RDONLY); - if (fd < 0) { + android::base::unique_fd fd(open(path, O_CLOEXEC | O_DIRECTORY | O_RDONLY)); + if (fd == -1) { ALOGE("failed to open %s: %s", path, strerror(errno)); return false; } - android::base::unique_fd fd_guard{fd}; struct linux_dirent64 { uint64_t d_ino; @@ -125,7 +124,7 @@ bool ThreadCaptureImpl::ListThreads(TidList& tids) { char dirent_buf[4096]; ssize_t nread; do { - nread = syscall(SYS_getdents64, fd, dirent_buf, sizeof(dirent_buf)); + nread = syscall(SYS_getdents64, fd.get(), dirent_buf, sizeof(dirent_buf)); if (nread < 0) { ALOGE("failed to get directory entries from %s: %s", path, strerror(errno)); return false; diff --git a/libmemunreachable/tests/ThreadCapture_test.cpp b/libmemunreachable/tests/ThreadCapture_test.cpp index cefe94e6a..41ed84ee0 100644 --- a/libmemunreachable/tests/ThreadCapture_test.cpp +++ b/libmemunreachable/tests/ThreadCapture_test.cpp @@ -28,8 +28,6 @@ #include <gtest/gtest.h> -#include <android-base/unique_fd.h> - #include "Allocator.h" #include "ScopedDisableMalloc.h" #include "ScopedPipe.h" |
