dumpstate: always include last ANR as a separate entry.
For consistency, as well as to make tooling easier.
Most of this change is an extended yak-shave to try and close DumpData
FDs in a consistent manner. Several layers of abstraction were assuming
that it was their job to close input FDs, leading to double closes in some
cases. These double closes are benign prior to this change to dump a
given DumpData twice, given that dumpstate is single threaded.
Bug: 68188758
Test: adb bugreport
Change-Id: I6302f4cb553139c0c26defb4859c4eca5b18ec93
diff --git a/cmds/dumpstate/DumpstateUtil.cpp b/cmds/dumpstate/DumpstateUtil.cpp
index ea7109b..ede4254 100644
--- a/cmds/dumpstate/DumpstateUtil.cpp
+++ b/cmds/dumpstate/DumpstateUtil.cpp
@@ -30,6 +30,7 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <android-base/unique_fd.h>
#include <log/log.h>
#include "DumpstateInternal.h"
@@ -182,8 +183,8 @@
}
int DumpFileToFd(int out_fd, const std::string& title, const std::string& path) {
- int fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC));
- if (fd < 0) {
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
+ if (fd.get() < 0) {
int err = errno;
if (title.empty()) {
dprintf(out_fd, "*** Error dumping %s: %s\n", path.c_str(), strerror(err));
@@ -194,7 +195,7 @@
fsync(out_fd);
return -1;
}
- return DumpFileFromFdToFd(title, path, fd, out_fd, PropertiesHelper::IsDryRun());
+ return DumpFileFromFdToFd(title, path, fd.get(), out_fd, PropertiesHelper::IsDryRun());
}
int RunCommandToFd(int fd, const std::string& title, const std::vector<std::string>& full_command,