Skip to content

Commit

Permalink
perf tools: Remove some needless die() calls from the main routine
Browse files Browse the repository at this point in the history
Some would just call exit() anyway right after calling die() and the
main routine doesn't have to call it, just return the exit value.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-nzq0sdur6oq6lgkt2ipf4o8s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
acmel committed Jan 24, 2013
1 parent ab1bf65 commit 2a16bf8
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,23 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
return 0;

status = 1;
/* Check for ENOSPC and EIO errors.. */
if (fflush(stdout))
die("write failure on standard output: %s", strerror(errno));
if (ferror(stdout))
die("unknown write failure on standard output");
if (fclose(stdout))
die("close failed on standard output: %s", strerror(errno));
return 0;
if (fflush(stdout)) {
fprintf(stderr, "write failure on standard output: %s", strerror(errno));
goto out;
}
if (ferror(stdout)) {
fprintf(stderr, "unknown write failure on standard output");
goto out;
}
if (fclose(stdout)) {
fprintf(stderr, "close failed on standard output: %s", strerror(errno));
goto out;
}
status = 0;
out:
return status;
}

static void handle_internal_command(int argc, const char **argv)
Expand Down Expand Up @@ -467,7 +476,8 @@ int main(int argc, const char **argv)
cmd += 5;
argv[0] = cmd;
handle_internal_command(argc, argv);
die("cannot handle %s internally", cmd);
fprintf(stderr, "cannot handle %s internally", cmd);
goto out;
}

/* Look for flags.. */
Expand All @@ -485,7 +495,7 @@ int main(int argc, const char **argv)
printf("\n usage: %s\n\n", perf_usage_string);
list_common_cmds_help();
printf("\n %s\n\n", perf_more_info_string);
exit(1);
goto out;
}
cmd = argv[0];

Expand Down Expand Up @@ -517,7 +527,7 @@ int main(int argc, const char **argv)
fprintf(stderr, "Expansion of alias '%s' failed; "
"'%s' is not a perf-command\n",
cmd, argv[0]);
exit(1);
goto out;
}
if (!done_help) {
cmd = argv[0] = help_unknown_cmd(cmd);
Expand All @@ -528,6 +538,6 @@ int main(int argc, const char **argv)

fprintf(stderr, "Failed to run command '%s': %s\n",
cmd, strerror(errno));

out:
return 1;
}

0 comments on commit 2a16bf8

Please sign in to comment.