Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23878133 authored by Felipe Leme's avatar Felipe Leme Committed by android-build-merger
Browse files

Merge "Expose functions used to add entries to the zip file." into nyc-dev

am: 6108f5d4

* commit '6108f5d4':
  Expose functions used to add entries to the zip file.

Change-Id: I6c1ce87ce8eb9edf32df7c3f0e1926acd1bc0e00
parents 782ac39b 6108f5d4
Loading
Loading
Loading
Loading
+10 −18
Original line number Diff line number Diff line
@@ -61,9 +61,10 @@ static time_t now;
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 @@ typedef struct {

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 @@ static void dump_dev_files(const char *title, const char *driverpath, const char
    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 @@ static void print_header(std::string version) {
    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 @@ static bool add_zip_entry_from_fd(const std::string& entry_name, int fd) {
    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));
@@ -1133,9 +1133,6 @@ int main(int argc, char *argv[]) {
        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;

@@ -1151,10 +1148,6 @@ int main(int argc, char *argv[]) {
    /* 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;

@@ -1186,7 +1179,6 @@ int main(int argc, char *argv[]) {
        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"
@@ -1281,7 +1273,7 @@ int main(int argc, char *argv[]) {
    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.
+12 −0
Original line number Diff line number Diff line
@@ -81,6 +81,18 @@ static const int WEIGHT_FILE = 5;
 * 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);