[PATCH] perf: fix not exit when fork error

From: jovi zhang
Date: Mon Oct 04 2010 - 23:26:46 EST


fix one bug(not exit when fork error in builtin-stat.c), also unify
some exit code usage.

Signed-off-by: jovi zhang <bookjovi@xxxxxxxxx>
tools/perf/builtin-stat.c | Â Â7 +++++--
tools/perf/builtin-top.c Â| Â Â6 +++---
tools/perf/perf.c     |  Â4 ++--
3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index a6b4d44..fe3e044 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -285,12 +285,15 @@ static int run_perf_stat(int argc __used, const
char **argv)

   if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
       perror("failed to create pipes");
- Â Â Â Â Â Â Â exit(1);
+ Â Â Â Â Â Â Â exit(-1);
   }

   if (forks) {
- Â Â Â Â Â Â Â if ((child_pid = fork()) < 0)
+ Â Â Â Â Â Â Â child_pid = fork();
+ Â Â Â Â Â Â Â if (child_pid < 0) {
           perror("failed to fork");
+ Â Â Â Â Â Â Â Â Â Â Â exit(-1);
+ Â Â Â Â Â Â Â }

       if (!child_pid) {
           close(child_ready_pipe[0]);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index b513e40..d0e646c 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1047,7 +1047,7 @@ static void event__process_sample(const event_t *self,
         RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
           pr_err("The %s file can't be used\n",
              Âsymbol_conf.vmlinux_name);
- Â Â Â Â Â Â Â Â Â Â Â exit(1);
+ Â Â Â Â Â Â Â Â Â Â Â exit(-1);
       }

       return;
@@ -1066,7 +1066,7 @@ static void event__process_sample(const event_t *self,
               machine__fprintf_vmlinux_path(machine, stderr);
           } else
               pr_err(".\n");
- Â Â Â Â Â Â Â Â Â Â Â exit(1);
+ Â Â Â Â Â Â Â Â Â Â Â exit(-1);
       }
   }

@@ -1439,7 +1439,7 @@ int cmd_top(int argc, const char **argv, const
char *prefix __used)
       default_interval = freq;
   } else {
       fprintf(stderr, "frequency and count are zero, aborting\n");
- Â Â Â Â Â Â Â exit(EXIT_FAILURE);
+ Â Â Â Â Â Â Â exit(-1);
   }

   /*
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index cdd6c03..2d4601f 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -468,7 +468,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);
+ Â Â Â Â Â Â Â exit(-1);
   }
   cmd = argv[0];

@@ -492,7 +492,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);
+ Â Â Â Â Â Â Â Â Â Â Â exit(-1);
       }
       if (!done_help) {
           cmd = argv[0] = help_unknown_cmd(cmd);
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i