summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2018-03-15 04:01:35 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-03-15 04:01:35 +0000
commit4eec17a87383ee27286eda7ce8fe1fd51d0fa9ef (patch)
tree4cbfc00a169a9f79f0157e92a5c9ac74a0b3b2b1
parentb370a9b83d32982a9ef1325d74a250ceaf969b05 (diff)
parentd05127172ce1f113230b1774119b6d54475dc158 (diff)
Merge "Avoid crashing when a directory does not exist" into pi-dev
-rw-r--r--cmds/dumpstate/dumpstate.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 371533c4db..10f252fb7e 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -176,6 +176,11 @@ static std::vector<DumpData>* GetDumpFds(const std::string& dir_path,
std::unique_ptr<std::vector<DumpData>> dump_data(new std::vector<DumpData>());
std::unique_ptr<DIR, decltype(&closedir)> dump_dir(opendir(dir_path.c_str()), closedir);
+ if (dump_dir == nullptr) {
+ MYLOGW("Unable to open directory %s: %s\n", dir_path.c_str(), strerror(errno));
+ return dump_data.release();
+ }
+
struct dirent* entry = nullptr;
while ((entry = readdir(dump_dir.get()))) {
if (entry->d_type != DT_REG) {
@@ -191,13 +196,13 @@ static std::vector<DumpData>* GetDumpFds(const std::string& dir_path,
android::base::unique_fd fd(
TEMP_FAILURE_RETRY(open(abs_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)));
if (fd == -1) {
- MYLOGW("Unable to open dump file: %s %s\n", abs_path.c_str(), strerror(errno));
+ MYLOGW("Unable to open dump file %s: %s\n", abs_path.c_str(), strerror(errno));
break;
}
struct stat st = {};
if (fstat(fd, &st) == -1) {
- MYLOGW("Unable to stat dump file: %s %s\n", abs_path.c_str(), strerror(errno));
+ MYLOGW("Unable to stat dump file %s: %s\n", abs_path.c_str(), strerror(errno));
continue;
}