diff options
author | David Ahern <dsahern@gmail.com> | 2012-08-26 14:24:45 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-05 16:21:10 -0400 |
commit | cc58482133296f52873be909a2795f6d934ecec9 (patch) | |
tree | 61e1427bcb8ad9ae09227ff5dea6cb6406a98a22 /tools/perf/builtin-help.c | |
parent | fceda7feb4a7822feee9662bc64968230d8f37bf (diff) |
perf help: Remove use of die and handle errors
Allows perf to clean up properly on exit.
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1346005487-62961-6-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-help.c')
-rw-r--r-- | tools/perf/builtin-help.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 6d5a8a7faf48..f9daae5ac47a 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c | |||
@@ -24,13 +24,14 @@ static struct man_viewer_info_list { | |||
24 | } *man_viewer_info_list; | 24 | } *man_viewer_info_list; |
25 | 25 | ||
26 | enum help_format { | 26 | enum help_format { |
27 | HELP_FORMAT_NONE, | ||
27 | HELP_FORMAT_MAN, | 28 | HELP_FORMAT_MAN, |
28 | HELP_FORMAT_INFO, | 29 | HELP_FORMAT_INFO, |
29 | HELP_FORMAT_WEB, | 30 | HELP_FORMAT_WEB, |
30 | }; | 31 | }; |
31 | 32 | ||
32 | static bool show_all = false; | 33 | static bool show_all = false; |
33 | static enum help_format help_format = HELP_FORMAT_MAN; | 34 | static enum help_format help_format = HELP_FORMAT_NONE; |
34 | static struct option builtin_help_options[] = { | 35 | static struct option builtin_help_options[] = { |
35 | OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), | 36 | OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), |
36 | OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), | 37 | OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), |
@@ -54,7 +55,9 @@ static enum help_format parse_help_format(const char *format) | |||
54 | return HELP_FORMAT_INFO; | 55 | return HELP_FORMAT_INFO; |
55 | if (!strcmp(format, "web") || !strcmp(format, "html")) | 56 | if (!strcmp(format, "web") || !strcmp(format, "html")) |
56 | return HELP_FORMAT_WEB; | 57 | return HELP_FORMAT_WEB; |
57 | die("unrecognized help format '%s'", format); | 58 | |
59 | pr_err("unrecognized help format '%s'", format); | ||
60 | return HELP_FORMAT_NONE; | ||
58 | } | 61 | } |
59 | 62 | ||
60 | static const char *get_man_viewer_info(const char *name) | 63 | static const char *get_man_viewer_info(const char *name) |
@@ -259,6 +262,8 @@ static int perf_help_config(const char *var, const char *value, void *cb) | |||
259 | if (!value) | 262 | if (!value) |
260 | return config_error_nonbool(var); | 263 | return config_error_nonbool(var); |
261 | help_format = parse_help_format(value); | 264 | help_format = parse_help_format(value); |
265 | if (help_format == HELP_FORMAT_NONE) | ||
266 | return -1; | ||
262 | return 0; | 267 | return 0; |
263 | } | 268 | } |
264 | if (!strcmp(var, "man.viewer")) { | 269 | if (!strcmp(var, "man.viewer")) { |
@@ -352,7 +357,7 @@ static void exec_viewer(const char *name, const char *page) | |||
352 | warning("'%s': unknown man viewer.", name); | 357 | warning("'%s': unknown man viewer.", name); |
353 | } | 358 | } |
354 | 359 | ||
355 | static void show_man_page(const char *perf_cmd) | 360 | static int show_man_page(const char *perf_cmd) |
356 | { | 361 | { |
357 | struct man_viewer_list *viewer; | 362 | struct man_viewer_list *viewer; |
358 | const char *page = cmd_to_page(perf_cmd); | 363 | const char *page = cmd_to_page(perf_cmd); |
@@ -365,28 +370,35 @@ static void show_man_page(const char *perf_cmd) | |||
365 | if (fallback) | 370 | if (fallback) |
366 | exec_viewer(fallback, page); | 371 | exec_viewer(fallback, page); |
367 | exec_viewer("man", page); | 372 | exec_viewer("man", page); |
368 | die("no man viewer handled the request"); | 373 | |
374 | pr_err("no man viewer handled the request"); | ||
375 | return -1; | ||
369 | } | 376 | } |
370 | 377 | ||
371 | static void show_info_page(const char *perf_cmd) | 378 | static int show_info_page(const char *perf_cmd) |
372 | { | 379 | { |
373 | const char *page = cmd_to_page(perf_cmd); | 380 | const char *page = cmd_to_page(perf_cmd); |
374 | setenv("INFOPATH", system_path(PERF_INFO_PATH), 1); | 381 | setenv("INFOPATH", system_path(PERF_INFO_PATH), 1); |
375 | execlp("info", "info", "perfman", page, NULL); | 382 | execlp("info", "info", "perfman", page, NULL); |
383 | return -1; | ||
376 | } | 384 | } |
377 | 385 | ||
378 | static void get_html_page_path(struct strbuf *page_path, const char *page) | 386 | static int get_html_page_path(struct strbuf *page_path, const char *page) |
379 | { | 387 | { |
380 | struct stat st; | 388 | struct stat st; |
381 | const char *html_path = system_path(PERF_HTML_PATH); | 389 | const char *html_path = system_path(PERF_HTML_PATH); |
382 | 390 | ||
383 | /* Check that we have a perf documentation directory. */ | 391 | /* Check that we have a perf documentation directory. */ |
384 | if (stat(mkpath("%s/perf.html", html_path), &st) | 392 | if (stat(mkpath("%s/perf.html", html_path), &st) |
385 | || !S_ISREG(st.st_mode)) | 393 | || !S_ISREG(st.st_mode)) { |
386 | die("'%s': not a documentation directory.", html_path); | 394 | pr_err("'%s': not a documentation directory.", html_path); |
395 | return -1; | ||
396 | } | ||
387 | 397 | ||
388 | strbuf_init(page_path, 0); | 398 | strbuf_init(page_path, 0); |
389 | strbuf_addf(page_path, "%s/%s.html", html_path, page); | 399 | strbuf_addf(page_path, "%s/%s.html", html_path, page); |
400 | |||
401 | return 0; | ||
390 | } | 402 | } |
391 | 403 | ||
392 | /* | 404 | /* |
@@ -401,19 +413,23 @@ static void open_html(const char *path) | |||
401 | } | 413 | } |
402 | #endif | 414 | #endif |
403 | 415 | ||
404 | static void show_html_page(const char *perf_cmd) | 416 | static int show_html_page(const char *perf_cmd) |
405 | { | 417 | { |
406 | const char *page = cmd_to_page(perf_cmd); | 418 | const char *page = cmd_to_page(perf_cmd); |
407 | struct strbuf page_path; /* it leaks but we exec bellow */ | 419 | struct strbuf page_path; /* it leaks but we exec bellow */ |
408 | 420 | ||
409 | get_html_page_path(&page_path, page); | 421 | if (get_html_page_path(&page_path, page) != 0) |
422 | return -1; | ||
410 | 423 | ||
411 | open_html(page_path.buf); | 424 | open_html(page_path.buf); |
425 | |||
426 | return 0; | ||
412 | } | 427 | } |
413 | 428 | ||
414 | int cmd_help(int argc, const char **argv, const char *prefix __used) | 429 | int cmd_help(int argc, const char **argv, const char *prefix __used) |
415 | { | 430 | { |
416 | const char *alias; | 431 | const char *alias; |
432 | int rc = 0; | ||
417 | 433 | ||
418 | load_command_list("perf-", &main_cmds, &other_cmds); | 434 | load_command_list("perf-", &main_cmds, &other_cmds); |
419 | 435 | ||
@@ -444,16 +460,20 @@ int cmd_help(int argc, const char **argv, const char *prefix __used) | |||
444 | 460 | ||
445 | switch (help_format) { | 461 | switch (help_format) { |
446 | case HELP_FORMAT_MAN: | 462 | case HELP_FORMAT_MAN: |
447 | show_man_page(argv[0]); | 463 | rc = show_man_page(argv[0]); |
448 | break; | 464 | break; |
449 | case HELP_FORMAT_INFO: | 465 | case HELP_FORMAT_INFO: |
450 | show_info_page(argv[0]); | 466 | rc = show_info_page(argv[0]); |
451 | break; | 467 | break; |
452 | case HELP_FORMAT_WEB: | 468 | case HELP_FORMAT_WEB: |
453 | show_html_page(argv[0]); | 469 | rc = show_html_page(argv[0]); |
470 | break; | ||
471 | case HELP_FORMAT_NONE: | ||
472 | /* fall-through */ | ||
454 | default: | 473 | default: |
474 | rc = -1; | ||
455 | break; | 475 | break; |
456 | } | 476 | } |
457 | 477 | ||
458 | return 0; | 478 | return rc; |
459 | } | 479 | } |