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

Commit 0b59f3d3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Lotta of small dumpstate fixes..."

parents 3828399b 46b85da7
Loading
Loading
Loading
Loading
+19 −22
Original line number Original line Diff line number Diff line
@@ -19,9 +19,9 @@
// TODO: use android::os::dumpstate (must wait until device code is refactored)
// TODO: use android::os::dumpstate (must wait until device code is refactored)


/*
/*
 * Defines the Linux user that should be executing a command.
 * Defines the Linux account that should be executing a command.
 */
 */
enum RootMode {
enum PrivilegeMode {
    /* Explicitly change the `uid` and `gid` to be `shell`.*/
    /* Explicitly change the `uid` and `gid` to be `shell`.*/
    DROP_ROOT,
    DROP_ROOT,
    /* Don't change the `uid` and `gid`. */
    /* Don't change the `uid` and `gid`. */
@@ -31,12 +31,12 @@ enum RootMode {
};
};


/*
/*
 * Defines what should happen with the `stdout` stream of a command.
 * Defines what should happen with the main output stream (`stdout` or fd) of a command.
 */
 */
enum StdoutMode {
enum OutputMode {
    /* Don't change `stdout`. */
    /* Don't change main output. */
    NORMAL_STDOUT,
    NORMAL_OUTPUT,
    /* Redirect `stdout` to `stderr`. */
    /* Redirect main output to `stderr`. */
    REDIRECT_TO_STDERR
    REDIRECT_TO_STDERR
};
};


@@ -65,8 +65,8 @@ class CommandOptions {


        int64_t timeout_;
        int64_t timeout_;
        bool always_;
        bool always_;
        RootMode root_mode_;
        PrivilegeMode account_mode_;
        StdoutMode stdout_mode_;
        OutputMode output_mode_;
        std::string logging_message_;
        std::string logging_message_;


        friend class CommandOptions;
        friend class CommandOptions;
@@ -82,11 +82,11 @@ class CommandOptions {
      public:
      public:
        /* Sets the command to always run, even on `dry-run` mode. */
        /* Sets the command to always run, even on `dry-run` mode. */
        CommandOptionsBuilder& Always();
        CommandOptionsBuilder& Always();
        /* Sets the command's RootMode as `SU_ROOT` */
        /* Sets the command's PrivilegeMode as `SU_ROOT` */
        CommandOptionsBuilder& AsRoot();
        CommandOptionsBuilder& AsRoot();
        /* Sets the command's RootMode as `DROP_ROOT` */
        /* Sets the command's PrivilegeMode as `DROP_ROOT` */
        CommandOptionsBuilder& DropRoot();
        CommandOptionsBuilder& DropRoot();
        /* Sets the command's StdoutMode `REDIRECT_TO_STDERR` */
        /* Sets the command's OutputMode as `REDIRECT_TO_STDERR` */
        CommandOptionsBuilder& RedirectStderr();
        CommandOptionsBuilder& RedirectStderr();
        /* When not empty, logs a message before executing the command.
        /* When not empty, logs a message before executing the command.
         * Must contain a `%s`, which will be replaced by the full command line, and end on `\n`. */
         * Must contain a `%s`, which will be replaced by the full command line, and end on `\n`. */
@@ -104,10 +104,10 @@ class CommandOptions {
    int64_t Timeout() const;
    int64_t Timeout() const;
    /* Checks whether the command should always be run, even on dry-run mode. */
    /* Checks whether the command should always be run, even on dry-run mode. */
    bool Always() const;
    bool Always() const;
    /** Gets the RootMode of the command. */
    /** Gets the PrivilegeMode of the command. */
    RootMode RootMode() const;
    PrivilegeMode PrivilegeMode() const;
    /** Gets the StdoutMode of the command. */
    /** Gets the OutputMode of the command. */
    StdoutMode StdoutMode() const;
    OutputMode OutputMode() const;
    /** Gets the logging message header, it any. */
    /** Gets the logging message header, it any. */
    std::string LoggingMessage() const;
    std::string LoggingMessage() const;


@@ -128,12 +128,9 @@ class CommandOptions {
 * |full_command| array containing the command (first entry) and its arguments.
 * |full_command| array containing the command (first entry) and its arguments.
 *                Must contain at least one element.
 *                Must contain at least one element.
 * |options| optional argument defining the command's behavior.
 * |options| optional argument defining the command's behavior.
 * |description| optional description of the command to be used on log messages. If empty,
 * the command path (without arguments) will be used instead.
 */
 */
int RunCommandToFd(int fd, const std::vector<const char*>& full_command,
int RunCommandToFd(int fd, const std::vector<std::string>& full_command,
                   const CommandOptions& options = CommandOptions::DEFAULT,
                   const CommandOptions& options = CommandOptions::DEFAULT);
                   const std::string& description = "");


/*
/*
 * Dumps the contents of a file into a file descriptor.
 * Dumps the contents of a file into a file descriptor.
+5 −2
Original line number Original line Diff line number Diff line
@@ -159,7 +159,7 @@ void add_mountinfo() {
    if (!ds.IsZipping()) return;
    if (!ds.IsZipping()) return;
    std::string title = "MOUNT INFO";
    std::string title = "MOUNT INFO";
    mount_points.clear();
    mount_points.clear();
    DurationReporter duration_reporter(title, nullptr);
    DurationReporter duration_reporter(title, true);
    for_each_pid(do_mountinfo, nullptr);
    for_each_pid(do_mountinfo, nullptr);
    MYLOGD("%s: %d entries added to zip file\n", title.c_str(), (int)mount_points.size());
    MYLOGD("%s: %d entries added to zip file\n", title.c_str(), (int)mount_points.size());
}
}
@@ -692,6 +692,7 @@ void Dumpstate::PrintHeader() const {
    printf("Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", id_, pid_,
    printf("Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", id_, pid_,
           dry_run_, args_.c_str(), extra_options_.c_str());
           dry_run_, args_.c_str(), extra_options_.c_str());
    printf("\n");
    printf("\n");
    fflush(stdout);
}
}


// List of file extensions that can cause a zip file attachment to be rejected by some email
// List of file extensions that can cause a zip file attachment to be rejected by some email
@@ -778,7 +779,7 @@ void Dumpstate::AddDir(const std::string& dir, bool recursive) {
        return;
        return;
    }
    }
    MYLOGD("Adding dir %s (recursive: %d)\n", dir.c_str(), recursive);
    MYLOGD("Adding dir %s (recursive: %d)\n", dir.c_str(), recursive);
    DurationReporter duration_reporter(dir, nullptr);
    DurationReporter duration_reporter(dir, true);
    dump_files("", dir.c_str(), recursive ? skip_none : is_dir, _add_file_from_fd);
    dump_files("", dir.c_str(), recursive ? skip_none : is_dir, _add_file_from_fd);
}
}


@@ -1201,6 +1202,8 @@ void Dumpstate::DumpstateBoard() {
    dumpstate_device->dumpstateBoard(handle);
    dumpstate_device->dumpstateBoard(handle);


    AddZipEntry("dumpstate-board.txt", path);
    AddZipEntry("dumpstate-board.txt", path);
    printf("*** See dumpstate-board.txt entry ***\n");
    fflush(stdout);


    native_handle_close(handle);
    native_handle_close(handle);
    native_handle_delete(handle);
    native_handle_delete(handle);
+3 −5
Original line number Original line Diff line number Diff line
@@ -63,18 +63,15 @@ extern "C" {
 */
 */
class DurationReporter {
class DurationReporter {
  public:
  public:
    DurationReporter(const std::string& title);
    DurationReporter(const std::string& title, bool log_only = false);
    DurationReporter(const std::string& title, FILE* out);


    ~DurationReporter();
    ~DurationReporter();


    static uint64_t Nanotime();
    static uint64_t Nanotime();


  private:
  private:
    // TODO: use std::string for title, once dump_files() and other places that pass a char* are
    // refactored as well.
    std::string title_;
    std::string title_;
    FILE* out_;
    bool log_only_;
    uint64_t started_;
    uint64_t started_;


    DISALLOW_COPY_AND_ASSIGN(DurationReporter);
    DISALLOW_COPY_AND_ASSIGN(DurationReporter);
@@ -167,6 +164,7 @@ static std::string VERSION_DEFAULT = "default";
 */
 */
class Dumpstate {
class Dumpstate {
    friend class DumpstateTest;
    friend class DumpstateTest;
    friend class DumpstateUtilTest;


  public:
  public:
    static CommandOptions DEFAULT_DUMPSYS;
    static CommandOptions DEFAULT_DUMPSYS;
+387 −25

File changed.

Preview size limit exceeded, changes collapsed.

+138 −101

File changed.

Preview size limit exceeded, changes collapsed.