Merge "Uses a system property to set dry-run mode."
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 8a4ebf3..52c6e56 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -65,6 +65,7 @@
/* suffix of the bugreport files - it's typically the date (when invoked with -d),
* although it could be changed by the user using a system property */
static std::string suffix;
+static bool dry_run = false;
#define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
#define ALT_PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops-0"
@@ -95,7 +96,7 @@
/*
* List of supported zip format versions.
*
- * See bugreport-format.txt for more info.
+ * See bugreport-format.md for more info.
*/
static std::string VERSION_DEFAULT = "1.0";
@@ -103,6 +104,10 @@
return 0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1);
}
+bool is_dry_run() {
+ return dry_run;
+}
+
/* gets the tombstone data, according to the bugreport type: if zipped, gets all tombstones;
* otherwise, gets just those modified in the last half an hour. */
static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
@@ -1161,6 +1166,11 @@
MYLOGI("begin\n");
+ dry_run = property_get_bool("dumpstate.dry_run", 0) != 0;
+ if (is_dry_run()) {
+ MYLOGI("Running on dry-run mode (to disable it, call 'setprop dumpstate.dry_run false')\n");
+ }
+
/* gets the sequential id */
char last_id[PROPERTY_VALUE_MAX];
property_get("dumpstate.last_id", last_id, "0");
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index a7d14f7..389444e 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -14,19 +14,15 @@
* limitations under the License.
*/
-#ifndef _DUMPSTATE_H_
-#define _DUMPSTATE_H_
+#ifndef FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_
+#define FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_
-/* When defined, skips the real dumps and just print the section headers.
- Useful when debugging dumpstate itself. */
-//#define _DUMPSTATE_DRY_RUN_
+#ifndef ON_DRY_RUN_RETURN
+#define ON_DRY_RUN_RETURN(X) if (is_dry_run()) return X
+#endif
-#ifdef _DUMPSTATE_DRY_RUN_
-#define ON_DRY_RUN_RETURN(X) return X
-#define ON_DRY_RUN(code) code
-#else
-#define ON_DRY_RUN_RETURN(X)
-#define ON_DRY_RUN(code)
+#ifndef ON_DRY_RUN
+#define ON_DRY_RUN(code) if (is_dry_run()) code
#endif
#ifndef MYLOGD
@@ -212,6 +208,15 @@
bool is_user_build();
/*
+ * When running in dry-run mode, skips the real dumps and just print the section headers.
+ *
+ * Useful when debugging dumpstate or other bugreport-related activities.
+ *
+ * Dry-run mode is enabled by setting the system property dumpstate.dry_run to true.
+ */
+bool is_dry_run();
+
+/*
* Helper class used to report how long it takes for a section to finish.
*
* Typical usage:
@@ -238,4 +243,4 @@
}
#endif
-#endif /* _DUMPSTATE_H_ */
+#endif /* FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_ */