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
12extern size_t strlcpy(char *dest, const char *src, size_t size);12extern size_t strlcpy(char *dest, const char *src, size_t size);
13#endif13#endif
14 14
15char *str_error_r(int errnum, char *buf, size_t buflen);
16
15#endif /* _LINUX_STRING_H_ */17#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 */
20char *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
29tools/lib/symbol/kallsyms.h29tools/lib/symbol/kallsyms.h
30tools/lib/find_bit.c30tools/lib/find_bit.c
31tools/lib/bitmap.c31tools/lib/bitmap.c
32tools/lib/str_error_r.c
32tools/include/asm/atomic.h33tools/include/asm/atomic.h
33tools/include/asm/barrier.h34tools/include/asm/barrier.h
34tools/include/asm/bug.h35tools/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
111 if (fd < 0) {111 if (fd < 0) {
112 pr_err("Error: sys_perf_event_open() syscall returned "112 pr_err("Error: sys_perf_event_open() syscall returned "
113 "with %d (%s)\n", fd,113 "with %d (%s)\n", fd,
114 strerror_r(errno, sbuf, sizeof(sbuf)));114 str_error_r(errno, sbuf, sizeof(sbuf)));
115 return -1;115 return -1;
116 }116 }
117 117
118 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);118 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
119 if (addr == (void *)(-1)) {119 if (addr == (void *)(-1)) {
120 pr_err("Error: mmap() syscall returned with (%s)\n",120 pr_err("Error: mmap() syscall returned with (%s)\n",
121 strerror_r(errno, sbuf, sizeof(sbuf)));121 str_error_r(errno, sbuf, sizeof(sbuf)));
122 goto out_close;122 goto out_close;
123 }123 }
124 124
tools/perf/builtin-buildid-cache.c+4−4
@@ -351,7 +351,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 350 unmodified lines
351 continue;351 continue;
352 }352 }
353 pr_warning("Couldn't add %s: %s\n",353 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)));
355 }355 }
356 356
357 strlist__delete(list);357 strlist__delete(list);
@@ -369,7 +369,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 11 unmodified lines
369 continue;369 continue;
370 }370 }
371 pr_warning("Couldn't remove %s: %s\n",371 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)));
373 }373 }
374 374
375 strlist__delete(list);375 strlist__delete(list);
@@ -387,7 +387,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 11 unmodified lines
387 continue;387 continue;
388 }388 }
389 pr_warning("Couldn't remove %s: %s\n",389 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)));
391 }391 }
392 392
393 strlist__delete(list);393 strlist__delete(list);
@@ -408,7 +408,7 @@ int cmd_buildid_cache(int argc, const char **argv, · 14 unmodified lines
408 continue;408 continue;
409 }409 }
410 pr_warning("Couldn't update %s: %s\n",410 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)));
412 }412 }
413 413
414 strlist__delete(list);414 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
117 free(man_page);117 free(man_page);
118 }118 }
119 warning("failed to exec '%s': %s", path,119 warning("failed to exec '%s': %s", path,
120 strerror_r(errno, sbuf, sizeof(sbuf)));120 str_error_r(errno, sbuf, sizeof(sbuf)));
121 }121 }
122}122}
123 123
@@ -150,7 +150,7 @@ static void exec_man_konqueror(const char *path, const char *page) · 26 unmodified lines
150 free(man_page);150 free(man_page);
151 }151 }
152 warning("failed to exec '%s': %s", path,152 warning("failed to exec '%s': %s", path,
153 strerror_r(errno, sbuf, sizeof(sbuf)));153 str_error_r(errno, sbuf, sizeof(sbuf)));
154 }154 }
155}155}
156 156
@@ -162,7 +162,7 @@ static void exec_man_man(const char *path, const char *page) · 5 unmodified lines
162 path = "man";162 path = "man";
163 execlp(path, "man", page, NULL);163 execlp(path, "man", page, NULL);
164 warning("failed to exec '%s': %s", path,164 warning("failed to exec '%s': %s", path,
165 strerror_r(errno, sbuf, sizeof(sbuf)));165 str_error_r(errno, sbuf, sizeof(sbuf)));
166}166}
167 167
168static void exec_man_cmd(const char *cmd, const char *page)168static 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
175 free(shell_cmd);175 free(shell_cmd);
176 }176 }
177 warning("failed to exec '%s': %s", cmd,177 warning("failed to exec '%s': %s", cmd,
178 strerror_r(errno, sbuf, sizeof(sbuf)));178 str_error_r(errno, sbuf, sizeof(sbuf)));
179}179}
180 180
181static void add_man_viewer(const char *name)181static 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
1018 err = perf_evlist__open(evlist);1018 err = perf_evlist__open(evlist);
1019 if (err < 0) {1019 if (err < 0) {
1020 printf("Couldn't create the events: %s\n",1020 printf("Couldn't create the events: %s\n",
1021 strerror_r(errno, sbuf, sizeof(sbuf)));1021 str_error_r(errno, sbuf, sizeof(sbuf)));
1022 goto out;1022 goto out;
1023 }1023 }
1024 1024
1025 if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) {1025 if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) {
1026 ui__error("Failed to mmap the events: %s\n",1026 ui__error("Failed to mmap the events: %s\n",
1027 strerror_r(errno, sbuf, sizeof(sbuf)));1027 str_error_r(errno, sbuf, sizeof(sbuf)));
1028 perf_evlist__close(evlist);1028 perf_evlist__close(evlist);
1029 goto out;1029 goto out;
1030 }1030 }
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
308 308
309 pr_err("%s", msg);309 pr_err("%s", msg);
310 pr_debug(" Reason: %s (Code: %d)",310 pr_debug(" Reason: %s (Code: %d)",
311 strerror_r(-err, sbuf, sizeof(sbuf)), err);311 str_error_r(-err, sbuf, sizeof(sbuf)), err);
312 pr_err("\n");312 pr_err("\n");
313}313}
314 314
tools/perf/builtin-record.c+3−3
@@ -361,7 +361,7 @@ static int record__mmap_evlist(struct record *rec, · 360 unmodified lines
361 return -errno;361 return -errno;
362 } else {362 } else {
363 pr_err("failed to mmap with %d (%s)\n", errno,363 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)));
365 if (errno)365 if (errno)
366 return -errno;366 return -errno;
367 else367 else
@@ -407,7 +407,7 @@ try_again: · 39 unmodified lines
407 if (perf_evlist__apply_filters(evlist, &pos)) {407 if (perf_evlist__apply_filters(evlist, &pos)) {
408 error("failed to set filter \"%s\" on event %s with %d (%s)\n",408 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
409 pos->filter, perf_evsel__name(pos), errno,409 pos->filter, perf_evsel__name(pos), errno,
410 strerror_r(errno, msg, sizeof(msg)));410 str_error_r(errno, msg, sizeof(msg)));
411 rc = -1;411 rc = -1;
412 goto out;412 goto out;
413 }413 }
@@ -1003,7 +1003,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) · 589 unmodified lines
1003 1003
1004 if (forks && workload_exec_errno) {1004 if (forks && workload_exec_errno) {
1005 char msg[STRERR_BUFSIZE];1005 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));
1007 pr_err("Workload failed: %s\n", emsg);1007 pr_err("Workload failed: %s\n", emsg);
1008 err = -1;1008 err = -1;
1009 goto out_child;1009 goto out_child;
tools/perf/builtin-sched.c+1−1
@@ -494,7 +494,7 @@ force_again: · 493 unmodified lines
494 }494 }
495 pr_err("Error: sys_perf_event_open() syscall returned "495 pr_err("Error: sys_perf_event_open() syscall returned "
496 "with %d (%s)\n%s", fd,496 "with %d (%s)\n%s", fd,
497 strerror_r(errno, sbuf, sizeof(sbuf)), info);497 str_error_r(errno, sbuf, sizeof(sbuf)), info);
498 exit(EXIT_FAILURE);498 exit(EXIT_FAILURE);
499 }499 }
500 return fd;500 return fd;
tools/perf/builtin-stat.c+2−2
@@ -596,7 +596,7 @@ try_again: · 595 unmodified lines
596 if (perf_evlist__apply_filters(evsel_list, &counter)) {596 if (perf_evlist__apply_filters(evsel_list, &counter)) {
597 error("failed to set filter \"%s\" on event %s with %d (%s)\n",597 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
598 counter->filter, perf_evsel__name(counter), errno,598 counter->filter, perf_evsel__name(counter), errno,
599 strerror_r(errno, msg, sizeof(msg)));599 str_error_r(errno, msg, sizeof(msg)));
600 return -1;600 return -1;
601 }601 }
602 602
@@ -637,7 +637,7 @@ try_again: · 34 unmodified lines
637 wait(&status);637 wait(&status);
638 638
639 if (workload_exec_errno) {639 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));
641 pr_err("Workload failed: %s\n", emsg);641 pr_err("Workload failed: %s\n", emsg);
642 return -1;642 return -1;
643 }643 }
tools/perf/builtin-top.c+3−3
@@ -907,7 +907,7 @@ try_again: · 906 unmodified lines
907 907
908 if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {908 if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
909 ui__error("Failed to mmap with %d (%s)\n",909 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)));
911 goto out_err;911 goto out_err;
912 }912 }
913 913
@@ -1028,7 +1028,7 @@ out_delete: · 114 unmodified lines
1028 1028
1029out_err_cpu_topo: {1029out_err_cpu_topo: {
1030 char errbuf[BUFSIZ];1030 char errbuf[BUFSIZ];
1031 const char *err = strerror_r(-ret, errbuf, sizeof(errbuf));1031 const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
1032 1032
1033 ui__error("Could not read the CPU topology map: %s\n", err);1033 ui__error("Could not read the CPU topology map: %s\n", err);
1034 goto out_delete;1034 goto out_delete;
@@ -1295,7 +1295,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) · 260 unmodified lines
1295 1295
1296 if (perf_evlist__create_maps(top.evlist, target) < 0) {1296 if (perf_evlist__create_maps(top.evlist, target) < 0) {
1297 ui__error("Couldn't create thread/CPU maps: %s\n",1297 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)));
1299 goto out_delete_evlist;1299 goto out_delete_evlist;
1300 }1300 }
1301 1301
tools/perf/builtin-trace.c+2−2
@@ -1601,7 +1601,7 @@ signed_print: · 1600 unmodified lines
1601 fprintf(trace->output, ") = %ld", ret);1601 fprintf(trace->output, ") = %ld", ret);
1602 } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {1602 } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {
1603 char bf[STRERR_BUFSIZE];1603 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)),
1605 *e = audit_errno_to_name(-ret);1605 *e = audit_errno_to_name(-ret);
1606 1606
1607 fprintf(trace->output, ") = -1 %s %s", e, emsg);1607 fprintf(trace->output, ") = -1 %s %s", e, emsg);
@@ -2402,7 +2402,7 @@ out_error_apply_filters: · 794 unmodified lines
2402 fprintf(trace->output,2402 fprintf(trace->output,
2403 "Failed to set filter \"%s\" on event %s with %d (%s)\n",2403 "Failed to set filter \"%s\" on event %s with %d (%s)\n",
2404 evsel->filter, perf_evsel__name(evsel), errno,2404 evsel->filter, perf_evsel__name(evsel), errno,
2405 strerror_r(errno, errbuf, sizeof(errbuf)));2405 str_error_r(errno, errbuf, sizeof(errbuf)));
2406 goto out_delete_evlist;2406 goto out_delete_evlist;
2407}2407}
2408out_error_mem:2408out_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
374 /* Check for ENOSPC and EIO errors.. */374 /* Check for ENOSPC and EIO errors.. */
375 if (fflush(stdout)) {375 if (fflush(stdout)) {
376 fprintf(stderr, "write failure on standard output: %s",376 fprintf(stderr, "write failure on standard output: %s",
377 strerror_r(errno, sbuf, sizeof(sbuf)));377 str_error_r(errno, sbuf, sizeof(sbuf)));
378 goto out;378 goto out;
379 }379 }
380 if (ferror(stdout)) {380 if (ferror(stdout)) {
@@ -383,7 +383,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · 2 unmodified lines
383 }383 }
384 if (fclose(stdout)) {384 if (fclose(stdout)) {
385 fprintf(stderr, "close failed on standard output: %s",385 fprintf(stderr, "close failed on standard output: %s",
386 strerror_r(errno, sbuf, sizeof(sbuf)));386 str_error_r(errno, sbuf, sizeof(sbuf)));
387 goto out;387 goto out;
388 }388 }
389 status = 0;389 status = 0;
@@ -615,7 +615,7 @@ int main(int argc, const char **argv) · 225 unmodified lines
615 }615 }
616 616
617 fprintf(stderr, "Failed to run command '%s': %s\n",617 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)));
619out:619out:
620 return 1;620 return 1;
621}621}
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
60 err = perf_evlist__mmap(evlist, mmap_pages, true);60 err = perf_evlist__mmap(evlist, mmap_pages, true);
61 if (err < 0) {61 if (err < 0) {
62 pr_debug("perf_evlist__mmap: %s\n",62 pr_debug("perf_evlist__mmap: %s\n",
63 strerror_r(errno, sbuf, sizeof(sbuf)));63 str_error_r(errno, sbuf, sizeof(sbuf)));
64 return TEST_FAIL;64 return TEST_FAIL;
65 }65 }
66 66
@@ -124,7 +124,7 @@ int test__backward_ring_buffer(int subtest __maybe_unused) · 57 unmodified lines
124 err = perf_evlist__open(evlist);124 err = perf_evlist__open(evlist);
125 if (err < 0) {125 if (err < 0) {
126 pr_debug("perf_evlist__open: %s\n",126 pr_debug("perf_evlist__open: %s\n",
127 strerror_r(errno, sbuf, sizeof(sbuf)));127 str_error_r(errno, sbuf, sizeof(sbuf)));
128 goto out_delete_evlist;128 goto out_delete_evlist;
129 }129 }
130 130
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
143 err = perf_evlist__open(evlist);143 err = perf_evlist__open(evlist);
144 if (err < 0) {144 if (err < 0) {
145 pr_debug("perf_evlist__open: %s\n",145 pr_debug("perf_evlist__open: %s\n",
146 strerror_r(errno, sbuf, sizeof(sbuf)));146 str_error_r(errno, sbuf, sizeof(sbuf)));
147 goto out_delete_evlist;147 goto out_delete_evlist;
148 }148 }
149 149
150 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);150 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
151 if (err < 0) {151 if (err < 0) {
152 pr_debug("perf_evlist__mmap: %s\n",152 pr_debug("perf_evlist__mmap: %s\n",
153 strerror_r(errno, sbuf, sizeof(sbuf)));153 str_error_r(errno, sbuf, sizeof(sbuf)));
154 goto out_delete_evlist;154 goto out_delete_evlist;
155 }155 }
156 156
tools/perf/tests/builtin-test.c+1−1
@@ -258,7 +258,7 @@ static int run_test(struct test *test, int subtest) · 257 unmodified lines
258 258
259 if (child < 0) {259 if (child < 0) {
260 pr_err("failed to fork test: %s\n",260 pr_err("failed to fork test: %s\n",
261 strerror_r(errno, sbuf, sizeof(sbuf)));261 str_error_r(errno, sbuf, sizeof(sbuf)));
262 return -1;262 return -1;
263 }263 }
264 264
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
37 err = perf_evlist__open(evlist);37 err = perf_evlist__open(evlist);
38 if (err < 0) {38 if (err < 0) {
39 pr_debug("perf_evlist__open: %s\n",39 pr_debug("perf_evlist__open: %s\n",
40 strerror_r(errno, sbuf, sizeof(sbuf)));40 str_error_r(errno, sbuf, sizeof(sbuf)));
41 return err;41 return err;
42 }42 }
43 43
tools/perf/tests/mmap-basic.c+3−3
@@ -49,7 +49,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 48 unmodified lines
49 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);49 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
50 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {50 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
51 pr_debug("sched_setaffinity() failed on CPU %d: %s ",51 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)));
53 goto out_free_cpus;53 goto out_free_cpus;
54 }54 }
55 55
@@ -79,7 +79,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 23 unmodified lines
79 if (perf_evsel__open(evsels[i], cpus, threads) < 0) {79 if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
80 pr_debug("failed to open counter: %s, "80 pr_debug("failed to open counter: %s, "
81 "tweak /proc/sys/kernel/perf_event_paranoid?\n",81 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
82 strerror_r(errno, sbuf, sizeof(sbuf)));82 str_error_r(errno, sbuf, sizeof(sbuf)));
83 goto out_delete_evlist;83 goto out_delete_evlist;
84 }84 }
85 85
@@ -89,7 +89,7 @@ int test__basic_mmap(int subtest __maybe_unused) · 3 unmodified lines
89 89
90 if (perf_evlist__mmap(evlist, 128, true) < 0) {90 if (perf_evlist__mmap(evlist, 128, true) < 0) {
91 pr_debug("failed to mmap events: %d (%s)\n", errno,91 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)));
93 goto out_delete_evlist;93 goto out_delete_evlist;
94 }94 }
95 95
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
41 if (perf_evsel__open(evsel, cpus, threads) < 0) {41 if (perf_evsel__open(evsel, cpus, threads) < 0) {
42 pr_debug("failed to open counter: %s, "42 pr_debug("failed to open counter: %s, "
43 "tweak /proc/sys/kernel/perf_event_paranoid?\n",43 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
44 strerror_r(errno, sbuf, sizeof(sbuf)));44 str_error_r(errno, sbuf, sizeof(sbuf)));
45 goto out_evsel_delete;45 goto out_evsel_delete;
46 }46 }
47 47
@@ -62,7 +62,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused) · 14 unmodified lines
62 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {62 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
63 pr_debug("sched_setaffinity() failed on CPU %d: %s ",63 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
64 cpus->map[cpu],64 cpus->map[cpu],
65 strerror_r(errno, sbuf, sizeof(sbuf)));65 str_error_r(errno, sbuf, sizeof(sbuf)));
66 goto out_close_fd;66 goto out_close_fd;
67 }67 }
68 for (i = 0; i < ncalls; ++i) {68 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
51 err = perf_evlist__open(evlist);51 err = perf_evlist__open(evlist);
52 if (err < 0) {52 if (err < 0) {
53 pr_debug("perf_evlist__open: %s\n",53 pr_debug("perf_evlist__open: %s\n",
54 strerror_r(errno, sbuf, sizeof(sbuf)));54 str_error_r(errno, sbuf, sizeof(sbuf)));
55 goto out_delete_evlist;55 goto out_delete_evlist;
56 }56 }
57 57
58 err = perf_evlist__mmap(evlist, UINT_MAX, false);58 err = perf_evlist__mmap(evlist, UINT_MAX, false);
59 if (err < 0) {59 if (err < 0) {
60 pr_debug("perf_evlist__mmap: %s\n",60 pr_debug("perf_evlist__mmap: %s\n",
61 strerror_r(errno, sbuf, sizeof(sbuf)));61 str_error_r(errno, sbuf, sizeof(sbuf)));
62 goto out_delete_evlist;62 goto out_delete_evlist;
63 }63 }
64 64
tools/perf/tests/openat-syscall.c+1−1
@@ -29,7 +29,7 @@ int test__openat_syscall_event(int subtest __maybe_unused) · 28 unmodified lines
29 if (perf_evsel__open_per_thread(evsel, threads) < 0) {29 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
30 pr_debug("failed to open counter: %s, "30 pr_debug("failed to open counter: %s, "
31 "tweak /proc/sys/kernel/perf_event_paranoid?\n",31 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
32 strerror_r(errno, sbuf, sizeof(sbuf)));32 str_error_r(errno, sbuf, sizeof(sbuf)));
33 goto out_evsel_delete;33 goto out_evsel_delete;
34 }34 }
35 35
tools/perf/tests/perf-record.c+4−4
@@ -104,7 +104,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 103 unmodified lines
104 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);104 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
105 if (err < 0) {105 if (err < 0) {
106 pr_debug("sched__get_first_possible_cpu: %s\n",106 pr_debug("sched__get_first_possible_cpu: %s\n",
107 strerror_r(errno, sbuf, sizeof(sbuf)));107 str_error_r(errno, sbuf, sizeof(sbuf)));
108 goto out_delete_evlist;108 goto out_delete_evlist;
109 }109 }
110 110
@@ -115,7 +115,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 4 unmodified lines
115 */115 */
116 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {116 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
117 pr_debug("sched_setaffinity: %s\n",117 pr_debug("sched_setaffinity: %s\n",
118 strerror_r(errno, sbuf, sizeof(sbuf)));118 str_error_r(errno, sbuf, sizeof(sbuf)));
119 goto out_delete_evlist;119 goto out_delete_evlist;
120 }120 }
121 121
@@ -126,7 +126,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 4 unmodified lines
126 err = perf_evlist__open(evlist);126 err = perf_evlist__open(evlist);
127 if (err < 0) {127 if (err < 0) {
128 pr_debug("perf_evlist__open: %s\n",128 pr_debug("perf_evlist__open: %s\n",
129 strerror_r(errno, sbuf, sizeof(sbuf)));129 str_error_r(errno, sbuf, sizeof(sbuf)));
130 goto out_delete_evlist;130 goto out_delete_evlist;
131 }131 }
132 132
@@ -138,7 +138,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) · 5 unmodified lines
138 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);138 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
139 if (err < 0) {139 if (err < 0) {
140 pr_debug("perf_evlist__mmap: %s\n",140 pr_debug("perf_evlist__mmap: %s\n",
141 strerror_r(errno, sbuf, sizeof(sbuf)));141 str_error_r(errno, sbuf, sizeof(sbuf)));
142 goto out_delete_evlist;142 goto out_delete_evlist;
143 }143 }
144 144
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
70 70
71 err = -errno;71 err = -errno;
72 pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",72 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)),
74 knob, (u64)attr.sample_freq);74 knob, (u64)attr.sample_freq);
75 goto out_delete_evlist;75 goto out_delete_evlist;
76 }76 }
@@ -78,7 +78,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) · 1 unmodified line
78 err = perf_evlist__mmap(evlist, 128, true);78 err = perf_evlist__mmap(evlist, 128, true);
79 if (err < 0) {79 if (err < 0) {
80 pr_debug("failed to mmap event: %d (%s)\n", errno,80 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)));
82 goto out_delete_evlist;82 goto out_delete_evlist;
83 }83 }
84 84
tools/perf/tests/task-exit.c+2−2
@@ -91,13 +91,13 @@ int test__task_exit(int subtest __maybe_unused) · 90 unmodified lines
91 err = perf_evlist__open(evlist);91 err = perf_evlist__open(evlist);
92 if (err < 0) {92 if (err < 0) {
93 pr_debug("Couldn't open the evlist: %s\n",93 pr_debug("Couldn't open the evlist: %s\n",
94 strerror_r(-err, sbuf, sizeof(sbuf)));94 str_error_r(-err, sbuf, sizeof(sbuf)));
95 goto out_delete_evlist;95 goto out_delete_evlist;
96 }96 }
97 97
98 if (perf_evlist__mmap(evlist, 128, true) < 0) {98 if (perf_evlist__mmap(evlist, 128, true) < 0) {
99 pr_debug("failed to mmap events: %d (%s)\n", errno,99 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)));
101 goto out_delete_evlist;101 goto out_delete_evlist;
102 }102 }
103 103
tools/perf/ui/browsers/hists.c+1−1
@@ -2029,7 +2029,7 @@ static int hist_browser__dump(struct hist_browser *browser) · 2028 unmodified lines
2029 fp = fopen(filename, "w");2029 fp = fopen(filename, "w");
2030 if (fp == NULL) {2030 if (fp == NULL) {
2031 char bf[64];2031 char bf[64];
2032 const char *err = strerror_r(errno, bf, sizeof(bf));2032 const char *err = str_error_r(errno, bf, sizeof(bf));
2033 ui_helpline__fpush("Couldn't write to %s: %s", filename, err);2033 ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
2034 return -1;2034 return -1;
2035 }2035 }
tools/perf/util/Build+5−0
@@ -70,6 +70,7 @@ libperf-y += stat.o · 69 unmodified lines
70libperf-y += stat-shadow.o70libperf-y += stat-shadow.o
71libperf-y += record.o71libperf-y += record.o
72libperf-y += srcline.o72libperf-y += srcline.o
73libperf-y += str_error_r.o
73libperf-y += data.o74libperf-y += data.o
74libperf-y += tsc.o75libperf-y += tsc.o
75libperf-y += cloexec.o76libperf-y += cloexec.o
@@ -173,6 +174,10 @@ $(OUTPUT)util/libstring.o: ../lib/string.c FORCE · 97 unmodified lines
173 $(call rule_mkdir)174 $(call rule_mkdir)
174 $(call if_changed_dep,cc_o_c)175 $(call if_changed_dep,cc_o_c)
175 176
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
176$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE181$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
177 $(call rule_mkdir)182 $(call rule_mkdir)
178 $(call if_changed_dep,cc_o_c)183 $(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
1589 snprintf(buf, size, "Unknown bpf loader error %d", err);1589 snprintf(buf, size, "Unknown bpf loader error %d", err);
1590 else1590 else
1591 snprintf(buf, size, "%s",1591 snprintf(buf, size, "%s",
1592 strerror_r(err, sbuf, sizeof(sbuf)));1592 str_error_r(err, sbuf, sizeof(sbuf)));
1593 1593
1594 buf[size - 1] = '\0';1594 buf[size - 1] = '\0';
1595 return -1;1595 return -1;
tools/perf/util/cloexec.c+2−2
@@ -58,7 +58,7 @@ static int perf_flag_probe(void) · 57 unmodified lines
58 58
59 WARN_ONCE(err != EINVAL && err != EBUSY,59 WARN_ONCE(err != EINVAL && err != EBUSY,
60 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",60 "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)));
62 62
63 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */63 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
64 while (1) {64 while (1) {
@@ -76,7 +76,7 @@ static int perf_flag_probe(void) · 11 unmodified lines
76 76
77 if (WARN_ONCE(fd < 0 && err != EBUSY,77 if (WARN_ONCE(fd < 0 && err != EBUSY,
78 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",78 "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))))
80 return -1;80 return -1;
81 81
82 return 0;82 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
57 int err = errno;57 int err = errno;
58 58
59 pr_err("failed to open %s: %s", file->path,59 pr_err("failed to open %s: %s", file->path,
60 strerror_r(err, sbuf, sizeof(sbuf)));60 str_error_r(err, sbuf, sizeof(sbuf)));
61 if (err == ENOENT && !strcmp(file->path, "perf.data"))61 if (err == ENOENT && !strcmp(file->path, "perf.data"))
62 pr_err(" (try 'perf record' first)");62 pr_err(" (try 'perf record' first)");
63 pr_err("\n");63 pr_err("\n");
@@ -99,7 +99,7 @@ static int open_file_write(struct perf_data_file *file) · 35 unmodified lines
99 99
100 if (fd < 0)100 if (fd < 0)
101 pr_err("failed to open %s : %s\n", file->path,101 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)));
103 103
104 return fd;104 return fd;
105}105}
tools/perf/util/debug.h+1−1
@@ -38,7 +38,7 @@ extern int debug_data_convert; · 37 unmodified lines
38#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)38#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
39#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)39#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
40 40
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 */
42 42
43int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));43int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
44void trace_event(union perf_event *event);44void 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
335 return fd;335 return fd;
336 336
337 pr_debug("dso open failed: %s\n",337 pr_debug("dso open failed: %s\n",
338 strerror_r(errno, sbuf, sizeof(sbuf)));338 str_error_r(errno, sbuf, sizeof(sbuf)));
339 if (!dso__data_open_cnt || errno != EMFILE)339 if (!dso__data_open_cnt || errno != EMFILE)
340 break;340 break;
341 341
@@ -786,7 +786,7 @@ static int data_file_size(struct dso *dso, struct machine *machine) · 444 unmodified lines
786 if (fstat(dso->data.fd, &st) < 0) {786 if (fstat(dso->data.fd, &st) < 0) {
787 ret = -errno;787 ret = -errno;
788 pr_err("dso cache fstat failed: %s\n",788 pr_err("dso cache fstat failed: %s\n",
789 strerror_r(errno, sbuf, sizeof(sbuf)));789 str_error_r(errno, sbuf, sizeof(sbuf)));
790 dso->data.status = DSO_DATA_STATUS_ERROR;790 dso->data.status = DSO_DATA_STATUS_ERROR;
791 goto out;791 goto out;
792 }792 }
@@ -1366,7 +1366,7 @@ int dso__strerror_load(struct dso *dso, char *buf, size_t buflen) · 573 unmodified lines
1366 BUG_ON(buflen == 0);1366 BUG_ON(buflen == 0);
1367 1367
1368 if (errnum >= 0) {1368 if (errnum >= 0) {
1369 const char *err = strerror_r(errnum, buf, buflen);1369 const char *err = str_error_r(errnum, buf, buflen);
1370 1370
1371 if (err != buf)1371 if (err != buf)
1372 scnprintf(buf, buflen, "%s", err);1372 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
1790 int err, char *buf, size_t size)1790 int err, char *buf, size_t size)
1791{1791{
1792 int printed, value;1792 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));
1794 1794
1795 switch (err) {1795 switch (err) {
1796 case EACCES:1796 case EACCES:
@@ -1842,7 +1842,7 @@ out_default: · 45 unmodified lines
1842 1842
1843int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)1843int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
1844{1844{
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));
1846 int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;1846 int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
1847 1847
1848 switch (err) {1848 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
2419 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"2419 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
2420 "/bin/dmesg may provide additional information.\n"2420 "/bin/dmesg may provide additional information.\n"
2421 "No CONFIG_PERF_EVENTS=y kernel support configured?",2421 "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)),
2423 perf_evsel__name(evsel));2423 perf_evsel__name(evsel));
2424}2424}
2425 2425
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
106 file = popen(cmd, "r");106 file = popen(cmd, "r");
107 if (!file) {107 if (!file) {
108 pr_err("ERROR: unable to popen cmd: %s\n",108 pr_err("ERROR: unable to popen cmd: %s\n",
109 strerror_r(errno, serr, sizeof(serr)));109 str_error_r(errno, serr, sizeof(serr)));
110 return -EINVAL;110 return -EINVAL;
111 }111 }
112 112
@@ -140,7 +140,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz) · 27 unmodified lines
140 140
141 if (ferror(file)) {141 if (ferror(file)) {
142 pr_err("ERROR: error occurred when reading from pipe: %s\n",142 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)));
144 err = -EIO;144 err = -EIO;
145 goto errout;145 goto errout;
146 }146 }
@@ -382,7 +382,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, · 235 unmodified lines
382 if (path[0] != '-' && realpath(path, abspath) == NULL) {382 if (path[0] != '-' && realpath(path, abspath) == NULL) {
383 err = errno;383 err = errno;
384 pr_err("ERROR: problems with path %s: %s\n",384 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)));
386 return -err;386 return -err;
387 }387 }
388 388
@@ -410,7 +410,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, · 21 unmodified lines
410 if (nr_cpus_avail <= 0) {410 if (nr_cpus_avail <= 0) {
411 pr_err(411 pr_err(
412"WARNING:\tunable to get available CPUs in this system: %s\n"412"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)));
414 nr_cpus_avail = 128;414 nr_cpus_avail = 128;
415 }415 }
416 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",416 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
468 err = kernel_get_module_dso(module, &dso);468 err = kernel_get_module_dso(module, &dso);
469 if (err < 0) {469 if (err < 0) {
470 if (!dso || dso->load_errno == 0) {470 if (!dso || dso->load_errno == 0) {
471 if (!strerror_r(-err, reason, STRERR_BUFSIZE))471 if (!str_error_r(-err, reason, STRERR_BUFSIZE))
472 strcpy(reason, "(unknown)");472 strcpy(reason, "(unknown)");
473 } else473 } else
474 dso__strerror_load(dso, reason, STRERR_BUFSIZE);474 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
806error:806error:
807 if (ferror(fp)) {807 if (ferror(fp)) {
808 pr_warning("File read error: %s\n",808 pr_warning("File read error: %s\n",
809 strerror_r(errno, sbuf, sizeof(sbuf)));809 str_error_r(errno, sbuf, sizeof(sbuf)));
810 return -1;810 return -1;
811 }811 }
812 return 0;812 return 0;
@@ -886,7 +886,7 @@ static int __show_line_range(struct line_range *lr, const char *module, · 73 unmodified lines
886 fp = fopen(lr->path, "r");886 fp = fopen(lr->path, "r");
887 if (fp == NULL) {887 if (fp == NULL) {
888 pr_warning("Failed to open %s: %s\n", lr->path,888 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)));
890 return -errno;890 return -errno;
891 }891 }
892 /* Skip to starting line number */892 /* 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
50 else50 else
51 pr_warning("Failed to open %cprobe_events: %s\n",51 pr_warning("Failed to open %cprobe_events: %s\n",
52 uprobe ? 'u' : 'k',52 uprobe ? 'u' : 'k',
53 strerror_r(-err, sbuf, sizeof(sbuf)));53 str_error_r(-err, sbuf, sizeof(sbuf)));
54}54}
55 55
56static void print_both_open_warning(int kerr, int uerr)56static 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
64 else {64 else {
65 char sbuf[STRERR_BUFSIZE];65 char sbuf[STRERR_BUFSIZE];
66 pr_warning("Failed to open kprobe events: %s.\n",66 pr_warning("Failed to open kprobe events: %s.\n",
67 strerror_r(-kerr, sbuf, sizeof(sbuf)));67 str_error_r(-kerr, sbuf, sizeof(sbuf)));
68 pr_warning("Failed to open uprobe events: %s.\n",68 pr_warning("Failed to open uprobe events: %s.\n",
69 strerror_r(-uerr, sbuf, sizeof(sbuf)));69 str_error_r(-uerr, sbuf, sizeof(sbuf)));
70 }70 }
71}71}
72 72
@@ -224,7 +224,7 @@ int probe_file__add_event(int fd, struct probe_trace_event *tev) · 151 unmodified lines
224 if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) {224 if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) {
225 ret = -errno;225 ret = -errno;
226 pr_warning("Failed to write event: %s\n",226 pr_warning("Failed to write event: %s\n",
227 strerror_r(errno, sbuf, sizeof(sbuf)));227 str_error_r(errno, sbuf, sizeof(sbuf)));
228 }228 }
229 }229 }
230 free(buf);230 free(buf);
@@ -262,7 +262,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) · 31 unmodified lines
262 return 0;262 return 0;
263error:263error:
264 pr_warning("Failed to delete event: %s\n",264 pr_warning("Failed to delete event: %s\n",
265 strerror_r(-ret, buf, sizeof(buf)));265 str_error_r(-ret, buf, sizeof(buf)));
266 return ret;266 return ret;
267}267}
268 268
tools/perf/util/probe-finder.c+2−2
@@ -381,7 +381,7 @@ formatted: · 380 unmodified lines
381 if (ret >= 16)381 if (ret >= 16)
382 ret = -E2BIG;382 ret = -E2BIG;
383 pr_warning("Failed to convert variable type: %s\n",383 pr_warning("Failed to convert variable type: %s\n",
384 strerror_r(-ret, sbuf, sizeof(sbuf)));384 str_error_r(-ret, sbuf, sizeof(sbuf)));
385 return ret;385 return ret;
386 }386 }
387 tvar->type = strdup(buf);387 tvar->type = strdup(buf);
@@ -809,7 +809,7 @@ static int find_lazy_match_lines(struct intlist *list, · 421 unmodified lines
809 fp = fopen(fname, "r");809 fp = fopen(fname, "r");
810 if (!fp) {810 if (!fp) {
811 pr_warning("Failed to open %s: %s\n", fname,811 pr_warning("Failed to open %s: %s\n", fname,
812 strerror_r(errno, sbuf, sizeof(sbuf)));812 str_error_r(errno, sbuf, sizeof(sbuf)));
813 return -errno;813 return -errno;
814 }814 }
815 815
tools/perf/util/python-ext-sources+1−0
@@ -13,6 +13,7 @@ util/cpumap.c · 12 unmodified lines
13../lib/bitmap.c13../lib/bitmap.c
14../lib/find_bit.c14../lib/find_bit.c
15../lib/hweight.c15../lib/hweight.c
16../lib/str_error_r.c
16util/thread_map.c17util/thread_map.c
17util/util.c18util/util.c
18util/xyarray.c19util/xyarray.c
tools/perf/util/target.c+1−1
@@ -121,7 +121,7 @@ int target__strerror(struct target *target, int errnum, · 120 unmodified lines
121 BUG_ON(buflen == 0);121 BUG_ON(buflen == 0);
122 122
123 if (errnum >= 0) {123 if (errnum >= 0) {
124 const char *err = strerror_r(errnum, buf, buflen);124 const char *err = str_error_r(errnum, buf, buflen);
125 125
126 if (err != buf)126 if (err != buf)
127 scnprintf(buf, buflen, "%s", err);127 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
360void print_binary(unsigned char *data, size_t len,360void print_binary(unsigned char *data, size_t len,
361 size_t bytes_per_line, print_binary_t printer,361 size_t bytes_per_line, print_binary_t printer,
362 void *extra);362 void *extra);
363
363#endif /* GIT_COMPAT_UTIL_H */364#endif /* GIT_COMPAT_UTIL_H */