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

Commit 12ae14a5 authored by Nandana Dutt's avatar Nandana Dutt
Browse files

Simplify the exit conditions for dumpstate

Now that the exit conditions are mostly in one place it is more readable
to directly call exit.

BUG:111441001
Test: /system/bin/dumpstate -d || echo "bad flag works as expected"
Test: /system/bin/dumpstate -h && echo "help flag works as expected"
Test: adb bugreport a.zip
Change-Id: Ie40d81a3317ad8bb97c825523533ea3fa1016733
parent dc23aff2
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -1695,7 +1695,7 @@ void Dumpstate::DumpstateBoard() {
    printf("*** See dumpstate-board.txt entry ***\n");
}

static void ShowUsageAndExit(int exit_code = 1) {
static void ShowUsage() {
    fprintf(stderr,
            "usage: dumpstate [-h] [-b soundfile] [-e soundfile] [-o file] [-d] [-p] "
            "[-z]] [-s] [-S] [-q] [-B] [-P] [-R] [-V version]\n"
@@ -1715,12 +1715,6 @@ static void ShowUsageAndExit(int exit_code = 1) {
            "  -R: take bugreport in remote mode (requires -o, -z, -d and -B, "
            "shouldn't be used with -P)\n"
            "  -v: prints the dumpstate header and exit\n");
    exit(exit_code);
}

static void ExitOnInvalidArgs() {
    fprintf(stderr, "invalid combination of args\n");
    ShowUsageAndExit();
}

static void register_sig_handler() {
@@ -2517,17 +2511,18 @@ int run_main(int argc, char* argv[]) {

    switch (status) {
        case Dumpstate::RunStatus::OK:
            return 0;
            // TODO(b/111441001): Exit directly in the following cases.
            exit(0);
        case Dumpstate::RunStatus::HELP:
            ShowUsageAndExit(0 /* exit code */);
            break;
            ShowUsage();
            exit(0);
        case Dumpstate::RunStatus::INVALID_INPUT:
            ExitOnInvalidArgs();
            break;
            fprintf(stderr, "Invalid combination of args\n");
            ShowUsage();
            exit(1);
        case Dumpstate::RunStatus::ERROR:
            exit(-1);
            break;
            exit(2);
        default:
            fprintf(stderr, "Unknown status: %d\n", status);
            exit(2);
    }
    return 0;
}