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

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: 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/20140814022236.3545.3367.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
6e81c74c 5f03cba4

+36 -14
+4 -2
tools/perf/util/cloexec.c
··· 3 3 #include "../perf.h" 4 4 #include "cloexec.h" 5 5 #include "asm/bug.h" 6 + #include "debug.h" 6 7 7 8 static unsigned long flag = PERF_FLAG_FD_CLOEXEC; 8 9 ··· 19 18 int err; 20 19 int cpu; 21 20 pid_t pid = -1; 21 + char sbuf[STRERR_BUFSIZE]; 22 22 23 23 cpu = sched_getcpu(); 24 24 if (cpu < 0) ··· 44 42 45 43 WARN_ONCE(err != EINVAL && err != EBUSY, 46 44 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", 47 - err, strerror(err)); 45 + err, strerror_r(err, sbuf, sizeof(sbuf))); 48 46 49 47 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */ 50 48 fd = sys_perf_event_open(&attr, pid, cpu, -1, 0); ··· 52 50 53 51 if (WARN_ONCE(fd < 0 && err != EBUSY, 54 52 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", 55 - err, strerror(err))) 53 + err, strerror_r(err, sbuf, sizeof(sbuf)))) 56 54 return -1; 57 55 58 56 close(fd);
+6 -2
tools/perf/util/data.c
··· 50 50 { 51 51 struct stat st; 52 52 int fd; 53 + char sbuf[STRERR_BUFSIZE]; 53 54 54 55 fd = open(file->path, O_RDONLY); 55 56 if (fd < 0) { 56 57 int err = errno; 57 58 58 - pr_err("failed to open %s: %s", file->path, strerror(err)); 59 + pr_err("failed to open %s: %s", file->path, 60 + strerror_r(err, sbuf, sizeof(sbuf))); 59 61 if (err == ENOENT && !strcmp(file->path, "perf.data")) 60 62 pr_err(" (try 'perf record' first)"); 61 63 pr_err("\n"); ··· 90 88 static int open_file_write(struct perf_data_file *file) 91 89 { 92 90 int fd; 91 + char sbuf[STRERR_BUFSIZE]; 93 92 94 93 if (check_backup(file)) 95 94 return -1; ··· 98 95 fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); 99 96 100 97 if (fd < 0) 101 - pr_err("failed to open %s : %s\n", file->path, strerror(errno)); 98 + pr_err("failed to open %s : %s\n", file->path, 99 + strerror_r(errno, sbuf, sizeof(sbuf))); 102 100 103 101 return fd; 104 102 }
+6 -2
tools/perf/util/dso.c
··· 162 162 static int do_open(char *name) 163 163 { 164 164 int fd; 165 + char sbuf[STRERR_BUFSIZE]; 165 166 166 167 do { 167 168 fd = open(name, O_RDONLY); 168 169 if (fd >= 0) 169 170 return fd; 170 171 171 - pr_debug("dso open failed, mmap: %s\n", strerror(errno)); 172 + pr_debug("dso open failed, mmap: %s\n", 173 + strerror_r(errno, sbuf, sizeof(sbuf))); 172 174 if (!dso__data_open_cnt || errno != EMFILE) 173 175 break; 174 176 ··· 532 530 static int data_file_size(struct dso *dso) 533 531 { 534 532 struct stat st; 533 + char sbuf[STRERR_BUFSIZE]; 535 534 536 535 if (!dso->data.file_size) { 537 536 if (fstat(dso->data.fd, &st)) { 538 - pr_err("dso mmap failed, fstat: %s\n", strerror(errno)); 537 + pr_err("dso mmap failed, fstat: %s\n", 538 + strerror_r(errno, sbuf, sizeof(sbuf))); 539 539 return -1; 540 540 } 541 541 dso->data.file_size = st.st_size;
+1 -1
tools/perf/util/evlist.c
··· 1295 1295 int err, char *buf, size_t size) 1296 1296 { 1297 1297 int printed, value; 1298 - char sbuf[128], *emsg = strerror_r(err, sbuf, sizeof(sbuf)); 1298 + char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf)); 1299 1299 1300 1300 switch (err) { 1301 1301 case EACCES:
+5 -2
tools/perf/util/evsel.c
··· 2027 2027 int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, 2028 2028 int err, char *msg, size_t size) 2029 2029 { 2030 + char sbuf[STRERR_BUFSIZE]; 2031 + 2030 2032 switch (err) { 2031 2033 case EPERM: 2032 2034 case EACCES: ··· 2074 2072 } 2075 2073 2076 2074 return scnprintf(msg, size, 2077 - "The sys_perf_event_open() syscall returned with %d (%s) for event (%s). \n" 2075 + "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n" 2078 2076 "/bin/dmesg may provide additional information.\n" 2079 2077 "No CONFIG_PERF_EVENTS=y kernel support configured?\n", 2080 - err, strerror(err), perf_evsel__name(evsel)); 2078 + err, strerror_r(err, sbuf, sizeof(sbuf)), 2079 + perf_evsel__name(evsel)); 2081 2080 }
+4 -1
tools/perf/util/parse-events.c
··· 10 10 #include "symbol.h" 11 11 #include "cache.h" 12 12 #include "header.h" 13 + #include "debug.h" 13 14 #include <api/fs/debugfs.h> 14 15 #include "parse-events-bison.h" 15 16 #define YY_EXTRA_TYPE int ··· 1007 1006 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 1008 1007 char evt_path[MAXPATHLEN]; 1009 1008 char dir_path[MAXPATHLEN]; 1009 + char sbuf[STRERR_BUFSIZE]; 1010 1010 1011 1011 if (debugfs_valid_mountpoint(tracing_events_path)) { 1012 - printf(" [ Tracepoints not available: %s ]\n", strerror(errno)); 1012 + printf(" [ Tracepoints not available: %s ]\n", 1013 + strerror_r(errno, sbuf, sizeof(sbuf))); 1013 1014 return; 1014 1015 } 1015 1016
+7 -2
tools/perf/util/run-command.c
··· 1 1 #include "cache.h" 2 2 #include "run-command.h" 3 3 #include "exec_cmd.h" 4 + #include "debug.h" 4 5 5 6 static inline void close_pair(int fd[2]) 6 7 { ··· 20 19 { 21 20 int need_in, need_out, need_err; 22 21 int fdin[2], fdout[2], fderr[2]; 22 + char sbuf[STRERR_BUFSIZE]; 23 23 24 24 /* 25 25 * In case of errors we must keep the promise to close FDs ··· 101 99 102 100 if (cmd->dir && chdir(cmd->dir)) 103 101 die("exec %s: cd to %s failed (%s)", cmd->argv[0], 104 - cmd->dir, strerror(errno)); 102 + cmd->dir, strerror_r(errno, sbuf, sizeof(sbuf))); 105 103 if (cmd->env) { 106 104 for (; *cmd->env; cmd->env++) { 107 105 if (strchr(*cmd->env, '=')) ··· 155 153 156 154 static int wait_or_whine(pid_t pid) 157 155 { 156 + char sbuf[STRERR_BUFSIZE]; 157 + 158 158 for (;;) { 159 159 int status, code; 160 160 pid_t waiting = waitpid(pid, &status, 0); ··· 164 160 if (waiting < 0) { 165 161 if (errno == EINTR) 166 162 continue; 167 - error("waitpid failed (%s)", strerror(errno)); 163 + error("waitpid failed (%s)", 164 + strerror_r(errno, sbuf, sizeof(sbuf))); 168 165 return -ERR_RUN_COMMAND_WAITPID; 169 166 } 170 167 if (waiting != pid)
+3 -2
tools/perf/util/util.c
··· 456 456 size_t size = 0, alloc_size = 0; 457 457 void *bf = NULL, *nbf; 458 458 int fd, n, err = 0; 459 + char sbuf[STRERR_BUFSIZE]; 459 460 460 461 fd = open(filename, O_RDONLY); 461 462 if (fd < 0) ··· 477 476 n = read(fd, bf + size, alloc_size - size); 478 477 if (n < 0) { 479 478 if (size) { 480 - pr_warning("read failed %d: %s\n", 481 - errno, strerror(errno)); 479 + pr_warning("read failed %d: %s\n", errno, 480 + strerror_r(errno, sbuf, sizeof(sbuf))); 482 481 err = 0; 483 482 } else 484 483 err = -errno;