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
(cherry picked from commit 6b9516ced325e93880e9c8ef2793380866a1c579)
Merged-In: I6302f4cb553139c0c26defb4859c4eca5b18ec93
Change-Id: I54ba5e11135b6aefa97d95b287e00325b5867c8a
diff --git a/cmds/dumpstate/DumpstateUtil.cpp b/cmds/dumpstate/DumpstateUtil.cpp
index 7488827..45de8d4 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 <cutils/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,