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

perf probe: Make error messages thread-safe

To make error messages thread-safe, this replaces strerror with
strerror_r for warnings, and just shows the return value instead of
using strerror for debug messages.

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/20140814022234.3545.22199.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
5f03cba4 b2348e1d

+24 -16
+4 -1
tools/perf/builtin-probe.c
··· 290 290 291 291 static void pr_err_with_code(const char *msg, int err) 292 292 { 293 + char sbuf[STRERR_BUFSIZE]; 294 + 293 295 pr_err("%s", msg); 294 - pr_debug(" Reason: %s (Code: %d)", strerror(-err), err); 296 + pr_debug(" Reason: %s (Code: %d)", 297 + strerror_r(-err, sbuf, sizeof(sbuf)), err); 295 298 pr_err("\n"); 296 299 } 297 300
+15 -13
tools/perf/util/probe-event.c
··· 573 573 574 574 static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) 575 575 { 576 - char buf[LINEBUF_SIZE]; 576 + char buf[LINEBUF_SIZE], sbuf[STRERR_BUFSIZE]; 577 577 const char *color = show_num ? "" : PERF_COLOR_BLUE; 578 578 const char *prefix = NULL; 579 579 ··· 593 593 return 1; 594 594 error: 595 595 if (ferror(fp)) { 596 - pr_warning("File read error: %s\n", strerror(errno)); 596 + pr_warning("File read error: %s\n", 597 + strerror_r(errno, sbuf, sizeof(sbuf))); 597 598 return -1; 598 599 } 599 600 return 0; ··· 627 626 FILE *fp; 628 627 int ret; 629 628 char *tmp; 629 + char sbuf[STRERR_BUFSIZE]; 630 630 631 631 /* Search a line range */ 632 632 dinfo = open_debuginfo(module, false); ··· 664 662 fp = fopen(lr->path, "r"); 665 663 if (fp == NULL) { 666 664 pr_warning("Failed to open %s: %s\n", lr->path, 667 - strerror(errno)); 665 + strerror_r(errno, sbuf, sizeof(sbuf))); 668 666 return -errno; 669 667 } 670 668 /* Skip to starting line number */ ··· 1412 1410 1413 1411 return tmp - buf; 1414 1412 error: 1415 - pr_debug("Failed to synthesize perf probe argument: %s\n", 1416 - strerror(-ret)); 1413 + pr_debug("Failed to synthesize perf probe argument: %d\n", ret); 1417 1414 return ret; 1418 1415 } 1419 1416 ··· 1461 1460 1462 1461 return buf; 1463 1462 error: 1464 - pr_debug("Failed to synthesize perf probe point: %s\n", 1465 - strerror(-ret)); 1463 + pr_debug("Failed to synthesize perf probe point: %d\n", ret); 1466 1464 free(buf); 1467 1465 return NULL; 1468 1466 } ··· 1787 1787 1788 1788 static void print_open_warning(int err, bool is_kprobe) 1789 1789 { 1790 - char sbuf[128]; 1790 + char sbuf[STRERR_BUFSIZE]; 1791 1791 1792 1792 if (err == -ENOENT) { 1793 1793 const char *config; ··· 1817 1817 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " 1818 1818 "or/and CONFIG_UPROBE_EVENTS.\n"); 1819 1819 else { 1820 - char sbuf[128]; 1820 + char sbuf[STRERR_BUFSIZE]; 1821 1821 pr_warning("Failed to open kprobe events: %s.\n", 1822 1822 strerror_r(-kerr, sbuf, sizeof(sbuf))); 1823 1823 pr_warning("Failed to open uprobe events: %s.\n", ··· 2038 2038 { 2039 2039 int ret = 0; 2040 2040 char *buf = synthesize_probe_trace_command(tev); 2041 + char sbuf[STRERR_BUFSIZE]; 2041 2042 2042 2043 if (!buf) { 2043 2044 pr_debug("Failed to synthesize probe trace event.\n"); ··· 2050 2049 ret = write(fd, buf, strlen(buf)); 2051 2050 if (ret <= 0) 2052 2051 pr_warning("Failed to write event: %s\n", 2053 - strerror(errno)); 2052 + strerror_r(errno, sbuf, sizeof(sbuf))); 2054 2053 } 2055 2054 free(buf); 2056 2055 return ret; ··· 2064 2063 /* Try no suffix */ 2065 2064 ret = e_snprintf(buf, len, "%s", base); 2066 2065 if (ret < 0) { 2067 - pr_debug("snprintf() failed: %s\n", strerror(-ret)); 2066 + pr_debug("snprintf() failed: %d\n", ret); 2068 2067 return ret; 2069 2068 } 2070 2069 if (!strlist__has_entry(namelist, buf)) ··· 2080 2079 for (i = 1; i < MAX_EVENT_INDEX; i++) { 2081 2080 ret = e_snprintf(buf, len, "%s_%d", base, i); 2082 2081 if (ret < 0) { 2083 - pr_debug("snprintf() failed: %s\n", strerror(-ret)); 2082 + pr_debug("snprintf() failed: %d\n", ret); 2084 2083 return ret; 2085 2084 } 2086 2085 if (!strlist__has_entry(namelist, buf)) ··· 2445 2444 printf("Removed event: %s\n", ent->s); 2446 2445 return 0; 2447 2446 error: 2448 - pr_warning("Failed to delete event: %s\n", strerror(-ret)); 2447 + pr_warning("Failed to delete event: %s\n", 2448 + strerror_r(-ret, buf, sizeof(buf))); 2449 2449 return ret; 2450 2450 } 2451 2451
+5 -2
tools/perf/util/probe-finder.c
··· 281 281 struct probe_trace_arg_ref **ref_ptr = &tvar->ref; 282 282 Dwarf_Die type; 283 283 char buf[16]; 284 + char sbuf[STRERR_BUFSIZE]; 284 285 int bsize, boffs, total; 285 286 int ret; 286 287 ··· 368 367 if (ret >= 16) 369 368 ret = -E2BIG; 370 369 pr_warning("Failed to convert variable type: %s\n", 371 - strerror(-ret)); 370 + strerror_r(-ret, sbuf, sizeof(sbuf))); 372 371 return ret; 373 372 } 374 373 tvar->type = strdup(buf); ··· 780 779 size_t line_len; 781 780 ssize_t len; 782 781 int count = 0, linenum = 1; 782 + char sbuf[STRERR_BUFSIZE]; 783 783 784 784 fp = fopen(fname, "r"); 785 785 if (!fp) { 786 - pr_warning("Failed to open %s: %s\n", fname, strerror(errno)); 786 + pr_warning("Failed to open %s: %s\n", fname, 787 + strerror_r(errno, sbuf, sizeof(sbuf))); 787 788 return -errno; 788 789 } 789 790