Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e81c74c authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo
Browse files

perf util: Replace strerror with strerror_r for thread-safety



Replaces all strerror with strerror_r in util for making the perf lib
thread-safe.

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/20140814022236.3545.3367.stgit@kbuild-fedora.novalocal


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5f03cba4
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@
#include "../perf.h"
#include "../perf.h"
#include "cloexec.h"
#include "cloexec.h"
#include "asm/bug.h"
#include "asm/bug.h"
#include "debug.h"


static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
static unsigned long flag = PERF_FLAG_FD_CLOEXEC;


@@ -18,6 +19,7 @@ static int perf_flag_probe(void)
	int err;
	int err;
	int cpu;
	int cpu;
	pid_t pid = -1;
	pid_t pid = -1;
	char sbuf[STRERR_BUFSIZE];


	cpu = sched_getcpu();
	cpu = sched_getcpu();
	if (cpu < 0)
	if (cpu < 0)
@@ -42,7 +44,7 @@ static int perf_flag_probe(void)


	WARN_ONCE(err != EINVAL && err != EBUSY,
	WARN_ONCE(err != EINVAL && err != EBUSY,
		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
		  "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 */
	/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
	fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
	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,
	if (WARN_ONCE(fd < 0 && err != EBUSY,
		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
		      err, strerror(err)))
		      err, strerror_r(err, sbuf, sizeof(sbuf))))
		return -1;
		return -1;


	close(fd);
	close(fd);
+6 −2
Original line number Original line Diff line number Diff line
@@ -50,12 +50,14 @@ static int open_file_read(struct perf_data_file *file)
{
{
	struct stat st;
	struct stat st;
	int fd;
	int fd;
	char sbuf[STRERR_BUFSIZE];


	fd = open(file->path, O_RDONLY);
	fd = open(file->path, O_RDONLY);
	if (fd < 0) {
	if (fd < 0) {
		int err = errno;
		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"))
		if (err == ENOENT && !strcmp(file->path, "perf.data"))
			pr_err("  (try 'perf record' first)");
			pr_err("  (try 'perf record' first)");
		pr_err("\n");
		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)
static int open_file_write(struct perf_data_file *file)
{
{
	int fd;
	int fd;
	char sbuf[STRERR_BUFSIZE];


	if (check_backup(file))
	if (check_backup(file))
		return -1;
		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);
	fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);


	if (fd < 0)
	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;
	return fd;
}
}
+6 −2
Original line number Original line Diff line number Diff line
@@ -162,13 +162,15 @@ static void close_first_dso(void);
static int do_open(char *name)
static int do_open(char *name)
{
{
	int fd;
	int fd;
	char sbuf[STRERR_BUFSIZE];


	do {
	do {
		fd = open(name, O_RDONLY);
		fd = open(name, O_RDONLY);
		if (fd >= 0)
		if (fd >= 0)
			return fd;
			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)
		if (!dso__data_open_cnt || errno != EMFILE)
			break;
			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)
static int data_file_size(struct dso *dso)
{
{
	struct stat st;
	struct stat st;
	char sbuf[STRERR_BUFSIZE];


	if (!dso->data.file_size) {
	if (!dso->data.file_size) {
		if (fstat(dso->data.fd, &st)) {
		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;
			return -1;
		}
		}
		dso->data.file_size = st.st_size;
		dso->data.file_size = st.st_size;
+1 −1
Original line number Original line Diff line number Diff line
@@ -1295,7 +1295,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused,
			       int err, char *buf, size_t size)
			       int err, char *buf, size_t size)
{
{
	int printed, value;
	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) {
	switch (err) {
	case EACCES:
	case EACCES:
+5 −2
Original line number Original line Diff line number Diff line
@@ -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 perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
			      int err, char *msg, size_t size)
			      int err, char *msg, size_t size)
{
{
	char sbuf[STRERR_BUFSIZE];

	switch (err) {
	switch (err) {
	case EPERM:
	case EPERM:
	case EACCES:
	case EACCES:
@@ -2075,5 +2077,6 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
	"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"
	"/bin/dmesg may provide additional information.\n"
	"No CONFIG_PERF_EVENTS=y kernel support configured?\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));
}
}
Loading