* [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety
@ 2014-08-14 2:20 Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 1/8] perf probe: Don't use strerror if strlist__add failed Masami Hiramatsu
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Hi,
Here is a series to get rid of thread-unsafe strerror() from
perf tools. Of course, there maybe other thread-unsafe functions,
so this goes just one step forward. :)
This introduces STRERR_BUFSIZE(=128) macro for allocating local
buffer, but some strerror_r()s don't use that. If there are
already a local buffer on the stack, and if it is bigger than
STRERR_BUFSIZE, I chose it for strerror_r()'s buffer.
By the way, while doing this cleanup, I've found some confusions
on the code. Currently perf has 3 ways to output messages except
for standard (f)printf, pr_XXX, ui__XXX and warning/error functions.
Is there any differences among those APIs? What is the expected
use cases for them?
For example, a pure printf is in kvm_live_open_events@builtin-kvm.c
but it seems to be ui__error, because the error output next to it
uses that. However, other parts use pr_XXX too. It seems inconsistent.
Thank you,
---
Masami Hiramatsu (8):
perf probe: Don't use strerror if strlist__add failed
perf: Use strerror_r instead of strerror
perf probe: Make error messages thread-safe
perf/util: Replace strerror with strerror_r for thread-safety
perf top: Use strerror_r instead of strerror
perf trace: Use strerror_r instead of strerror
perf record: Use strerror_r instead of strerror
perf test: Use strerror_r instead of strerror
tools/perf/builtin-probe.c | 5 +++-
tools/perf/builtin-record.c | 7 +++---
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 6 +++--
tools/perf/perf.c | 10 ++++++---
tools/perf/tests/builtin-test.c | 4 +++
tools/perf/tests/mmap-basic.c | 7 +++---
tools/perf/tests/open-syscall-all-cpus.c | 5 +++-
tools/perf/tests/open-syscall-tp-fields.c | 7 ++++--
tools/perf/tests/open-syscall.c | 3 ++-
tools/perf/tests/perf-record.c | 13 ++++++++---
tools/perf/tests/rdpmc.c | 6 +++--
tools/perf/tests/sw-clock.c | 6 +++--
tools/perf/tests/task-exit.c | 6 +++--
tools/perf/util/cloexec.c | 6 +++--
tools/perf/util/data.c | 8 +++++--
tools/perf/util/debug.h | 3 +++
tools/perf/util/dso.c | 8 +++++--
tools/perf/util/evlist.c | 2 +-
tools/perf/util/evsel.c | 7 ++++--
tools/perf/util/parse-events.c | 5 +++-
tools/perf/util/probe-event.c | 34 ++++++++++++++++-------------
tools/perf/util/probe-finder.c | 7 ++++--
tools/perf/util/run-command.c | 9 ++++++--
tools/perf/util/util.c | 5 +++-
25 files changed, 121 insertions(+), 60 deletions(-)
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/8] perf probe: Don't use strerror if strlist__add failed
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 2/8] perf: Use strerror_r instead of strerror Masami Hiramatsu
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Since the strlist__add doesn't involves any IO, the failure
reason must be ENOMEM or EINVAL, moreover this is just a
debug message, we don't need to show the error string.
And also, if get_probe_trace_command_rawlist() returns NULL,
it doesn't mean the rawlist is empty, there is an error.
So caller must use -ENOMEM for the error.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/util/probe-event.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 784ea42..66799c6 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1876,7 +1876,7 @@ static struct strlist *get_probe_trace_command_rawlist(int fd)
p[idx] = '\0';
ret = strlist__add(sl, buf);
if (ret < 0) {
- pr_debug("strlist__add failed: %s\n", strerror(-ret));
+ pr_debug("strlist__add failed (%d)\n", ret);
strlist__delete(sl);
return NULL;
}
@@ -1935,7 +1935,7 @@ static int __show_perf_probe_events(int fd, bool is_kprobe)
rawlist = get_probe_trace_command_rawlist(fd);
if (!rawlist)
- return -ENOENT;
+ return -ENOMEM;
strlist__for_each(ent, rawlist) {
ret = parse_probe_trace_command(ent->s, &tev);
@@ -2002,6 +2002,8 @@ static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
memset(&tev, 0, sizeof(tev));
rawlist = get_probe_trace_command_rawlist(fd);
+ if (!rawlist)
+ return NULL;
sl = strlist__new(true, NULL);
strlist__for_each(ent, rawlist) {
ret = parse_probe_trace_command(ent->s, &tev);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/8] perf: Use strerror_r instead of strerror
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 1/8] perf probe: Don't use strerror if strlist__add failed Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 3/8] perf probe: Make error messages thread-safe Masami Hiramatsu
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
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>
---
tools/perf/perf.c | 10 +++++++---
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 2282d41..452a847 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)
int status;
struct stat st;
const char *prefix;
+ char sbuf[STRERR_BUFSIZE];
prefix = NULL;
if (p->option & RUN_SETUP)
@@ -343,7 +344,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
status = 1;
/* Check for ENOSPC and EIO errors.. */
if (fflush(stdout)) {
- fprintf(stderr, "write failure on standard output: %s", strerror(errno));
+ fprintf(stderr, "write failure on standard output: %s",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out;
}
if (ferror(stdout)) {
@@ -351,7 +353,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
goto out;
}
if (fclose(stdout)) {
- fprintf(stderr, "close failed on standard output: %s", strerror(errno));
+ fprintf(stderr, "close failed on standard output: %s",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out;
}
status = 0;
@@ -466,6 +469,7 @@ void pthread__unblock_sigwinch(void)
int main(int argc, const char **argv)
{
const char *cmd;
+ char sbuf[STRERR_BUFSIZE];
/* The page_size is placed in util object. */
page_size = sysconf(_SC_PAGE_SIZE);
@@ -561,7 +565,7 @@ int main(int argc, const char **argv)
}
fprintf(stderr, "Failed to run command '%s': %s\n",
- cmd, strerror(errno));
+ cmd, strerror_r(errno, sbuf, sizeof(sbuf)));
out:
return 1;
}
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 6944ea3..be264d6 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -3,6 +3,7 @@
#define __PERF_DEBUG_H
#include <stdbool.h>
+#include <string.h>
#include "event.h"
#include "../ui/helpline.h"
#include "../ui/progress.h"
@@ -36,6 +37,8 @@ extern int debug_ordered_events;
#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
+#define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */
+
int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
void trace_event(union perf_event *event);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/8] perf probe: Make error messages thread-safe
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 1/8] perf probe: Don't use strerror if strlist__add failed Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 2/8] perf: Use strerror_r instead of strerror Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 4/8] perf/util: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
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>
---
tools/perf/builtin-probe.c | 5 ++++-
tools/perf/util/probe-event.c | 28 +++++++++++++++-------------
tools/perf/util/probe-finder.c | 7 +++++--
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index c63fa29..347729e 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -290,8 +290,11 @@ static void cleanup_params(void)
static void pr_err_with_code(const char *msg, int err)
{
+ char sbuf[STRERR_BUFSIZE];
+
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");
}
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 66799c6..e685ef4 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -565,7 +565,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)
{
- char buf[LINEBUF_SIZE];
+ char buf[LINEBUF_SIZE], sbuf[STRERR_BUFSIZE];
const char *color = show_num ? "" : PERF_COLOR_BLUE;
const char *prefix = NULL;
@@ -585,7 +585,8 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
return 1;
error:
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 0;
@@ -618,6 +619,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
FILE *fp;
int ret;
char *tmp;
+ char sbuf[STRERR_BUFSIZE];
/* Search a line range */
dinfo = open_debuginfo(module);
@@ -656,7 +658,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
fp = fopen(lr->path, "r");
if (fp == NULL) {
pr_warning("Failed to open %s: %s\n", lr->path,
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return -errno;
}
/* Skip to starting line number */
@@ -1405,8 +1407,7 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
return tmp - buf;
error:
- pr_debug("Failed to synthesize perf probe argument: %s\n",
- strerror(-ret));
+ pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
return ret;
}
@@ -1455,8 +1456,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
return buf;
error:
- pr_debug("Failed to synthesize perf probe point: %s\n",
- strerror(-ret));
+ pr_debug("Failed to synthesize perf probe point: %d\n", ret);
free(buf);
return NULL;
}
@@ -1782,7 +1782,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
static void print_open_warning(int err, bool is_kprobe)
{
- char sbuf[128];
+ char sbuf[STRERR_BUFSIZE];
if (err == -ENOENT) {
const char *config;
@@ -1812,7 +1812,7 @@ static void print_both_open_warning(int kerr, int uerr)
pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
"or/and CONFIG_UPROBE_EVENTS.\n");
else {
- char sbuf[128];
+ char sbuf[STRERR_BUFSIZE];
pr_warning("Failed to open kprobe events: %s.\n",
strerror_r(-kerr, sbuf, sizeof(sbuf)));
pr_warning("Failed to open uprobe events: %s.\n",
@@ -2033,6 +2033,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
{
int ret = 0;
char *buf = synthesize_probe_trace_command(tev);
+ char sbuf[STRERR_BUFSIZE];
if (!buf) {
pr_debug("Failed to synthesize probe trace event.\n");
@@ -2044,7 +2045,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
ret = write(fd, buf, strlen(buf));
if (ret <= 0)
pr_warning("Failed to write event: %s\n",
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
}
free(buf);
return ret;
@@ -2058,7 +2059,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
/* Try no suffix */
ret = e_snprintf(buf, len, "%s", base);
if (ret < 0) {
- pr_debug("snprintf() failed: %s\n", strerror(-ret));
+ pr_debug("snprintf() failed: %d\n", ret);
return ret;
}
if (!strlist__has_entry(namelist, buf))
@@ -2074,7 +2075,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
for (i = 1; i < MAX_EVENT_INDEX; i++) {
ret = e_snprintf(buf, len, "%s_%d", base, i);
if (ret < 0) {
- pr_debug("snprintf() failed: %s\n", strerror(-ret));
+ pr_debug("snprintf() failed: %d\n", ret);
return ret;
}
if (!strlist__has_entry(namelist, buf))
@@ -2439,7 +2440,8 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
printf("Removed event: %s\n", ent->s);
return 0;
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;
}
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index dca9145..9c59356 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -281,6 +281,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
struct probe_trace_arg_ref **ref_ptr = &tvar->ref;
Dwarf_Die type;
char buf[16];
+ char sbuf[STRERR_BUFSIZE];
int bsize, boffs, total;
int ret;
@@ -367,7 +368,7 @@ formatted:
if (ret >= 16)
ret = -E2BIG;
pr_warning("Failed to convert variable type: %s\n",
- strerror(-ret));
+ strerror_r(-ret, sbuf, sizeof(sbuf)));
return ret;
}
tvar->type = strdup(buf);
@@ -779,10 +780,12 @@ static int find_lazy_match_lines(struct intlist *list,
size_t line_len;
ssize_t len;
int count = 0, linenum = 1;
+ char sbuf[STRERR_BUFSIZE];
fp = fopen(fname, "r");
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;
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/8] perf/util: Replace strerror with strerror_r for thread-safety
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (2 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 3/8] perf probe: Make error messages thread-safe Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 5/8] perf top: Use strerror_r instead of strerror Masami Hiramatsu
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Replaces all strerror with strerror_r in util for making
the perf lib thread-safe.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/util/cloexec.c | 6 ++++--
tools/perf/util/data.c | 8 ++++++--
tools/perf/util/dso.c | 8 ++++++--
tools/perf/util/evlist.c | 2 +-
tools/perf/util/evsel.c | 7 +++++--
tools/perf/util/parse-events.c | 5 ++++-
tools/perf/util/run-command.c | 9 +++++++--
tools/perf/util/util.c | 5 +++--
8 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 4945aa5..47b78b3 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -3,6 +3,7 @@
#include "../perf.h"
#include "cloexec.h"
#include "asm/bug.h"
+#include "debug.h"
static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
@@ -18,6 +19,7 @@ static int perf_flag_probe(void)
int err;
int cpu;
pid_t pid = -1;
+ char sbuf[STRERR_BUFSIZE];
cpu = sched_getcpu();
if (cpu < 0)
@@ -42,7 +44,7 @@ static int perf_flag_probe(void)
WARN_ONCE(err != EINVAL && err != EBUSY,
"perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
- err, strerror(err));
+ err, strerror_r(err, sbuf, sizeof(sbuf)));
/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
@@ -50,7 +52,7 @@ static int perf_flag_probe(void)
if (WARN_ONCE(fd < 0 && err != EBUSY,
"perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
- err, strerror(err)))
+ err, strerror_r(err, sbuf, sizeof(sbuf))))
return -1;
close(fd);
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 29d720c..1921942f 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -50,12 +50,14 @@ static int open_file_read(struct perf_data_file *file)
{
struct stat st;
int fd;
+ char sbuf[STRERR_BUFSIZE];
fd = open(file->path, O_RDONLY);
if (fd < 0) {
int err = errno;
- pr_err("failed to open %s: %s", file->path, strerror(err));
+ pr_err("failed to open %s: %s", file->path,
+ strerror_r(err, sbuf, sizeof(sbuf)));
if (err == ENOENT && !strcmp(file->path, "perf.data"))
pr_err(" (try 'perf record' first)");
pr_err("\n");
@@ -88,6 +90,7 @@ static int open_file_read(struct perf_data_file *file)
static int open_file_write(struct perf_data_file *file)
{
int fd;
+ char sbuf[STRERR_BUFSIZE];
if (check_backup(file))
return -1;
@@ -95,7 +98,8 @@ static int open_file_write(struct perf_data_file *file)
fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0)
- pr_err("failed to open %s : %s\n", file->path, strerror(errno));
+ pr_err("failed to open %s : %s\n", file->path,
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return fd;
}
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index bdafd30..55e39dc 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -162,13 +162,15 @@ static void close_first_dso(void);
static int do_open(char *name)
{
int fd;
+ char sbuf[STRERR_BUFSIZE];
do {
fd = open(name, O_RDONLY);
if (fd >= 0)
return fd;
- pr_debug("dso open failed, mmap: %s\n", strerror(errno));
+ pr_debug("dso open failed, mmap: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
if (!dso__data_open_cnt || errno != EMFILE)
break;
@@ -530,10 +532,12 @@ static ssize_t cached_read(struct dso *dso, u64 offset, u8 *data, ssize_t size)
static int data_file_size(struct dso *dso)
{
struct stat st;
+ char sbuf[STRERR_BUFSIZE];
if (!dso->data.file_size) {
if (fstat(dso->data.fd, &st)) {
- pr_err("dso mmap failed, fstat: %s\n", strerror(errno));
+ pr_err("dso mmap failed, fstat: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return -1;
}
dso->data.file_size = st.st_size;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 5dcd28c..a3e28b4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1295,7 +1295,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused,
int err, char *buf, size_t size)
{
int printed, value;
- char sbuf[128], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
+ char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
switch (err) {
case EACCES:
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 01ce14c..b38de58 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2027,6 +2027,8 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
int err, char *msg, size_t size)
{
+ char sbuf[STRERR_BUFSIZE];
+
switch (err) {
case EPERM:
case EACCES:
@@ -2072,8 +2074,9 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
}
return scnprintf(msg, size,
- "The sys_perf_event_open() syscall returned with %d (%s) for event (%s). \n"
+ "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
"/bin/dmesg may provide additional information.\n"
"No CONFIG_PERF_EVENTS=y kernel support configured?\n",
- err, strerror(err), perf_evsel__name(evsel));
+ err, strerror_r(err, sbuf, sizeof(sbuf)),
+ perf_evsel__name(evsel));
}
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 1e15df1..e34c81a 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -10,6 +10,7 @@
#include "symbol.h"
#include "cache.h"
#include "header.h"
+#include "debug.h"
#include <api/fs/debugfs.h>
#include "parse-events-bison.h"
#define YY_EXTRA_TYPE int
@@ -1006,9 +1007,11 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];
+ char sbuf[STRERR_BUFSIZE];
if (debugfs_valid_mountpoint(tracing_events_path)) {
- printf(" [ Tracepoints not available: %s ]\n", strerror(errno));
+ printf(" [ Tracepoints not available: %s ]\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return;
}
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
index da8e9b2..34622b5 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "run-command.h"
#include "exec_cmd.h"
+#include "debug.h"
static inline void close_pair(int fd[2])
{
@@ -19,6 +20,7 @@ int start_command(struct child_process *cmd)
{
int need_in, need_out, need_err;
int fdin[2], fdout[2], fderr[2];
+ char sbuf[STRERR_BUFSIZE];
/*
* In case of errors we must keep the promise to close FDs
@@ -99,7 +101,7 @@ int start_command(struct child_process *cmd)
if (cmd->dir && chdir(cmd->dir))
die("exec %s: cd to %s failed (%s)", cmd->argv[0],
- cmd->dir, strerror(errno));
+ cmd->dir, strerror_r(errno, sbuf, sizeof(sbuf)));
if (cmd->env) {
for (; *cmd->env; cmd->env++) {
if (strchr(*cmd->env, '='))
@@ -153,6 +155,8 @@ int start_command(struct child_process *cmd)
static int wait_or_whine(pid_t pid)
{
+ char sbuf[STRERR_BUFSIZE];
+
for (;;) {
int status, code;
pid_t waiting = waitpid(pid, &status, 0);
@@ -160,7 +164,8 @@ static int wait_or_whine(pid_t pid)
if (waiting < 0) {
if (errno == EINTR)
continue;
- error("waitpid failed (%s)", strerror(errno));
+ error("waitpid failed (%s)",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return -ERR_RUN_COMMAND_WAITPID;
}
if (waiting != pid)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 25822bd..24e8d87 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -456,6 +456,7 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
size_t size = 0, alloc_size = 0;
void *bf = NULL, *nbf;
int fd, n, err = 0;
+ char sbuf[STRERR_BUFSIZE];
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -476,8 +477,8 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
n = read(fd, bf + size, alloc_size - size);
if (n < 0) {
if (size) {
- pr_warning("read failed %d: %s\n",
- errno, strerror(errno));
+ pr_warning("read failed %d: %s\n", errno,
+ strerror_r(errno, sbuf, sizeof(sbuf)));
err = 0;
} else
err = -errno;
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/8] perf top: Use strerror_r instead of strerror
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (3 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 4/8] perf/util: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 6/8] perf trace: " Masami Hiramatsu
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Use strerror_r instead of strerror in error message
for thread-safety.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/builtin-top.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 87a6615..a77ff6c 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -899,7 +899,7 @@ try_again:
if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
ui__error("Failed to mmap with %d (%s)\n",
- errno, strerror(errno));
+ errno, strerror_r(errno, msg, sizeof(msg)));
goto out_err;
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/8] perf trace: Use strerror_r instead of strerror
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (4 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 5/8] perf top: Use strerror_r instead of strerror Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 7/8] perf record: " Masami Hiramatsu
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Use strerror_r instead of strerror in error message
for thead-safety.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/builtin-trace.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d080b9c..a9e96ff 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1750,7 +1750,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
signed_print:
fprintf(trace->output, ") = %d", ret);
} else if (ret < 0 && sc->fmt->errmsg) {
- char bf[256];
+ char bf[STRERR_BUFSIZE];
const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
*e = audit_errno_to_name(-ret);
@@ -2044,6 +2044,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
int err = -1, i;
unsigned long before;
const bool forks = argc > 0;
+ char sbuf[STRERR_BUFSIZE];
trace->live = true;
@@ -2105,7 +2106,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
if (err < 0) {
- fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
+ fprintf(trace->output, "Couldn't mmap the events: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/8] perf record: Use strerror_r instead of strerror
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (5 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 6/8] perf trace: " Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 8/8] perf test: " Masami Hiramatsu
2014-08-14 2:23 ` (ltc-kernel 9923) [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Use strerror_r instead of strerror in error messages
for thread-safety.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/builtin-record.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4db670d..87e28a4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -161,7 +161,7 @@ try_again:
if (perf_evlist__apply_filters(evlist)) {
error("failed to set filter with %d (%s)\n", errno,
- strerror(errno));
+ strerror_r(errno, msg, sizeof(msg)));
rc = -1;
goto out;
}
@@ -175,7 +175,8 @@ try_again:
"(current value: %u)\n", opts->mmap_pages);
rc = -errno;
} else {
- pr_err("failed to mmap with %d (%s)\n", errno, strerror(errno));
+ pr_err("failed to mmap with %d (%s)\n", errno,
+ strerror_r(errno, msg, sizeof(msg)));
rc = -errno;
}
goto out;
@@ -480,7 +481,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
if (forks && workload_exec_errno) {
- char msg[512];
+ char msg[STRERR_BUFSIZE];
const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
pr_err("Workload failed: %s\n", emsg);
err = -1;
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/8] perf test: Use strerror_r instead of strerror
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (6 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 7/8] perf record: " Masami Hiramatsu
@ 2014-08-14 2:20 ` Masami Hiramatsu
2014-08-14 2:23 ` (ltc-kernel 9923) [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Use strerror_r instead of strerror in error messages
for thread-safety.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/tests/builtin-test.c | 4 +++-
tools/perf/tests/mmap-basic.c | 7 ++++---
tools/perf/tests/open-syscall-all-cpus.c | 5 +++--
tools/perf/tests/open-syscall-tp-fields.c | 7 +++++--
tools/perf/tests/open-syscall.c | 3 ++-
tools/perf/tests/perf-record.c | 13 +++++++++----
tools/perf/tests/rdpmc.c | 6 ++++--
tools/perf/tests/sw-clock.c | 6 ++++--
tools/perf/tests/task-exit.c | 6 ++++--
9 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index c6796d2..9948136 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -185,9 +185,11 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
static int run_test(struct test *test)
{
int status, err = -1, child = fork();
+ char sbuf[STRERR_BUFSIZE];
if (child < 0) {
- pr_err("failed to fork test: %s\n", strerror(errno));
+ pr_err("failed to fork test: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return -1;
}
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 1422634..9b9622a 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -31,6 +31,7 @@ int test__basic_mmap(void)
unsigned int nr_events[nsyscalls],
expected_nr_events[nsyscalls], i, j;
struct perf_evsel *evsels[nsyscalls], *evsel;
+ char sbuf[STRERR_BUFSIZE];
threads = thread_map__new(-1, getpid(), UINT_MAX);
if (threads == NULL) {
@@ -49,7 +50,7 @@ int test__basic_mmap(void)
sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
- cpus->map[0], strerror(errno));
+ cpus->map[0], strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_free_cpus;
}
@@ -79,7 +80,7 @@ int test__basic_mmap(void)
if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
@@ -89,7 +90,7 @@ int test__basic_mmap(void)
if (perf_evlist__mmap(evlist, 128, true) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno,
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
index 5fecdbd..8fa82d1 100644
--- a/tools/perf/tests/open-syscall-all-cpus.c
+++ b/tools/perf/tests/open-syscall-all-cpus.c
@@ -12,6 +12,7 @@ int test__open_syscall_event_on_all_cpus(void)
unsigned int nr_open_calls = 111, i;
cpu_set_t cpu_set;
struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
+ char sbuf[STRERR_BUFSIZE];
if (threads == NULL) {
pr_debug("thread_map__new\n");
@@ -35,7 +36,7 @@ int test__open_syscall_event_on_all_cpus(void)
if (perf_evsel__open(evsel, cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_evsel_delete;
}
@@ -56,7 +57,7 @@ int test__open_syscall_event_on_all_cpus(void)
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
cpus->map[cpu],
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_close_fd;
}
for (i = 0; i < ncalls; ++i) {
diff --git a/tools/perf/tests/open-syscall-tp-fields.c b/tools/perf/tests/open-syscall-tp-fields.c
index 0785b64..922bdb6 100644
--- a/tools/perf/tests/open-syscall-tp-fields.c
+++ b/tools/perf/tests/open-syscall-tp-fields.c
@@ -22,6 +22,7 @@ int test__syscall_open_tp_fields(void)
struct perf_evlist *evlist = perf_evlist__new();
struct perf_evsel *evsel;
int err = -1, i, nr_events = 0, nr_polls = 0;
+ char sbuf[STRERR_BUFSIZE];
if (evlist == NULL) {
pr_debug("%s: perf_evlist__new\n", __func__);
@@ -48,13 +49,15 @@ int test__syscall_open_tp_fields(void)
err = perf_evlist__open(evlist);
if (err < 0) {
- pr_debug("perf_evlist__open: %s\n", strerror(errno));
+ pr_debug("perf_evlist__open: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
err = perf_evlist__mmap(evlist, UINT_MAX, false);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
+ pr_debug("perf_evlist__mmap: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c
index c1dc7d2..a33b2da 100644
--- a/tools/perf/tests/open-syscall.c
+++ b/tools/perf/tests/open-syscall.c
@@ -9,6 +9,7 @@ int test__open_syscall_event(void)
struct perf_evsel *evsel;
unsigned int nr_open_calls = 111, i;
struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
+ char sbuf[STRERR_BUFSIZE];
if (threads == NULL) {
pr_debug("thread_map__new\n");
@@ -24,7 +25,7 @@ int test__open_syscall_event(void)
if (perf_evsel__open_per_thread(evsel, threads) < 0) {
pr_debug("failed to open counter: %s, "
"tweak /proc/sys/kernel/perf_event_paranoid?\n",
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_evsel_delete;
}
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index aca1a83..2ce753c 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -59,6 +59,7 @@ int test__PERF_RECORD(void)
int err = -1, errs = 0, i, wakeups = 0;
u32 cpu;
int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
+ char sbuf[STRERR_BUFSIZE];
if (evlist == NULL || argv == NULL) {
pr_debug("Not enough memory to create evlist\n");
@@ -100,7 +101,8 @@ int test__PERF_RECORD(void)
err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
if (err < 0) {
- pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
+ pr_debug("sched__get_first_possible_cpu: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
@@ -110,7 +112,8 @@ int test__PERF_RECORD(void)
* So that we can check perf_sample.cpu on all the samples.
*/
if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
- pr_debug("sched_setaffinity: %s\n", strerror(errno));
+ pr_debug("sched_setaffinity: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
@@ -120,7 +123,8 @@ int test__PERF_RECORD(void)
*/
err = perf_evlist__open(evlist);
if (err < 0) {
- pr_debug("perf_evlist__open: %s\n", strerror(errno));
+ pr_debug("perf_evlist__open: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
@@ -131,7 +135,8 @@ int test__PERF_RECORD(void)
*/
err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
+ pr_debug("perf_evlist__mmap: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/rdpmc.c b/tools/perf/tests/rdpmc.c
index c04d1f2..d31f2c4 100644
--- a/tools/perf/tests/rdpmc.c
+++ b/tools/perf/tests/rdpmc.c
@@ -100,6 +100,7 @@ static int __test__rdpmc(void)
};
u64 delta_sum = 0;
struct sigaction sa;
+ char sbuf[STRERR_BUFSIZE];
sigfillset(&sa.sa_mask);
sa.sa_sigaction = segfault_handler;
@@ -109,14 +110,15 @@ static int __test__rdpmc(void)
perf_event_open_cloexec_flag());
if (fd < 0) {
pr_err("Error: sys_perf_event_open() syscall returned "
- "with %d (%s)\n", fd, strerror(errno));
+ "with %d (%s)\n", fd,
+ strerror_r(errno, sbuf, sizeof(sbuf)));
return -1;
}
addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
if (addr == (void *)(-1)) {
pr_err("Error: mmap() syscall returned with (%s)\n",
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_close;
}
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 983d6b8..1aa21c9 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -22,6 +22,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
volatile int tmp = 0;
u64 total_periods = 0;
int nr_samples = 0;
+ char sbuf[STRERR_BUFSIZE];
union perf_event *event;
struct perf_evsel *evsel;
struct perf_evlist *evlist;
@@ -62,14 +63,15 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
err = -errno;
pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",
- strerror(errno), knob, (u64)attr.sample_freq);
+ strerror_r(errno, sbuf, sizeof(sbuf)),
+ knob, (u64)attr.sample_freq);
goto out_delete_evlist;
}
err = perf_evlist__mmap(evlist, 128, true);
if (err < 0) {
pr_debug("failed to mmap event: %d (%s)\n", errno,
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 5ff3db3..87522f0 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -42,6 +42,7 @@ int test__task_exit(void)
.uses_mmap = true,
};
const char *argv[] = { "true", NULL };
+ char sbuf[STRERR_BUFSIZE];
signal(SIGCHLD, sig_handler);
@@ -82,13 +83,14 @@ int test__task_exit(void)
err = perf_evlist__open(evlist);
if (err < 0) {
- pr_debug("Couldn't open the evlist: %s\n", strerror(-err));
+ pr_debug("Couldn't open the evlist: %s\n",
+ strerror_r(-err, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
if (perf_evlist__mmap(evlist, 128, true) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno,
- strerror(errno));
+ strerror_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: (ltc-kernel 9923) [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
` (7 preceding siblings ...)
2014-08-14 2:20 ` [PATCH 8/8] perf test: " Masami Hiramatsu
@ 2014-08-14 2:23 ` Masami Hiramatsu
8 siblings, 0 replies; 10+ messages in thread
From: Masami Hiramatsu @ 2014-08-14 2:23 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, LKML, Ingo Molnar, Paul Mackerras,
Namhyung Kim
Oops, this is not a complete series... I'll resend same series.
(2014/08/14 11:20), Masami Hiramatsu wrote:
> Hi,
>
> Here is a series to get rid of thread-unsafe strerror() from
> perf tools. Of course, there maybe other thread-unsafe functions,
> so this goes just one step forward. :)
>
> This introduces STRERR_BUFSIZE(=128) macro for allocating local
> buffer, but some strerror_r()s don't use that. If there are
> already a local buffer on the stack, and if it is bigger than
> STRERR_BUFSIZE, I chose it for strerror_r()'s buffer.
>
> By the way, while doing this cleanup, I've found some confusions
> on the code. Currently perf has 3 ways to output messages except
> for standard (f)printf, pr_XXX, ui__XXX and warning/error functions.
> Is there any differences among those APIs? What is the expected
> use cases for them?
> For example, a pure printf is in kvm_live_open_events@builtin-kvm.c
> but it seems to be ui__error, because the error output next to it
> uses that. However, other parts use pr_XXX too. It seems inconsistent.
>
> Thank you,
>
> ---
>
> Masami Hiramatsu (8):
> perf probe: Don't use strerror if strlist__add failed
> perf: Use strerror_r instead of strerror
> perf probe: Make error messages thread-safe
> perf/util: Replace strerror with strerror_r for thread-safety
> perf top: Use strerror_r instead of strerror
> perf trace: Use strerror_r instead of strerror
> perf record: Use strerror_r instead of strerror
> perf test: Use strerror_r instead of strerror
>
>
> tools/perf/builtin-probe.c | 5 +++-
> tools/perf/builtin-record.c | 7 +++---
> tools/perf/builtin-top.c | 2 +-
> tools/perf/builtin-trace.c | 6 +++--
> tools/perf/perf.c | 10 ++++++---
> tools/perf/tests/builtin-test.c | 4 +++
> tools/perf/tests/mmap-basic.c | 7 +++---
> tools/perf/tests/open-syscall-all-cpus.c | 5 +++-
> tools/perf/tests/open-syscall-tp-fields.c | 7 ++++--
> tools/perf/tests/open-syscall.c | 3 ++-
> tools/perf/tests/perf-record.c | 13 ++++++++---
> tools/perf/tests/rdpmc.c | 6 +++--
> tools/perf/tests/sw-clock.c | 6 +++--
> tools/perf/tests/task-exit.c | 6 +++--
> tools/perf/util/cloexec.c | 6 +++--
> tools/perf/util/data.c | 8 +++++--
> tools/perf/util/debug.h | 3 +++
> tools/perf/util/dso.c | 8 +++++--
> tools/perf/util/evlist.c | 2 +-
> tools/perf/util/evsel.c | 7 ++++--
> tools/perf/util/parse-events.c | 5 +++-
> tools/perf/util/probe-event.c | 34 ++++++++++++++++-------------
> tools/perf/util/probe-finder.c | 7 ++++--
> tools/perf/util/run-command.c | 9 ++++++--
> tools/perf/util/util.c | 5 +++-
> 25 files changed, 121 insertions(+), 60 deletions(-)
>
> --
> Masami HIRAMATSU
> Software Platform Research Dept. Linux Technology Research Center
> Hitachi, Ltd., Yokohama Research Laboratory
> E-mail: masami.hiramatsu.pt@hitachi.com
>
>
--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-08-14 2:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-14 2:20 [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 1/8] perf probe: Don't use strerror if strlist__add failed Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 2/8] perf: Use strerror_r instead of strerror Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 3/8] perf probe: Make error messages thread-safe Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 4/8] perf/util: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 5/8] perf top: Use strerror_r instead of strerror Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 6/8] perf trace: " Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 7/8] perf record: " Masami Hiramatsu
2014-08-14 2:20 ` [PATCH 8/8] perf test: " Masami Hiramatsu
2014-08-14 2:23 ` (ltc-kernel 9923) [PATCH 0/8] perf: Replace strerror with strerror_r for thread-safety Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox