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

Commit c7fe8fe5 authored by Felipe Leme's avatar Felipe Leme
Browse files

Deprecate run_command() and dump_file().

This change will break dumpstate_board() implementations that were not
refactored to use the equivalent functions in the Dumpstate
class. For example:

void dumpstate_board() {
  dump_file("INTERRUPTS", "/proc/interrupts");
  run_command("SUBSYSTEM TOMBSTONES", 5, SU_PATH, "root",
              "ls", "-l", "/data/tombstones/ramdump", NULL);

}

Should be refactored to:

void dumpstate_board(){
  Dumpstate& ds = Dumpstate::GetInstance();

  ds.DumpFile("INTERRUPTS", "/proc/interrupts");
  ds.RunCommand("SUBSYSTEM TOMBSTONES",
                {"ls", "-l", "/data/tombstones/ramdump"},
                CommandOptions::AS_ROOT_5);
}

BUG: 26379932
Test: manual / refactored code

Change-Id: Ia74515cc57abc18bc6966a5aed71dd679422fd0e
parent 4ae86b1a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -367,7 +367,7 @@ static void dump_systrace() {
    if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--async_dump", "-o", systrace_path},
    if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--async_dump", "-o", systrace_path},
                   CommandOptions::WithTimeout(120).Build())) {
                   CommandOptions::WithTimeout(120).Build())) {
        MYLOGE("systrace timed out, its zip entry will be incomplete\n");
        MYLOGE("systrace timed out, its zip entry will be incomplete\n");
        // TODO: run_command tries to kill the process, but atrace doesn't die
        // TODO: RunCommand tries to kill the process, but atrace doesn't die
        // peacefully; ideally, we should call strace to stop itself, but there is no such option
        // peacefully; ideally, we should call strace to stop itself, but there is no such option
        // yet (just a --async_stop, which stops and dump
        // yet (just a --async_stop, which stops and dump
        // if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--kill"})) {
        // if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--kill"})) {
@@ -1621,7 +1621,7 @@ int main(int argc, char *argv[]) {
    dump_iptables();
    dump_iptables();


    // Run ss as root so we can see socket marks.
    // Run ss as root so we can see socket marks.
    run_command("DETAILED SOCKET STATE", 10, "ss", "-eionptu", NULL);
    RunCommand("DETAILED SOCKET STATE", {"ss", "-eionptu"}, CommandOptions::WithTimeout(10).Build());


    if (!drop_root_user()) {
    if (!drop_root_user()) {
        return -1;
        return -1;
+0 −10
Original line number Original line Diff line number Diff line
@@ -300,11 +300,6 @@ bool add_zip_entry_from_fd(const std::string& entry_name, int fd);
/* adds all files from a directory to the zipped bugreport file */
/* adds all files from a directory to the zipped bugreport file */
void add_dir(const std::string& dir, bool recursive);
void add_dir(const std::string& dir, bool recursive);


/* prints the contents of a file
 * DEPRECATED: will be removed once device-specific implementations use
 * dumpFile */
int dump_file(const char *title, const char *path);

/* saves the the contents of a file as a long */
/* saves the the contents of a file as a long */
int read_file_as_long(const char *path, long int *output);
int read_file_as_long(const char *path, long int *output);


@@ -322,11 +317,6 @@ int dump_file_from_fd(const char *title, const char *path, int fd);
int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path),
int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path),
               int (*dump_from_fd)(const char* title, const char* path, int fd));
               int (*dump_from_fd)(const char* title, const char* path, int fd));


/* forks a command and waits for it to finish -- terminate args with NULL
 * DEPRECATED: will be removed once device-specific implementations use
 * RunCommand */
int run_command(const char *title, int timeout_seconds, const char *command, ...);

/* switch to non-root user and group */
/* switch to non-root user and group */
bool drop_root_user();
bool drop_root_user();


+1 −24
Original line number Original line Diff line number Diff line
@@ -576,11 +576,6 @@ static int _dump_file_from_fd(const std::string& title, const char* path, int fd
    return 0;
    return 0;
}
}


// DEPRECATED: will be removed once device-specific implementations use dumpFile
int dump_file(const char *title, const char *path) {
    return ds.DumpFile(title, path);
}

int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
    DurationReporter durationReporter(title);
    DurationReporter durationReporter(title);
    int fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC));
    int fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC));
@@ -748,24 +743,6 @@ bool waitpid_with_timeout(pid_t pid, int timeout_seconds, int* status) {
    return true;
    return true;
}
}


// DEPRECATED: will be removed once device-specific implementations use RunCommand
int run_command(const char* title, int timeout_seconds, const char* command, ...) {
    std::vector<std::string> fullCommand = {command};
    size_t arg;
    va_list ap;
    va_start(ap, command);
    for (arg = 0; arg < MAX_ARGS_ARRAY_SIZE; ++arg) {
        const char* ptr = va_arg(ap, const char*);
        if (ptr == nullptr) {
            break;
        }
        fullCommand.push_back(ptr);
    }
    va_end(ap);

    return ds.RunCommand(title, fullCommand, CommandOptions::WithTimeout(timeout_seconds).Build());
}

int Dumpstate::RunCommand(const std::string& title, const std::vector<std::string>& fullCommand,
int Dumpstate::RunCommand(const std::string& title, const std::vector<std::string>& fullCommand,
                          const CommandOptions& options) {
                          const CommandOptions& options) {
    if (fullCommand.empty()) {
    if (fullCommand.empty()) {
@@ -1271,7 +1248,7 @@ void dump_route_tables() {
    DurationReporter duration_reporter("DUMP ROUTE TABLES");
    DurationReporter duration_reporter("DUMP ROUTE TABLES");
    if (is_dry_run()) return;
    if (is_dry_run()) return;
    const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
    const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
    dump_file("RT_TABLES", RT_TABLES_PATH);
    ds.DumpFile("RT_TABLES", RT_TABLES_PATH);
    FILE* fp = fopen(RT_TABLES_PATH, "re");
    FILE* fp = fopen(RT_TABLES_PATH, "re");
    if (!fp) {
    if (!fp) {
        printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno));
        printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno));