Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Masami Hiramatsu and committed by
Arnaldo Carvalho de Melo
b2348e1d 6eb08660

+10 -3
+7 -3
tools/perf/perf.c
··· 313 313 int status; 314 314 struct stat st; 315 315 const char *prefix; 316 + char sbuf[STRERR_BUFSIZE]; 316 317 317 318 prefix = NULL; 318 319 if (p->option & RUN_SETUP) ··· 344 343 status = 1; 345 344 /* Check for ENOSPC and EIO errors.. */ 346 345 if (fflush(stdout)) { 347 - fprintf(stderr, "write failure on standard output: %s", strerror(errno)); 346 + fprintf(stderr, "write failure on standard output: %s", 347 + strerror_r(errno, sbuf, sizeof(sbuf))); 348 348 goto out; 349 349 } 350 350 if (ferror(stdout)) { ··· 353 351 goto out; 354 352 } 355 353 if (fclose(stdout)) { 356 - fprintf(stderr, "close failed on standard output: %s", strerror(errno)); 354 + fprintf(stderr, "close failed on standard output: %s", 355 + strerror_r(errno, sbuf, sizeof(sbuf))); 357 356 goto out; 358 357 } 359 358 status = 0; ··· 469 466 int main(int argc, const char **argv) 470 467 { 471 468 const char *cmd; 469 + char sbuf[STRERR_BUFSIZE]; 472 470 473 471 /* The page_size is placed in util object. */ 474 472 page_size = sysconf(_SC_PAGE_SIZE); ··· 565 561 } 566 562 567 563 fprintf(stderr, "Failed to run command '%s': %s\n", 568 - cmd, strerror(errno)); 564 + cmd, strerror_r(errno, sbuf, sizeof(sbuf))); 569 565 out: 570 566 return 1; 571 567 }
+3
tools/perf/util/debug.h
··· 3 3 #define __PERF_DEBUG_H 4 4 5 5 #include <stdbool.h> 6 + #include <string.h> 6 7 #include "event.h" 7 8 #include "../ui/helpline.h" 8 9 #include "../ui/progress.h" ··· 36 35 37 36 #define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 38 37 #define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 38 + 39 + #define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */ 39 40 40 41 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 41 42 void trace_event(union perf_event *event);