Fixed logic that was passing NULL to a std::string parameter and
crashing dumpstate.
BUG: 8420215
Change-Id: If2f3ebad559683b5b6a8c2209de93ac3bec4fb1e
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index dbc53cf..277c73c 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -270,7 +270,7 @@
/* End copy from system/core/logd/LogBuffer.cpp */
/* dumps the current system state to stdout */
-static void dumpstate(std::string screenshot_path) {
+static void dumpstate(const std::string& screenshot_path) {
unsigned long timeout;
time_t now = time(NULL);
char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
@@ -815,13 +815,18 @@
}
}
- if (!screenshot_path.empty() && do_early_screenshot) {
- ALOGI("taking early screenshot\n");
- take_screenshot(screenshot_path);
- ALOGI("wrote screenshot: %s\n", screenshot_path.c_str());
- if (chown(screenshot_path.c_str(), AID_SHELL, AID_SHELL)) {
- ALOGE("Unable to change ownership of screenshot file %s: %s\n",
- screenshot_path.c_str(), strerror(errno));
+ if (do_fb && do_early_screenshot) {
+ if (screenshot_path.empty()) {
+ // should not have happened
+ ALOGE("INTERNAL ERROR: skipping early screenshot because path was not set");
+ } else {
+ ALOGI("taking early screenshot\n");
+ take_screenshot(screenshot_path);
+ ALOGI("wrote screenshot: %s\n", screenshot_path.c_str());
+ if (chown(screenshot_path.c_str(), AID_SHELL, AID_SHELL)) {
+ ALOGE("Unable to change ownership of screenshot file %s: %s\n",
+ screenshot_path.c_str(), strerror(errno));
+ }
}
}
@@ -884,7 +889,7 @@
redirect_to_file(stdout, const_cast<char*>(tmp_path.c_str()));
}
- dumpstate(do_early_screenshot ? NULL : screenshot_path);
+ dumpstate(do_early_screenshot ? "": screenshot_path);
/* done */
if (vibrator) {
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 26e16d0..9623e36 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -140,7 +140,7 @@
void dumpstate_board();
/* Takes a screenshot and save it to the given file */
-void take_screenshot(std::string path);
+void take_screenshot(const std::string& path);
#ifdef __cplusplus
}
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 5115e66..d939779 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -880,7 +880,7 @@
}
}
-void take_screenshot(std::string path) {
+void take_screenshot(const std::string& path) {
const char *args[] = { "/system/bin/screencap", "-p", path.c_str(), NULL };
run_command_always(NULL, 10, args);
}