Commit 5f03cba4 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo

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: default avatarMasami 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.novalocalSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b2348e1d
...@@ -290,8 +290,11 @@ static void cleanup_params(void) ...@@ -290,8 +290,11 @@ static void cleanup_params(void)
static void pr_err_with_code(const char *msg, int err) static void pr_err_with_code(const char *msg, int err)
{ {
char sbuf[STRERR_BUFSIZE];
pr_err("%s", msg); pr_err("%s", msg);
pr_debug(" Reason: %s (Code: %d)", strerror(-err), err); pr_debug(" Reason: %s (Code: %d)",
strerror_r(-err, sbuf, sizeof(sbuf)), err);
pr_err("\n"); pr_err("\n");
} }
......
...@@ -573,7 +573,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir, ...@@ -573,7 +573,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir,
static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
{ {
char buf[LINEBUF_SIZE]; char buf[LINEBUF_SIZE], sbuf[STRERR_BUFSIZE];
const char *color = show_num ? "" : PERF_COLOR_BLUE; const char *color = show_num ? "" : PERF_COLOR_BLUE;
const char *prefix = NULL; const char *prefix = NULL;
...@@ -593,7 +593,8 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) ...@@ -593,7 +593,8 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
return 1; return 1;
error: error:
if (ferror(fp)) { if (ferror(fp)) {
pr_warning("File read error: %s\n", strerror(errno)); pr_warning("File read error: %s\n",
strerror_r(errno, sbuf, sizeof(sbuf)));
return -1; return -1;
} }
return 0; return 0;
...@@ -626,6 +627,7 @@ static int __show_line_range(struct line_range *lr, const char *module) ...@@ -626,6 +627,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
FILE *fp; FILE *fp;
int ret; int ret;
char *tmp; char *tmp;
char sbuf[STRERR_BUFSIZE];
/* Search a line range */ /* Search a line range */
dinfo = open_debuginfo(module, false); dinfo = open_debuginfo(module, false);
...@@ -662,7 +664,7 @@ static int __show_line_range(struct line_range *lr, const char *module) ...@@ -662,7 +664,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
fp = fopen(lr->path, "r"); fp = fopen(lr->path, "r");
if (fp == NULL) { if (fp == NULL) {
pr_warning("Failed to open %s: %s\n", lr->path, pr_warning("Failed to open %s: %s\n", lr->path,
strerror(errno)); strerror_r(errno, sbuf, sizeof(sbuf)));
return -errno; return -errno;
} }
/* Skip to starting line number */ /* Skip to starting line number */
...@@ -1410,8 +1412,7 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) ...@@ -1410,8 +1412,7 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
return tmp - buf; return tmp - buf;
error: error:
pr_debug("Failed to synthesize perf probe argument: %s\n", pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
strerror(-ret));
return ret; return ret;
} }
...@@ -1460,8 +1461,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp) ...@@ -1460,8 +1461,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
return buf; return buf;
error: error:
pr_debug("Failed to synthesize perf probe point: %s\n", pr_debug("Failed to synthesize perf probe point: %d\n", ret);
strerror(-ret));
free(buf); free(buf);
return NULL; return NULL;
} }
...@@ -1787,7 +1787,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev) ...@@ -1787,7 +1787,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
static void print_open_warning(int err, bool is_kprobe) static void print_open_warning(int err, bool is_kprobe)
{ {
char sbuf[128]; char sbuf[STRERR_BUFSIZE];
if (err == -ENOENT) { if (err == -ENOENT) {
const char *config; const char *config;
...@@ -1817,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr) ...@@ -1817,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
"or/and CONFIG_UPROBE_EVENTS.\n"); "or/and CONFIG_UPROBE_EVENTS.\n");
else { else {
char sbuf[128]; char sbuf[STRERR_BUFSIZE];
pr_warning("Failed to open kprobe events: %s.\n", pr_warning("Failed to open kprobe events: %s.\n",
strerror_r(-kerr, sbuf, sizeof(sbuf))); strerror_r(-kerr, sbuf, sizeof(sbuf)));
pr_warning("Failed to open uprobe events: %s.\n", pr_warning("Failed to open uprobe events: %s.\n",
...@@ -2038,6 +2038,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev) ...@@ -2038,6 +2038,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
{ {
int ret = 0; int ret = 0;
char *buf = synthesize_probe_trace_command(tev); char *buf = synthesize_probe_trace_command(tev);
char sbuf[STRERR_BUFSIZE];
if (!buf) { if (!buf) {
pr_debug("Failed to synthesize probe trace event.\n"); pr_debug("Failed to synthesize probe trace event.\n");
...@@ -2049,7 +2050,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev) ...@@ -2049,7 +2050,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
ret = write(fd, buf, strlen(buf)); ret = write(fd, buf, strlen(buf));
if (ret <= 0) if (ret <= 0)
pr_warning("Failed to write event: %s\n", pr_warning("Failed to write event: %s\n",
strerror(errno)); strerror_r(errno, sbuf, sizeof(sbuf)));
} }
free(buf); free(buf);
return ret; return ret;
...@@ -2063,7 +2064,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base, ...@@ -2063,7 +2064,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
/* Try no suffix */ /* Try no suffix */
ret = e_snprintf(buf, len, "%s", base); ret = e_snprintf(buf, len, "%s", base);
if (ret < 0) { if (ret < 0) {
pr_debug("snprintf() failed: %s\n", strerror(-ret)); pr_debug("snprintf() failed: %d\n", ret);
return ret; return ret;
} }
if (!strlist__has_entry(namelist, buf)) if (!strlist__has_entry(namelist, buf))
...@@ -2079,7 +2080,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base, ...@@ -2079,7 +2080,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
for (i = 1; i < MAX_EVENT_INDEX; i++) { for (i = 1; i < MAX_EVENT_INDEX; i++) {
ret = e_snprintf(buf, len, "%s_%d", base, i); ret = e_snprintf(buf, len, "%s_%d", base, i);
if (ret < 0) { if (ret < 0) {
pr_debug("snprintf() failed: %s\n", strerror(-ret)); pr_debug("snprintf() failed: %d\n", ret);
return ret; return ret;
} }
if (!strlist__has_entry(namelist, buf)) if (!strlist__has_entry(namelist, buf))
...@@ -2444,7 +2445,8 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) ...@@ -2444,7 +2445,8 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
printf("Removed event: %s\n", ent->s); printf("Removed event: %s\n", ent->s);
return 0; return 0;
error: error:
pr_warning("Failed to delete event: %s\n", strerror(-ret)); pr_warning("Failed to delete event: %s\n",
strerror_r(-ret, buf, sizeof(buf)));
return ret; return ret;
} }
......
...@@ -281,6 +281,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, ...@@ -281,6 +281,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
struct probe_trace_arg_ref **ref_ptr = &tvar->ref; struct probe_trace_arg_ref **ref_ptr = &tvar->ref;
Dwarf_Die type; Dwarf_Die type;
char buf[16]; char buf[16];
char sbuf[STRERR_BUFSIZE];
int bsize, boffs, total; int bsize, boffs, total;
int ret; int ret;
...@@ -367,7 +368,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, ...@@ -367,7 +368,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
if (ret >= 16) if (ret >= 16)
ret = -E2BIG; ret = -E2BIG;
pr_warning("Failed to convert variable type: %s\n", pr_warning("Failed to convert variable type: %s\n",
strerror(-ret)); strerror_r(-ret, sbuf, sizeof(sbuf)));
return ret; return ret;
} }
tvar->type = strdup(buf); tvar->type = strdup(buf);
...@@ -779,10 +780,12 @@ static int find_lazy_match_lines(struct intlist *list, ...@@ -779,10 +780,12 @@ static int find_lazy_match_lines(struct intlist *list,
size_t line_len; size_t line_len;
ssize_t len; ssize_t len;
int count = 0, linenum = 1; int count = 0, linenum = 1;
char sbuf[STRERR_BUFSIZE];
fp = fopen(fname, "r"); fp = fopen(fname, "r");
if (!fp) { if (!fp) {
pr_warning("Failed to open %s: %s\n", fname, strerror(errno)); pr_warning("Failed to open %s: %s\n", fname,
strerror_r(errno, sbuf, sizeof(sbuf)));
return -errno; return -errno;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment