Merge "Expose functions used to add entries to the zip file." into nyc-dev
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 5f698a9..613f9df 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -61,9 +61,10 @@
 static std::unique_ptr<ZipWriter> zip_writer;
 static std::set<std::string> mount_points;
 void add_mountinfo();
-static bool add_zip_entry(const std::string& entry_name, const std::string& entry_path);
-static bool add_zip_entry_from_fd(const std::string& entry_name, int fd);
 static int control_socket_fd;
+/* 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;
 
 #define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
 
@@ -84,8 +85,8 @@
 
 static tombstone_data_t tombstone_data[NUM_TOMBSTONES];
 
-// Root dir for all files copied as-is into the bugreport
-const std::string& ZIP_ROOT_DIR = "FS";
+const std::string ZIP_ROOT_DIR = "FS";
+std::string bugreport_dir;
 
 /*
  * List of supported zip format versions.
@@ -175,11 +176,12 @@
     closedir(d);
 }
 
-static void dump_systrace(const std::string& systrace_path) {
+static void dump_systrace() {
     if (!zip_writer) {
         MYLOGD("Not dumping systrace because zip_writer is not set\n");
         return;
     }
+    std::string systrace_path = bugreport_dir + "/systrace-" + suffix + ".txt";
     if (systrace_path.empty()) {
         MYLOGE("Not dumping systrace because path is empty\n");
         return;
@@ -527,8 +529,7 @@
     printf("\n");
 }
 
-/* adds a new entry to the existing zip file. */
-static bool add_zip_entry_from_fd(const std::string& entry_name, int fd) {
+bool add_zip_entry_from_fd(const std::string& entry_name, int fd) {
     if (!zip_writer) {
         MYLOGD("Not adding zip entry %s from fd because zip_writer is not set\n",
                 entry_name.c_str());
@@ -569,8 +570,7 @@
     return true;
 }
 
-/* adds a new entry to the existing zip file. */
-static bool add_zip_entry(const std::string& entry_name, const std::string& entry_path) {
+bool add_zip_entry(const std::string& entry_name, const std::string& entry_path) {
     ScopedFd fd(TEMP_FAILURE_RETRY(open(entry_path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
     if (fd.get() == -1) {
         MYLOGE("open(%s): %s\n", entry_path.c_str(), strerror(errno));
@@ -1131,9 +1131,6 @@
         control_socket_fd = open_socket("dumpstate");
     }
 
-    /* full path of the directory where the bugreport files will be written */
-    std::string bugreport_dir;
-
     /* full path of the temporary file containing the bugreport */
     std::string tmp_path;
 
@@ -1149,10 +1146,6 @@
     /* base name (without suffix or extensions) of the bugreport files */
     std::string base_name;
 
-    /* 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 */
-    std::string suffix;
-
     /* pointer to the actual path, be it zip or text */
     std::string path;
 
@@ -1184,7 +1177,6 @@
         tmp_path = bugreport_dir + "/" + base_name + "-" + suffix + ".tmp";
         log_path = bugreport_dir + "/dumpstate_log-" + suffix + "-"
                 + std::to_string(getpid()) + ".txt";
-        systrace_path = bugreport_dir + "/systrace-" + suffix + ".txt";
 
         MYLOGD("Bugreport dir: %s\n"
                 "Base name: %s\n"
@@ -1279,7 +1271,7 @@
     print_header(version);
 
     // Dumps systrace right away, otherwise it will be filled with unnecessary events.
-    dump_systrace(systrace_path);
+    dump_systrace();
 
     // Invoking the following dumpsys calls before dump_traces() to try and
     // keep the system stats as close to its initial state as possible.
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index c51c79a..94bfc5a 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -81,6 +81,18 @@
  * idioms (like using std::string instead of char*, removing varargs, etc...) */
 extern int do_update_progress, progress, weight_total;
 
+/* full path of the directory where the bugreport files will be written */
+extern std::string bugreport_dir;
+
+/* root dir for all files copied as-is into the bugreport. */
+extern const std::string ZIP_ROOT_DIR;
+
+/* adds a new entry to the existing zip file. */
+bool add_zip_entry(const std::string& entry_name, const std::string& entry_path);
+
+/* adds a new entry to the existing zip file. */
+bool add_zip_entry_from_fd(const std::string& entry_name, int fd);
+
 /* prints the contents of a file */
 int dump_file(const char *title, const char *path);