History

tools: Introduce str_error_r()

The tools so far have been using the strerror_r() GNU variant, that returns a string, be it the buffer passed or something else. But that, besides being tricky in cases where we expect that the function using strerror_r() returns the error formatted in a provided buffer (we have to check if it returned something else and copy that instead), breaks the build on systems not using glibc, like Alpine Linux, where musl libc is used. So, introduce yet another wrapper, str_error_r(), that has the GNU interface, but uses the portable XSI variant of strerror_r(), so that users rest asured that the provided buffer is used and it is what is returned.

Arnaldo Carvalho de Melo committed 10 years ago

Commit c8b5f2c1 parent ffe3a2841 files · +113 −77Browse files

Unified · Split

41 files
  1. tools/include/linux/string.h +2 −0
  2. tools/lib/str_error_r.c +26 −0
  3. tools/perf/MANIFEST +1 −0
  4. tools/perf/arch/x86/tests/rdpmc.c +2 −2
  5. tools/perf/builtin-buildid-cache.c +4 −4
  6. tools/perf/builtin-help.c +4 −4
  7. tools/perf/builtin-kvm.c +2 −2
  8. tools/perf/builtin-probe.c +1 −1
  9. tools/perf/builtin-record.c +3 −3
  10. tools/perf/builtin-sched.c +1 −1
  11. tools/perf/builtin-stat.c +2 −2
  12. tools/perf/builtin-top.c +3 −3
  13. tools/perf/builtin-trace.c +2 −2
  14. tools/perf/perf.c +3 −3
  15. tools/perf/tests/backward-ring-buffer.c +2 −2
  16. tools/perf/tests/bpf.c +2 −2
  17. tools/perf/tests/builtin-test.c +1 −1
  18. tools/perf/tests/event-times.c +1 −1
  19. tools/perf/tests/mmap-basic.c +3 −3
  20. tools/perf/tests/openat-syscall-all-cpus.c +2 −2
  21. tools/perf/tests/openat-syscall-tp-fields.c +2 −2
  22. tools/perf/tests/openat-syscall.c +1 −1
  23. tools/perf/tests/perf-record.c +4 −4
  24. tools/perf/tests/sw-clock.c +2 −2
  25. tools/perf/tests/task-exit.c +2 −2
  26. tools/perf/ui/browsers/hists.c +1 −1
  27. tools/perf/util/Build +5 −0
  28. tools/perf/util/bpf-loader.c +1 −1
  29. tools/perf/util/cloexec.c +2 −2
  30. tools/perf/util/data.c +2 −2
  31. tools/perf/util/debug.h +1 −1
  32. tools/perf/util/dso.c +3 −3
  33. tools/perf/util/evlist.c +2 −2
  34. tools/perf/util/evsel.c +1 −1
  35. tools/perf/util/llvm-utils.c +4 −4
  36. tools/perf/util/probe-event.c +3 −3
  37. tools/perf/util/probe-file.c +5 −5
  38. tools/perf/util/probe-finder.c +2 −2
  39. tools/perf/util/python-ext-sources +1 −0
  40. tools/perf/util/target.c +1 −1
  41. tools/perf/util/util.h +1 −0
tools/include/linux/string.h+2−0
@@ -12,4 +12,6 @@ int strtobool(const char *s, bool *res); · 11 unmodified lines
1212 extern size_t strlcpy(char *dest, const char *src, size_t size);
1313 #endif
1414
15+char *str_error_r(int errnum, char *buf, size_t buflen);
16+
1517 #endif /* _LINUX_STRING_H_ */
tools/lib/str_error_r.c+26−0
@@ -0,0 +1,26 @@
1+#undef _GNU_SOURCE
2+#include <string.h>
3+#include <stdio.h>
4+#include <linux/string.h>
5+
6+/*
7+ * The tools so far have been using the strerror_r() GNU variant, that returns
8+ * a string, be it the buffer passed or something else.
9+ *
10+ * But that, besides being tricky in cases where we expect that the function
11+ * using strerror_r() returns the error formatted in a provided buffer (we have
12+ * to check if it returned something else and copy that instead), breaks the
13+ * build on systems not using glibc, like Alpine Linux, where musl libc is
14+ * used.
15+ *
16+ * So, introduce yet another wrapper, str_error_r(), that has the GNU
17+ * interface, but uses the portable XSI variant of strerror_r(), so that users
18+ * rest asured that the provided buffer is used and it is what is returned.
19+ */
20+char *str_error_r(int errnum, char *buf, size_t buflen)
21+{
22+ int err = strerror_r(errnum, buf, buflen);
23+ if (err)
24+ snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
25+ return buf;
26+}
tools/perf/MANIFEST+1−0
@@ -29,6 +29,7 @@ tools/lib/symbol/kallsyms.c · 28 unmodified lines
2929 tools/lib/symbol/kallsyms.h
3030 tools/lib/find_bit.c
3131 tools/lib/bitmap.c
32+tools/lib/str_error_r.c
3233 tools/include/asm/atomic.h
3334 tools/include/asm/barrier.h
3435 tools/include/asm/bug.h
tools/perf/arch/x86/tests/rdpmc.c+2−2
@@ -111,14 +111,14 @@ static int __test__rdpmc(void) · 110 unmodified lines
111111 if (fd < 0) {
112112 pr_err("Error: sys_perf_event_open() syscall returned "
113113 "with %d (%s)\n", fd,
114− strerror_r(errno, sbuf, sizeof(sbuf)));
114+ str_error_r(errno, sbuf, sizeof(sbuf)));
115115 return -1;
116116 }
117117
118118 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
119119 if (addr == (void *)(-1)) {
120120 pr_err("Error: mmap() syscall returned with (%s)\n",
121− strerror_r(errno, sbuf, sizeof(sbuf)));
121+ str_error_r(errno, sbuf, sizeof(sbuf)));
122122 goto out_close;
123123 }
124124
tools/perf/builtin-buildid-cache.c+4−4
@@ -351,7 +351,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 350 unmodified lines
351351 continue;
352352 }
353353 pr_warning("Couldn't add %s: %s\n",
354− pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
354+ pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
355355 }
356356
357357 strlist__delete(list);
@@ -369,7 +369,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 11 unmodified lines
369369 continue;
370370 }
371371 pr_warning("Couldn't remove %s: %s\n",
372− pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
372+ pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
373373 }
374374
375375 strlist__delete(list);
@@ -387,7 +387,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 11 unmodified lines
387387 continue;
388388 }
389389 pr_warning("Couldn't remove %s: %s\n",
390− pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
390+ pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
391391 }
392392
393393 strlist__delete(list);
@@ -408,7 +408,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 14 unmodified lines
408408 continue;
409409 }
410410 pr_warning("Couldn't update %s: %s\n",
411− pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
411+ pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
412412 }
413413
414414 strlist__delete(list);
tools/perf/builtin-help.c+4−4
@@ -117,7 +117,7 @@ static void exec_woman_emacs(const char *path, const char *page) · 116 unmodified lines
117117 free(man_page);
118118 }
119119 warning("failed to exec '%s': %s", path,
120− strerror_r(errno, sbuf, sizeof(sbuf)));
120+ str_error_r(errno, sbuf, sizeof(sbuf)));
121121 }
122122 }
123123
@@ -150,7 +150,7 @@ static void exec_man_konqueror(const char *path, const char *page) · 26 unmodified lines
150150 free(man_page);
151151 }
152152 warning("failed to exec '%s': %s", path,
153− strerror_r(errno, sbuf, sizeof(sbuf)));
153+ str_error_r(errno, sbuf, sizeof(sbuf)));
154154 }
155155 }
156156
@@ -162,7 +162,7 @@ static void exec_man_man(const char *path, const char *page) · 5 unmodified lines
162162 path = "man";
163163 execlp(path, "man", page, NULL);
164164 warning("failed to exec '%s': %s", path,
165− strerror_r(errno, sbuf, sizeof(sbuf)));
165+ str_error_r(errno, sbuf, sizeof(sbuf)));
166166 }
167167
168168 static void exec_man_cmd(const char *cmd, const char *page)
@@ -175,7 +175,7 @@ static void exec_man_cmd(const char *cmd, const char *page) · 6 unmodified lines
175175 free(shell_cmd);
176176 }
177177 warning("failed to exec '%s': %s", cmd,
178− strerror_r(errno, sbuf, sizeof(sbuf)));
178+ str_error_r(errno, sbuf, sizeof(sbuf)));
179179 }
180180
181181 static void add_man_viewer(const char *name)
tools/perf/builtin-kvm.c+2−2
@@ -1018,13 +1018,13 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm) · 1017 unmodified lines
10181018 err = perf_evlist__open(evlist);
10191019 if (err < 0) {
10201020 printf("Couldn't create the events: %s\n",
1021− strerror_r(errno, sbuf, sizeof(sbuf)));
1021+ str_error_r(errno, sbuf, sizeof(sbuf)));
10221022 goto out;
10231023 }
10241024
10251025 if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) {
10261026 ui__error("Failed to mmap the events: %s\n",
1027− strerror_r(errno, sbuf, sizeof(sbuf)));
1027+ str_error_r(errno, sbuf, sizeof(sbuf)));
10281028 perf_evlist__close(evlist);
10291029 goto out;
10301030 }
tools/perf/builtin-probe.c+1−1
@@ -308,7 +308,7 @@ static void pr_err_with_code(const char *msg, int err) · 307 unmodified lines
308308
309309 pr_err("%s", msg);
310310 pr_debug(" Reason: %s (Code: %d)",
311− strerror_r(-err, sbuf, sizeof(sbuf)), err);
311+ str_error_r(-err, sbuf, sizeof(sbuf)), err);
312312 pr_err("\n");
313313 }
314314
tools/perf/builtin-record.c+3−3
@@ -361,7 +361,7 @@ static int record__mmap_evlist(struct record *rec, · 360 unmodified lines
361361 return -errno;
362362 } else {
363363 pr_err("failed to mmap with %d (%s)\n", errno,
364− strerror_r(errno, msg, sizeof(msg)));
364+ str_error_r(errno, msg, sizeof(msg)));
365365 if (errno)
366366 return -errno;
367367 else
@@ -407,7 +407,7 @@ try_again: · 39 unmodified lines
407407 if (perf_evlist__apply_filters(evlist, &pos)) {
408408 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
409409 pos->filter, perf_evsel__name(pos), errno,
410− strerror_r(errno, msg, sizeof(msg)));
410+ str_error_r(errno, msg, sizeof(msg)));
411411 rc = -1;
412412 goto out;
413413 }
@@ -1003,7 +1003,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) · 589 unmodified lines
10031003
10041004 if (forks && workload_exec_errno) {
10051005 char msg[STRERR_BUFSIZE];
1006− const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
1006+ const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
10071007 pr_err("Workload failed: %s\n", emsg);
10081008 err = -1;
10091009 goto out_child;
tools/perf/builtin-sched.c+1−1
@@ -494,7 +494,7 @@ force_again: · 493 unmodified lines
494494 }
495495 pr_err("Error: sys_perf_event_open() syscall returned "
496496 "with %d (%s)\n%s", fd,
497− strerror_r(errno, sbuf, sizeof(sbuf)), info);
497+ str_error_r(errno, sbuf, sizeof(sbuf)), info);
498498 exit(EXIT_FAILURE);
499499 }
500500 return fd;
tools/perf/builtin-stat.c+2−2
@@ -596,7 +596,7 @@ try_again: · 595 unmodified lines
596596 if (perf_evlist__apply_filters(evsel_list, &counter)) {
597597 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
598598 counter->filter, perf_evsel__name(counter), errno,
599− strerror_r(errno, msg, sizeof(msg)));
599+ str_error_r(errno, msg, sizeof(msg)));
600600 return -1;
601601 }
602602
@@ -637,7 +637,7 @@ try_again: · 34 unmodified lines
637637 wait(&status);
638638
639639 if (workload_exec_errno) {
640− const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
640+ const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
641641 pr_err("Workload failed: %s\n", emsg);
642642 return -1;
643643 }
tools/perf/builtin-top.c+3−3
@@ -907,7 +907,7 @@ try_again: · 906 unmodified lines
907907
908908 if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
909909 ui__error("Failed to mmap with %d (%s)\n",
910− errno, strerror_r(errno, msg, sizeof(msg)));
910+ errno, str_error_r(errno, msg, sizeof(msg)));
911911 goto out_err;
912912 }
913913
@@ -1028,7 +1028,7 @@ out_delete: · 114 unmodified lines
10281028
10291029 out_err_cpu_topo: {
10301030 char errbuf[BUFSIZ];
1031− const char *err = strerror_r(-ret, errbuf, sizeof(errbuf));
1031+ const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
10321032
10331033 ui__error("Could not read the CPU topology map: %s\n", err);
10341034 goto out_delete;
@@ -1295,7 +1295,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) · 260 unmodified lines
12951295
12961296 if (perf_evlist__create_maps(top.evlist, target) < 0) {
12971297 ui__error("Couldn't create thread/CPU maps: %s\n",
1298− errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf)));
1298+ errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
12991299 goto out_delete_evlist;
13001300 }
13011301
tools/perf/builtin-trace.c+2−2
@@ -1601,7 +1601,7 @@ signed_print: · 1600 unmodified lines
16011601 fprintf(trace->output, ") = %ld", ret);
16021602 } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {
16031603 char bf[STRERR_BUFSIZE];
1604− const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
1604+ const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
16051605 *e = audit_errno_to_name(-ret);
16061606
16071607 fprintf(trace->output, ") = -1 %s %s", e, emsg);
@@ -2402,7 +2402,7 @@ out_error_apply_filters: · 794 unmodified lines
24022402 fprintf(trace->output,
24032403 "Failed to set filter \"%s\" on event %s with %d (%s)\n",
24042404 evsel->filter, perf_evsel__name(evsel), errno,
2405− strerror_r(errno, errbuf, sizeof(errbuf)));
2405+ str_error_r(errno, errbuf, sizeof(errbuf)));
24062406 goto out_delete_evlist;
24072407 }
24082408 out_error_mem:
tools/perf/perf.c+3−3
@@ -374,7 +374,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · 373 unmodified lines
374374 /* Check for ENOSPC and EIO errors.. */
375375 if (fflush(stdout)) {
376376 fprintf(stderr, "write failure on standard output: %s",
377− strerror_r(errno, sbuf, sizeof(sbuf)));
377+ str_error_r(errno, sbuf, sizeof(sbuf)));
378378 goto out;
379379 }
380380 if (ferror(stdout)) {
@@ -383,7 +383,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · 2 unmodified lines
383383 }
384384 if (fclose(stdout)) {
385385 fprintf(stderr, "close failed on standard output: %s",
386− strerror_r(errno, sbuf, sizeof(sbuf)));
386+ str_error_r(errno, sbuf, sizeof(sbuf)));
387387 goto out;
388388 }
389389 status = 0;
@@ -615,7 +615,7 @@ int main(int argc, const char **argv) · 225 unmodified lines
615615 }
616616
617617 fprintf(stderr, "Failed to run command '%s': %s\n",
618− cmd, strerror_r(errno, sbuf, sizeof(sbuf)));
618+ cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
619619 out:
620620 return 1;
621621 }
tools/perf/tests/backward-ring-buffer.c+2−2
@@ -60,7 +60,7 @@ static int do_test(struct perf_evlist *evlist, int mmap_pages, · 59 unmodified lines
6060 err = perf_evlist__mmap(evlist, mmap_pages, true);
6161 if (err < 0) {
6262 pr_debug("perf_evlist__mmap: %s\n",
63− strerror_r(errno, sbuf, sizeof(sbuf)));
63+ str_error_r(errno, sbuf, sizeof(sbuf)));
6464 return TEST_FAIL;
6565 }
6666
@@ -124,7 +124,7 @@ int test__backward_ring_buffer(int subtest __maybe_unused) · 57 unmodified lines
124124 err = perf_evlist__open(evlist);
125125 if (err < 0) {
126126 pr_debug("perf_evlist__open: %s\n",
127− strerror_r(errno, sbuf, sizeof(sbuf)));
127+ str_error_r(errno, sbuf, sizeof(sbuf)));
128128 goto out_delete_evlist;
129129 }
130130
tools/perf/tests/bpf.c+2−2
@@ -143,14 +143,14 @@ static int do_test(struct bpf_object *obj, int (*func)(void), · 142 unmodified lines
143143 err = perf_evlist__open(evlist);
144144 if (err < 0) {
145145 pr_debug("perf_evlist__open: %s\n",
146− strerror_r(errno, sbuf, sizeof(sbuf)));
146+ str_error_r(errno, sbuf, sizeof(sbuf)));
147147 goto out_delete_evlist;
148148 }
149149
150150 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
151151 if (err < 0) {
152152 pr_debug("perf_evlist__mmap: %s\n",
153− strerror_r(errno, sbuf, sizeof(sbuf)));
153+ str_error_r(errno, sbuf, sizeof(sbuf)));
154154 goto out_delete_evlist;
155155 }
156156
tools/perf/tests/builtin-test.c+1−1
@@ -258,7 +258,7 @@ static int run_test(struct test *test, int subtest) · 257 unmodified lines
258258
259259 if (child < 0) {
260260 pr_err("failed to fork test: %s\n",
261− strerror_r(errno, sbuf, sizeof(sbuf)));
261+ str_error_r(errno, sbuf, sizeof(sbuf)));
262262 return -1;
263263 }
264264
tools/perf/tests/event-times.c+1−1
@@ -37,7 +37,7 @@ static int attach__enable_on_exec(struct perf_evlist *evlist) · 36 unmodified lines
3737 err = perf_evlist__open(evlist);
3838 if (err < 0) {
3939 pr_debug("perf_evlist__open: %s\n",
40− strerror_r(errno, sbuf, sizeof(sbuf)));
40+ str_error_r(errno, sbuf, sizeof(sbuf)));
4141 return err;
4242 }
4343
tools/perf/tests/mmap-basic.c+3−3
@@ -49,7 +49,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 48 unmodified lines
4949 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
5050 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
5151 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
52− cpus->map[0], strerror_r(errno, sbuf, sizeof(sbuf)));
52+ cpus->map[0], str_error_r(errno, sbuf, sizeof(sbuf)));
5353 goto out_free_cpus;
5454 }
5555
@@ -79,7 +79,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 23 unmodified lines
7979 if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
8080 pr_debug("failed to open counter: %s, "
8181 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
82− strerror_r(errno, sbuf, sizeof(sbuf)));
82+ str_error_r(errno, sbuf, sizeof(sbuf)));
8383 goto out_delete_evlist;
8484 }
8585
@@ -89,7 +89,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 3 unmodified lines
8989
9090 if (perf_evlist__mmap(evlist, 128, true) < 0) {
9191 pr_debug("failed to mmap events: %d (%s)\n", errno,
92− strerror_r(errno, sbuf, sizeof(sbuf)));
92+ str_error_r(errno, sbuf, sizeof(sbuf)));
9393 goto out_delete_evlist;
9494 }
9595
tools/perf/tests/openat-syscall-all-cpus.c+2−2
@@ -41,7 +41,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused) · 40 unmodified lines
4141 if (perf_evsel__open(evsel, cpus, threads) < 0) {
4242 pr_debug("failed to open counter: %s, "
4343 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
44− strerror_r(errno, sbuf, sizeof(sbuf)));
44+ str_error_r(errno, sbuf, sizeof(sbuf)));
4545 goto out_evsel_delete;
4646 }
4747
@@ -62,7 +62,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused) · 14 unmodified lines
6262 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
6363 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
6464 cpus->map[cpu],
65− strerror_r(errno, sbuf, sizeof(sbuf)));
65+ str_error_r(errno, sbuf, sizeof(sbuf)));
6666 goto out_close_fd;
6767 }
6868 for (i = 0; i < ncalls; ++i) {
tools/perf/tests/openat-syscall-tp-fields.c+2−2
@@ -51,14 +51,14 @@ int test__syscall_openat_tp_fields(int subtest __maybe_unused) · 50 unmodified lines
5151 err = perf_evlist__open(evlist);
5252 if (err < 0) {
5353 pr_debug("perf_evlist__open: %s\n",
54− strerror_r(errno, sbuf, sizeof(sbuf)));
54+ str_error_r(errno, sbuf, sizeof(sbuf)));
5555 goto out_delete_evlist;
5656 }
5757
5858 err = perf_evlist__mmap(evlist, UINT_MAX, false);
5959 if (err < 0) {
6060 pr_debug("perf_evlist__mmap: %s\n",
61− strerror_r(errno, sbuf, sizeof(sbuf)));
61+ str_error_r(errno, sbuf, sizeof(sbuf)));
6262 goto out_delete_evlist;
6363 }
6464
tools/perf/tests/openat-syscall.c+1−1
@@ -29,7 +29,7 @@ int test__openat_syscall_event(int subtest __maybe_unused) · 28 unmodified lines
2929 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
3030 pr_debug("failed to open counter: %s, "
3131 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
32− strerror_r(errno, sbuf, sizeof(sbuf)));
32+ str_error_r(errno, sbuf, sizeof(sbuf)));
3333 goto out_evsel_delete;
3434 }
3535
tools/perf/tests/perf-record.c+4−4
@@ -104,7 +104,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 103 unmodified lines
104104 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
105105 if (err < 0) {
106106 pr_debug("sched__get_first_possible_cpu: %s\n",
107− strerror_r(errno, sbuf, sizeof(sbuf)));
107+ str_error_r(errno, sbuf, sizeof(sbuf)));
108108 goto out_delete_evlist;
109109 }
110110
@@ -115,7 +115,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 4 unmodified lines
115115 */
116116 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
117117 pr_debug("sched_setaffinity: %s\n",
118− strerror_r(errno, sbuf, sizeof(sbuf)));
118+ str_error_r(errno, sbuf, sizeof(sbuf)));
119119 goto out_delete_evlist;
120120 }
121121
@@ -126,7 +126,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 4 unmodified lines
126126 err = perf_evlist__open(evlist);
127127 if (err < 0) {
128128 pr_debug("perf_evlist__open: %s\n",
129− strerror_r(errno, sbuf, sizeof(sbuf)));
129+ str_error_r(errno, sbuf, sizeof(sbuf)));
130130 goto out_delete_evlist;
131131 }
132132
@@ -138,7 +138,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 5 unmodified lines
138138 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
139139 if (err < 0) {
140140 pr_debug("perf_evlist__mmap: %s\n",
141− strerror_r(errno, sbuf, sizeof(sbuf)));
141+ str_error_r(errno, sbuf, sizeof(sbuf)));
142142 goto out_delete_evlist;
143143 }
144144
tools/perf/tests/sw-clock.c+2−2
@@ -70,7 +70,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) · 69 unmodified lines
7070
7171 err = -errno;
7272 pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",
73− strerror_r(errno, sbuf, sizeof(sbuf)),
73+ str_error_r(errno, sbuf, sizeof(sbuf)),
7474 knob, (u64)attr.sample_freq);
7575 goto out_delete_evlist;
7676 }
@@ -78,7 +78,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) · 1 unmodified line
7878 err = perf_evlist__mmap(evlist, 128, true);
7979 if (err < 0) {
8080 pr_debug("failed to mmap event: %d (%s)\n", errno,
81− strerror_r(errno, sbuf, sizeof(sbuf)));
81+ str_error_r(errno, sbuf, sizeof(sbuf)));
8282 goto out_delete_evlist;
8383 }
8484
tools/perf/tests/task-exit.c+2−2
@@ -91,13 +91,13 @@ int test__task_exit(int subtest __maybe_unused) · 90 unmodified lines
9191 err = perf_evlist__open(evlist);
9292 if (err < 0) {
9393 pr_debug("Couldn't open the evlist: %s\n",
94− strerror_r(-err, sbuf, sizeof(sbuf)));
94+ str_error_r(-err, sbuf, sizeof(sbuf)));
9595 goto out_delete_evlist;
9696 }
9797
9898 if (perf_evlist__mmap(evlist, 128, true) < 0) {
9999 pr_debug("failed to mmap events: %d (%s)\n", errno,
100− strerror_r(errno, sbuf, sizeof(sbuf)));
100+ str_error_r(errno, sbuf, sizeof(sbuf)));
101101 goto out_delete_evlist;
102102 }
103103
tools/perf/ui/browsers/hists.c+1−1
@@ -2029,7 +2029,7 @@ static int hist_browser__dump(struct hist_browser *browser) · 2028 unmodified lines
20292029 fp = fopen(filename, "w");
20302030 if (fp == NULL) {
20312031 char bf[64];
2032− const char *err = strerror_r(errno, bf, sizeof(bf));
2032+ const char *err = str_error_r(errno, bf, sizeof(bf));
20332033 ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
20342034 return -1;
20352035 }
tools/perf/util/Build+5−0
@@ -70,6 +70,7 @@ libperf-y += stat.o · 69 unmodified lines
7070 libperf-y += stat-shadow.o
7171 libperf-y += record.o
7272 libperf-y += srcline.o
73+libperf-y += str_error_r.o
7374 libperf-y += data.o
7475 libperf-y += tsc.o
7576 libperf-y += cloexec.o
@@ -173,6 +174,10 @@ $(OUTPUT)util/libstring.o: ../lib/string.c FORCE · 97 unmodified lines
173174 $(call rule_mkdir)
174175 $(call if_changed_dep,cc_o_c)
175176
177+$(OUTPUT)util/str_error_r.o: ../lib/str_error_r.c FORCE
178+ $(call rule_mkdir)
179+ $(call if_changed_dep,cc_o_c)
180+
176181 $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
177182 $(call rule_mkdir)
178183 $(call if_changed_dep,cc_o_c)
tools/perf/util/bpf-loader.c+1−1
@@ -1589,7 +1589,7 @@ bpf_loader_strerror(int err, char *buf, size_t size) · 1588 unmodified lines
15891589 snprintf(buf, size, "Unknown bpf loader error %d", err);
15901590 else
15911591 snprintf(buf, size, "%s",
1592− strerror_r(err, sbuf, sizeof(sbuf)));
1592+ str_error_r(err, sbuf, sizeof(sbuf)));
15931593
15941594 buf[size - 1] = '\0';
15951595 return -1;
tools/perf/util/cloexec.c+2−2
@@ -58,7 +58,7 @@ static int perf_flag_probe(void) · 57 unmodified lines
5858
5959 WARN_ONCE(err != EINVAL && err != EBUSY,
6060 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
61− err, strerror_r(err, sbuf, sizeof(sbuf)));
61+ err, str_error_r(err, sbuf, sizeof(sbuf)));
6262
6363 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
6464 while (1) {
@@ -76,7 +76,7 @@ static int perf_flag_probe(void) · 11 unmodified lines
7676
7777 if (WARN_ONCE(fd < 0 && err != EBUSY,
7878 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
79− err, strerror_r(err, sbuf, sizeof(sbuf))))
79+ err, str_error_r(err, sbuf, sizeof(sbuf))))
8080 return -1;
8181
8282 return 0;
tools/perf/util/data.c+2−2
@@ -57,7 +57,7 @@ static int open_file_read(struct perf_data_file *file) · 56 unmodified lines
5757 int err = errno;
5858
5959 pr_err("failed to open %s: %s", file->path,
60− strerror_r(err, sbuf, sizeof(sbuf)));
60+ str_error_r(err, sbuf, sizeof(sbuf)));
6161 if (err == ENOENT && !strcmp(file->path, "perf.data"))
6262 pr_err(" (try 'perf record' first)");
6363 pr_err("\n");
@@ -99,7 +99,7 @@ static int open_file_write(struct perf_data_file *file) · 35 unmodified lines
9999
100100 if (fd < 0)
101101 pr_err("failed to open %s : %s\n", file->path,
102− strerror_r(errno, sbuf, sizeof(sbuf)));
102+ str_error_r(errno, sbuf, sizeof(sbuf)));
103103
104104 return fd;
105105 }
tools/perf/util/debug.h+1−1
@@ -38,7 +38,7 @@ extern int debug_data_convert; · 37 unmodified lines
3838 #define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
3939 #define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
4040
41−#define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */
41+#define STRERR_BUFSIZE 128 /* For the buffer size of str_error_r */
4242
4343 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
4444 void trace_event(union perf_event *event);
tools/perf/util/dso.c+3−3
@@ -335,7 +335,7 @@ static int do_open(char *name) · 334 unmodified lines
335335 return fd;
336336
337337 pr_debug("dso open failed: %s\n",
338− strerror_r(errno, sbuf, sizeof(sbuf)));
338+ str_error_r(errno, sbuf, sizeof(sbuf)));
339339 if (!dso__data_open_cnt || errno != EMFILE)
340340 break;
341341
@@ -786,7 +786,7 @@ static int data_file_size(struct dso *dso, struct machine *machine) · 444 unmodified lines
786786 if (fstat(dso->data.fd, &st) < 0) {
787787 ret = -errno;
788788 pr_err("dso cache fstat failed: %s\n",
789− strerror_r(errno, sbuf, sizeof(sbuf)));
789+ str_error_r(errno, sbuf, sizeof(sbuf)));
790790 dso->data.status = DSO_DATA_STATUS_ERROR;
791791 goto out;
792792 }
@@ -1366,7 +1366,7 @@ int dso__strerror_load(struct dso *dso, char *buf, size_t buflen) · 573 unmodified lines
13661366 BUG_ON(buflen == 0);
13671367
13681368 if (errnum >= 0) {
1369− const char *err = strerror_r(errnum, buf, buflen);
1369+ const char *err = str_error_r(errnum, buf, buflen);
13701370
13711371 if (err != buf)
13721372 scnprintf(buf, buflen, "%s", err);
tools/perf/util/evlist.c+2−2
@@ -1790,7 +1790,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist, · 1789 unmodified lines
17901790 int err, char *buf, size_t size)
17911791 {
17921792 int printed, value;
1793− char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
1793+ char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
17941794
17951795 switch (err) {
17961796 case EACCES:
@@ -1842,7 +1842,7 @@ out_default: · 45 unmodified lines
18421842
18431843 int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
18441844 {
1845− char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
1845+ char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
18461846 int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
18471847
18481848 switch (err) {
tools/perf/util/evsel.c+1−1
@@ -2419,7 +2419,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, · 2418 unmodified lines
24192419 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
24202420 "/bin/dmesg may provide additional information.\n"
24212421 "No CONFIG_PERF_EVENTS=y kernel support configured?",
2422− err, strerror_r(err, sbuf, sizeof(sbuf)),
2422+ err, str_error_r(err, sbuf, sizeof(sbuf)),
24232423 perf_evsel__name(evsel));
24242424 }
24252425
tools/perf/util/llvm-utils.c+4−4
@@ -106,7 +106,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz) · 105 unmodified lines
106106 file = popen(cmd, "r");
107107 if (!file) {
108108 pr_err("ERROR: unable to popen cmd: %s\n",
109− strerror_r(errno, serr, sizeof(serr)));
109+ str_error_r(errno, serr, sizeof(serr)));
110110 return -EINVAL;
111111 }
112112
@@ -140,7 +140,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz) · 27 unmodified lines
140140
141141 if (ferror(file)) {
142142 pr_err("ERROR: error occurred when reading from pipe: %s\n",
143− strerror_r(errno, serr, sizeof(serr)));
143+ str_error_r(errno, serr, sizeof(serr)));
144144 err = -EIO;
145145 goto errout;
146146 }
@@ -382,7 +382,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, · 235 unmodified lines
382382 if (path[0] != '-' && realpath(path, abspath) == NULL) {
383383 err = errno;
384384 pr_err("ERROR: problems with path %s: %s\n",
385− path, strerror_r(err, serr, sizeof(serr)));
385+ path, str_error_r(err, serr, sizeof(serr)));
386386 return -err;
387387 }
388388
@@ -410,7 +410,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, · 21 unmodified lines
410410 if (nr_cpus_avail <= 0) {
411411 pr_err(
412412 "WARNING:\tunable to get available CPUs in this system: %s\n"
413−" \tUse 128 instead.\n", strerror_r(errno, serr, sizeof(serr)));
413+" \tUse 128 instead.\n", str_error_r(errno, serr, sizeof(serr)));
414414 nr_cpus_avail = 128;
415415 }
416416 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
tools/perf/util/probe-event.c+3−3
@@ -468,7 +468,7 @@ static struct debuginfo *open_debuginfo(const char *module, bool silent) · 467 unmodified lines
468468 err = kernel_get_module_dso(module, &dso);
469469 if (err < 0) {
470470 if (!dso || dso->load_errno == 0) {
471− if (!strerror_r(-err, reason, STRERR_BUFSIZE))
471+ if (!str_error_r(-err, reason, STRERR_BUFSIZE))
472472 strcpy(reason, "(unknown)");
473473 } else
474474 dso__strerror_load(dso, reason, STRERR_BUFSIZE);
@@ -806,7 +806,7 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) · 331 unmodified lines
806806 error:
807807 if (ferror(fp)) {
808808 pr_warning("File read error: %s\n",
809− strerror_r(errno, sbuf, sizeof(sbuf)));
809+ str_error_r(errno, sbuf, sizeof(sbuf)));
810810 return -1;
811811 }
812812 return 0;
@@ -886,7 +886,7 @@ static int __show_line_range(struct line_range *lr, const char *module, · 73 unmodified lines
886886 fp = fopen(lr->path, "r");
887887 if (fp == NULL) {
888888 pr_warning("Failed to open %s: %s\n", lr->path,
889− strerror_r(errno, sbuf, sizeof(sbuf)));
889+ str_error_r(errno, sbuf, sizeof(sbuf)));
890890 return -errno;
891891 }
892892 /* Skip to starting line number */
tools/perf/util/probe-file.c+5−5
@@ -50,7 +50,7 @@ static void print_open_warning(int err, bool uprobe) · 49 unmodified lines
5050 else
5151 pr_warning("Failed to open %cprobe_events: %s\n",
5252 uprobe ? 'u' : 'k',
53− strerror_r(-err, sbuf, sizeof(sbuf)));
53+ str_error_r(-err, sbuf, sizeof(sbuf)));
5454 }
5555
5656 static void print_both_open_warning(int kerr, int uerr)
@@ -64,9 +64,9 @@ static void print_both_open_warning(int kerr, int uerr) · 7 unmodified lines
6464 else {
6565 char sbuf[STRERR_BUFSIZE];
6666 pr_warning("Failed to open kprobe events: %s.\n",
67− strerror_r(-kerr, sbuf, sizeof(sbuf)));
67+ str_error_r(-kerr, sbuf, sizeof(sbuf)));
6868 pr_warning("Failed to open uprobe events: %s.\n",
69− strerror_r(-uerr, sbuf, sizeof(sbuf)));
69+ str_error_r(-uerr, sbuf, sizeof(sbuf)));
7070 }
7171 }
7272
@@ -224,7 +224,7 @@ int probe_file__add_event(int fd, struct probe_trace_event *tev) · 151 unmodified lines
224224 if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) {
225225 ret = -errno;
226226 pr_warning("Failed to write event: %s\n",
227− strerror_r(errno, sbuf, sizeof(sbuf)));
227+ str_error_r(errno, sbuf, sizeof(sbuf)));
228228 }
229229 }
230230 free(buf);
@@ -262,7 +262,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) · 31 unmodified lines
262262 return 0;
263263 error:
264264 pr_warning("Failed to delete event: %s\n",
265− strerror_r(-ret, buf, sizeof(buf)));
265+ str_error_r(-ret, buf, sizeof(buf)));
266266 return ret;
267267 }
268268
tools/perf/util/probe-finder.c+2−2
@@ -381,7 +381,7 @@ formatted: · 380 unmodified lines
381381 if (ret >= 16)
382382 ret = -E2BIG;
383383 pr_warning("Failed to convert variable type: %s\n",
384− strerror_r(-ret, sbuf, sizeof(sbuf)));
384+ str_error_r(-ret, sbuf, sizeof(sbuf)));
385385 return ret;
386386 }
387387 tvar->type = strdup(buf);
@@ -809,7 +809,7 @@ static int find_lazy_match_lines(struct intlist *list, · 421 unmodified lines
809809 fp = fopen(fname, "r");
810810 if (!fp) {
811811 pr_warning("Failed to open %s: %s\n", fname,
812− strerror_r(errno, sbuf, sizeof(sbuf)));
812+ str_error_r(errno, sbuf, sizeof(sbuf)));
813813 return -errno;
814814 }
815815
tools/perf/util/python-ext-sources+1−0
@@ -13,6 +13,7 @@ util/cpumap.c · 12 unmodified lines
1313 ../lib/bitmap.c
1414 ../lib/find_bit.c
1515 ../lib/hweight.c
16+../lib/str_error_r.c
1617 util/thread_map.c
1718 util/util.c
1819 util/xyarray.c
tools/perf/util/target.c+1−1
@@ -121,7 +121,7 @@ int target__strerror(struct target *target, int errnum, · 120 unmodified lines
121121 BUG_ON(buflen == 0);
122122
123123 if (errnum >= 0) {
124− const char *err = strerror_r(errnum, buf, buflen);
124+ const char *err = str_error_r(errnum, buf, buflen);
125125
126126 if (err != buf)
127127 scnprintf(buf, buflen, "%s", err);
tools/perf/util/util.h+1−0
@@ -360,4 +360,5 @@ typedef void (*print_binary_t)(enum binary_printer_ops, · 359 unmodified lines
360360 void print_binary(unsigned char *data, size_t len,
361361 size_t bytes_per_line, print_binary_t printer,
362362 void *extra);
363+
363364 #endif /* GIT_COMPAT_UTIL_H */