diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2014-08-13 22:22:32 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-08-15 09:54:29 -0400 |
commit | b2348e1d8a67c58de44820587fabc4f987eafbb6 (patch) | |
tree | 2c6504e6cc99fa53b8f8daeabd38dd79e33eb5da | |
parent | 6eb08660962a91212902869672dab5199827cbfd (diff) |
perf: Use strerror_r instead of strerror
Use strerror_r instead of strerror in error messages for thread-safety.
This also introduce STRERR_BUFSIZE macro for the default size of message
buffer for strerror_r.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20140814022232.3545.14026.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/perf.c | 10 | ||||
-rw-r--r-- | tools/perf/util/debug.h | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 2282d41879a2..452a8474d29d 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -313,6 +313,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
313 | int status; | 313 | int status; |
314 | struct stat st; | 314 | struct stat st; |
315 | const char *prefix; | 315 | const char *prefix; |
316 | char sbuf[STRERR_BUFSIZE]; | ||
316 | 317 | ||
317 | prefix = NULL; | 318 | prefix = NULL; |
318 | if (p->option & RUN_SETUP) | 319 | if (p->option & RUN_SETUP) |
@@ -343,7 +344,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
343 | status = 1; | 344 | status = 1; |
344 | /* Check for ENOSPC and EIO errors.. */ | 345 | /* Check for ENOSPC and EIO errors.. */ |
345 | if (fflush(stdout)) { | 346 | if (fflush(stdout)) { |
346 | fprintf(stderr, "write failure on standard output: %s", strerror(errno)); | 347 | fprintf(stderr, "write failure on standard output: %s", |
348 | strerror_r(errno, sbuf, sizeof(sbuf))); | ||
347 | goto out; | 349 | goto out; |
348 | } | 350 | } |
349 | if (ferror(stdout)) { | 351 | if (ferror(stdout)) { |
@@ -351,7 +353,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
351 | goto out; | 353 | goto out; |
352 | } | 354 | } |
353 | if (fclose(stdout)) { | 355 | if (fclose(stdout)) { |
354 | fprintf(stderr, "close failed on standard output: %s", strerror(errno)); | 356 | fprintf(stderr, "close failed on standard output: %s", |
357 | strerror_r(errno, sbuf, sizeof(sbuf))); | ||
355 | goto out; | 358 | goto out; |
356 | } | 359 | } |
357 | status = 0; | 360 | status = 0; |
@@ -466,6 +469,7 @@ void pthread__unblock_sigwinch(void) | |||
466 | int main(int argc, const char **argv) | 469 | int main(int argc, const char **argv) |
467 | { | 470 | { |
468 | const char *cmd; | 471 | const char *cmd; |
472 | char sbuf[STRERR_BUFSIZE]; | ||
469 | 473 | ||
470 | /* The page_size is placed in util object. */ | 474 | /* The page_size is placed in util object. */ |
471 | page_size = sysconf(_SC_PAGE_SIZE); | 475 | page_size = sysconf(_SC_PAGE_SIZE); |
@@ -561,7 +565,7 @@ int main(int argc, const char **argv) | |||
561 | } | 565 | } |
562 | 566 | ||
563 | fprintf(stderr, "Failed to run command '%s': %s\n", | 567 | fprintf(stderr, "Failed to run command '%s': %s\n", |
564 | cmd, strerror(errno)); | 568 | cmd, strerror_r(errno, sbuf, sizeof(sbuf))); |
565 | out: | 569 | out: |
566 | return 1; | 570 | return 1; |
567 | } | 571 | } |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 6944ea3a119b..be264d6f3b30 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -3,6 +3,7 @@ | |||
3 | #define __PERF_DEBUG_H | 3 | #define __PERF_DEBUG_H |
4 | 4 | ||
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <string.h> | ||
6 | #include "event.h" | 7 | #include "event.h" |
7 | #include "../ui/helpline.h" | 8 | #include "../ui/helpline.h" |
8 | #include "../ui/progress.h" | 9 | #include "../ui/progress.h" |
@@ -36,6 +37,8 @@ extern int debug_ordered_events; | |||
36 | #define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) | 37 | #define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) |
37 | #define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) | 38 | #define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) |
38 | 39 | ||
40 | #define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */ | ||
41 | |||
39 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | 42 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
40 | void trace_event(union perf_event *event); | 43 | void trace_event(union perf_event *event); |
41 | 44 | ||