tools: Introduce str_error_r()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 Jul 2016 14:56:20 +0000 (11:56 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Jul 2016 18:19:47 +0000 (15:19 -0300)
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.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4t42fnf48ytlk8rjxs822tf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
41 files changed:
tools/include/linux/string.h
tools/lib/str_error_r.c [new file with mode: 0644]
tools/perf/MANIFEST
tools/perf/arch/x86/tests/rdpmc.c
tools/perf/builtin-buildid-cache.c
tools/perf/builtin-help.c
tools/perf/builtin-kvm.c
tools/perf/builtin-probe.c
tools/perf/builtin-record.c
tools/perf/builtin-sched.c
tools/perf/builtin-stat.c
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/perf.c
tools/perf/tests/backward-ring-buffer.c
tools/perf/tests/bpf.c
tools/perf/tests/builtin-test.c
tools/perf/tests/event-times.c
tools/perf/tests/mmap-basic.c
tools/perf/tests/openat-syscall-all-cpus.c
tools/perf/tests/openat-syscall-tp-fields.c
tools/perf/tests/openat-syscall.c
tools/perf/tests/perf-record.c
tools/perf/tests/sw-clock.c
tools/perf/tests/task-exit.c
tools/perf/ui/browsers/hists.c
tools/perf/util/Build
tools/perf/util/bpf-loader.c
tools/perf/util/cloexec.c
tools/perf/util/data.c
tools/perf/util/debug.h
tools/perf/util/dso.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/llvm-utils.c
tools/perf/util/probe-event.c
tools/perf/util/probe-file.c
tools/perf/util/probe-finder.c
tools/perf/util/python-ext-sources
tools/perf/util/target.c
tools/perf/util/util.h

index e26223f1f2872fb1091d3e9352e491fce665ef5e..b466d0228b5793c624fe190cfec2484a7b615075 100644 (file)
@@ -12,4 +12,6 @@ int strtobool(const char *s, bool *res);
 extern size_t strlcpy(char *dest, const char *src, size_t size);
 #endif
 
+char *str_error_r(int errnum, char *buf, size_t buflen);
+
 #endif /* _LINUX_STRING_H_ */
diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
new file mode 100644 (file)
index 0000000..503ae07
--- /dev/null
@@ -0,0 +1,26 @@
+#undef _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include <linux/string.h>
+
+/*
+ * 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.
+ */
+char *str_error_r(int errnum, char *buf, size_t buflen)
+{
+       int err = strerror_r(errnum, buf, buflen);
+       if (err)
+               snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
+       return buf;
+}
index 8c8c6b9ce915341dfc01a02185a53b4198b7d790..f18e781447bccdf3b5e9be6e841c4a9a0b300ed4 100644 (file)
@@ -29,6 +29,7 @@ tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
 tools/lib/find_bit.c
 tools/lib/bitmap.c
+tools/lib/str_error_r.c
 tools/include/asm/atomic.h
 tools/include/asm/barrier.h
 tools/include/asm/bug.h
index 72193f19d6d75d3c32e19b424a0f1910ebbc24a6..a32d72e91ffa0c915a4cda48563786e2af5c3494 100644 (file)
@@ -111,14 +111,14 @@ static int __test__rdpmc(void)
        if (fd < 0) {
                pr_err("Error: sys_perf_event_open() syscall returned "
                       "with %d (%s)\n", fd,
-                      strerror_r(errno, sbuf, sizeof(sbuf)));
+                      str_error_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_r(errno, sbuf, sizeof(sbuf)));
+                      str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_close;
        }
 
index 76a4d03c7cd09e95f64fec0d568d19fa99622081..30e2b2cb2421219de6cc168483f5e9144af8036c 100644 (file)
@@ -351,7 +351,7 @@ int cmd_buildid_cache(int argc, const char **argv,
                                                continue;
                                        }
                                        pr_warning("Couldn't add %s: %s\n",
-                                                  pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
+                                                  pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
                                }
 
                        strlist__delete(list);
@@ -369,7 +369,7 @@ int cmd_buildid_cache(int argc, const char **argv,
                                                continue;
                                        }
                                        pr_warning("Couldn't remove %s: %s\n",
-                                                  pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
+                                                  pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
                                }
 
                        strlist__delete(list);
@@ -387,7 +387,7 @@ int cmd_buildid_cache(int argc, const char **argv,
                                                continue;
                                        }
                                        pr_warning("Couldn't remove %s: %s\n",
-                                                  pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
+                                                  pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
                                }
 
                        strlist__delete(list);
@@ -408,7 +408,7 @@ int cmd_buildid_cache(int argc, const char **argv,
                                                continue;
                                        }
                                        pr_warning("Couldn't update %s: %s\n",
-                                                  pos->s, strerror_r(errno, sbuf, sizeof(sbuf)));
+                                                  pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
                                }
 
                        strlist__delete(list);
index 268ab732b8aae9ac0d5b92d9c69bb9aaa7943b52..3bdb2c78a21b3f0118d0c7a376222b7bb96c4735 100644 (file)
@@ -117,7 +117,7 @@ static void exec_woman_emacs(const char *path, const char *page)
                        free(man_page);
                }
                warning("failed to exec '%s': %s", path,
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
        }
 }
 
@@ -150,7 +150,7 @@ static void exec_man_konqueror(const char *path, const char *page)
                        free(man_page);
                }
                warning("failed to exec '%s': %s", path,
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
        }
 }
 
@@ -162,7 +162,7 @@ static void exec_man_man(const char *path, const char *page)
                path = "man";
        execlp(path, "man", page, NULL);
        warning("failed to exec '%s': %s", path,
-               strerror_r(errno, sbuf, sizeof(sbuf)));
+               str_error_r(errno, sbuf, sizeof(sbuf)));
 }
 
 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)
                free(shell_cmd);
        }
        warning("failed to exec '%s': %s", cmd,
-               strerror_r(errno, sbuf, sizeof(sbuf)));
+               str_error_r(errno, sbuf, sizeof(sbuf)));
 }
 
 static void add_man_viewer(const char *name)
index f4efef9d1eb3e58bd40f1896561c37f298c0c765..5e2127e04f8386c4aa92b62e0370afff08d9e9b5 100644 (file)
@@ -1018,13 +1018,13 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                printf("Couldn't create the events: %s\n",
-                      strerror_r(errno, sbuf, sizeof(sbuf)));
+                      str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out;
        }
 
        if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) {
                ui__error("Failed to mmap the events: %s\n",
-                         strerror_r(errno, sbuf, sizeof(sbuf)));
+                         str_error_r(errno, sbuf, sizeof(sbuf)));
                perf_evlist__close(evlist);
                goto out;
        }
index a1a5cd1b8d601275ea8404e48588be0629dae775..c6d890ad2c1a202da7f7b39841dff52f62077871 100644 (file)
@@ -308,7 +308,7 @@ static void pr_err_with_code(const char *msg, int err)
 
        pr_err("%s", msg);
        pr_debug(" Reason: %s (Code: %d)",
-                strerror_r(-err, sbuf, sizeof(sbuf)), err);
+                str_error_r(-err, sbuf, sizeof(sbuf)), err);
        pr_err("\n");
 }
 
index b2b3b600adf536a9b94551c6e68e402e858dfd20..d9f5cc3a36679c30fe2b18344a6cecb834d81f99 100644 (file)
@@ -361,7 +361,7 @@ static int record__mmap_evlist(struct record *rec,
                        return -errno;
                } else {
                        pr_err("failed to mmap with %d (%s)\n", errno,
-                               strerror_r(errno, msg, sizeof(msg)));
+                               str_error_r(errno, msg, sizeof(msg)));
                        if (errno)
                                return -errno;
                        else
@@ -407,7 +407,7 @@ try_again:
        if (perf_evlist__apply_filters(evlist, &pos)) {
                error("failed to set filter \"%s\" on event %s with %d (%s)\n",
                        pos->filter, perf_evsel__name(pos), errno,
-                       strerror_r(errno, msg, sizeof(msg)));
+                       str_error_r(errno, msg, sizeof(msg)));
                rc = -1;
                goto out;
        }
@@ -1003,7 +1003,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
        if (forks && workload_exec_errno) {
                char msg[STRERR_BUFSIZE];
-               const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
+               const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
                pr_err("Workload failed: %s\n", emsg);
                err = -1;
                goto out_child;
index afa057666c2adf68ec1279dc29a027744ec38fff..0dfe8df2ab9b237b2530bbb4c81967b9eac6a689 100644 (file)
@@ -494,7 +494,7 @@ force_again:
                }
                pr_err("Error: sys_perf_event_open() syscall returned "
                       "with %d (%s)\n%s", fd,
-                      strerror_r(errno, sbuf, sizeof(sbuf)), info);
+                      str_error_r(errno, sbuf, sizeof(sbuf)), info);
                exit(EXIT_FAILURE);
        }
        return fd;
index c367a43525e6e77156fe9448d954d420fcd54191..8c5a3bfdfdd7348215d970dbe2916ac454355bef 100644 (file)
@@ -596,7 +596,7 @@ try_again:
        if (perf_evlist__apply_filters(evsel_list, &counter)) {
                error("failed to set filter \"%s\" on event %s with %d (%s)\n",
                        counter->filter, perf_evsel__name(counter), errno,
-                       strerror_r(errno, msg, sizeof(msg)));
+                       str_error_r(errno, msg, sizeof(msg)));
                return -1;
        }
 
@@ -637,7 +637,7 @@ try_again:
                wait(&status);
 
                if (workload_exec_errno) {
-                       const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
+                       const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
                        pr_err("Workload failed: %s\n", emsg);
                        return -1;
                }
index 07fc7921980c053829ec9270e339892714058cfa..bd108683fcb87d30a45bda771f2ad665c59723cf 100644 (file)
@@ -907,7 +907,7 @@ try_again:
 
        if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
                ui__error("Failed to mmap with %d (%s)\n",
-                           errno, strerror_r(errno, msg, sizeof(msg)));
+                           errno, str_error_r(errno, msg, sizeof(msg)));
                goto out_err;
        }
 
@@ -1028,7 +1028,7 @@ out_delete:
 
 out_err_cpu_topo: {
        char errbuf[BUFSIZ];
-       const char *err = strerror_r(-ret, errbuf, sizeof(errbuf));
+       const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
 
        ui__error("Could not read the CPU topology map: %s\n", err);
        goto out_delete;
@@ -1295,7 +1295,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 
        if (perf_evlist__create_maps(top.evlist, target) < 0) {
                ui__error("Couldn't create thread/CPU maps: %s\n",
-                         errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf)));
+                         errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
                goto out_delete_evlist;
        }
 
index cf90de811523b78289ef4224fd3b66f767f474c7..e7e0b6e306b7c9e3731fb2d84b76934e7d065e82 100644 (file)
@@ -1601,7 +1601,7 @@ signed_print:
                fprintf(trace->output, ") = %ld", ret);
        } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {
                char bf[STRERR_BUFSIZE];
-               const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
+               const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
                           *e = audit_errno_to_name(-ret);
 
                fprintf(trace->output, ") = -1 %s %s", e, emsg);
@@ -2402,7 +2402,7 @@ out_error_apply_filters:
        fprintf(trace->output,
                "Failed to set filter \"%s\" on event %s with %d (%s)\n",
                evsel->filter, perf_evsel__name(evsel), errno,
-               strerror_r(errno, errbuf, sizeof(errbuf)));
+               str_error_r(errno, errbuf, sizeof(errbuf)));
        goto out_delete_evlist;
 }
 out_error_mem:
index 8f219223f305eed5277d322ef743b532e0185295..f7d7dbbd2af670669ff89e6ab6a3c19f91d0bcb4 100644 (file)
@@ -374,7 +374,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        /* Check for ENOSPC and EIO errors.. */
        if (fflush(stdout)) {
                fprintf(stderr, "write failure on standard output: %s",
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out;
        }
        if (ferror(stdout)) {
@@ -383,7 +383,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        }
        if (fclose(stdout)) {
                fprintf(stderr, "close failed on standard output: %s",
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out;
        }
        status = 0;
@@ -615,7 +615,7 @@ int main(int argc, const char **argv)
        }
 
        fprintf(stderr, "Failed to run command '%s': %s\n",
-               cmd, strerror_r(errno, sbuf, sizeof(sbuf)));
+               cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
 out:
        return 1;
 }
index e70313fac5a55225cbc089fd51f4c5daff2278ea..f20ea4c0d0cb9c551c2726a23aa9857c6135882c 100644 (file)
@@ -60,7 +60,7 @@ static int do_test(struct perf_evlist *evlist, int mmap_pages,
        err = perf_evlist__mmap(evlist, mmap_pages, true);
        if (err < 0) {
                pr_debug("perf_evlist__mmap: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                return TEST_FAIL;
        }
 
@@ -124,7 +124,7 @@ int test__backward_ring_buffer(int subtest __maybe_unused)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index f31eed31c1a9cff8e8307a1f06c3013329871ec6..da0d876139752dc79c7d7617eb4dfda75dc1dc86 100644 (file)
@@ -143,14 +143,14 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
        err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
        if (err < 0) {
                pr_debug("perf_evlist__mmap: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 07c14e9f654664ca488a00bcc13a5714b3fa20b8..c23cbf7335498b8f04ee413de49ec5fa8190d5e0 100644 (file)
@@ -258,7 +258,7 @@ static int run_test(struct test *test, int subtest)
 
        if (child < 0) {
                pr_err("failed to fork test: %s\n",
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
                return -1;
        }
 
index 9f5698ac81ae2373461db58d40a2e742712b96bc..19ef77bd6eb4152b539dc46638d4ef3a8db972e3 100644 (file)
@@ -37,7 +37,7 @@ static int attach__enable_on_exec(struct perf_evlist *evlist)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                return err;
        }
 
index aea33f5589c5b4ddc307a8746205145ae5994cea..5c9b931b7b66ad97e1899b48cb92557eead44235 100644 (file)
@@ -49,7 +49,7 @@ int test__basic_mmap(int subtest __maybe_unused)
        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_r(errno, sbuf, sizeof(sbuf)));
+                        cpus->map[0], str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_free_cpus;
        }
 
@@ -79,7 +79,7 @@ int test__basic_mmap(int subtest __maybe_unused)
                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_r(errno, sbuf, sizeof(sbuf)));
+                                str_error_r(errno, sbuf, sizeof(sbuf)));
                        goto out_delete_evlist;
                }
 
@@ -89,7 +89,7 @@ int test__basic_mmap(int subtest __maybe_unused)
 
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
                pr_debug("failed to mmap events: %d (%s)\n", errno,
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index ad1cb63139a79af0b176fe312294798d487aa2be..265abb12dfffc14fca968fdc948448a7a6e3524a 100644 (file)
@@ -41,7 +41,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused)
        if (perf_evsel__open(evsel, cpus, threads) < 0) {
                pr_debug("failed to open counter: %s, "
                         "tweak /proc/sys/kernel/perf_event_paranoid?\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_evsel_delete;
        }
 
@@ -62,7 +62,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused)
                if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
                        pr_debug("sched_setaffinity() failed on CPU %d: %s ",
                                 cpus->map[cpu],
-                                strerror_r(errno, sbuf, sizeof(sbuf)));
+                                str_error_r(errno, sbuf, sizeof(sbuf)));
                        goto out_close_fd;
                }
                for (i = 0; i < ncalls; ++i) {
index 4344fe482c1d2f9a9dec676e236d3200e372e78f..942dbf43d7c746745d1503d1dc59257d98bab282 100644 (file)
@@ -51,14 +51,14 @@ int test__syscall_openat_tp_fields(int subtest __maybe_unused)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_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_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 1184f9ba649927826f3e96cbeb734404e08ae9be..d7414128d7fe40d150dcb2424082dd858f6779d1 100644 (file)
@@ -29,7 +29,7 @@ int test__openat_syscall_event(int subtest __maybe_unused)
        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_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_evsel_delete;
        }
 
index b836ee6a8d9bb6a676f65bcfa5243fef840c73e0..3eb67a977b6ae604bd807b037912edb662fca648 100644 (file)
@@ -104,7 +104,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
        err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
        if (err < 0) {
                pr_debug("sched__get_first_possible_cpu: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -115,7 +115,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
         */
        if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
                pr_debug("sched_setaffinity: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -126,7 +126,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -138,7 +138,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
        err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
        if (err < 0) {
                pr_debug("perf_evlist__mmap: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 36e8ce1550e30f3769cf0c32c60439d8aa750f7a..4c9fd046d57b1772422747fbf7deea8be036d68f 100644 (file)
@@ -70,7 +70,7 @@ 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_r(errno, sbuf, sizeof(sbuf)),
+                        str_error_r(errno, sbuf, sizeof(sbuf)),
                         knob, (u64)attr.sample_freq);
                goto out_delete_evlist;
        }
@@ -78,7 +78,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
        err = perf_evlist__mmap(evlist, 128, true);
        if (err < 0) {
                pr_debug("failed to mmap event: %d (%s)\n", errno,
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 2dfff7ac8ef31eae49b01b62c024ff4ddcf246dc..01a5ba2788c604c8c6b6c6e9f0a0364444f90da0 100644 (file)
@@ -91,13 +91,13 @@ int test__task_exit(int subtest __maybe_unused)
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("Couldn't open the evlist: %s\n",
-                        strerror_r(-err, sbuf, sizeof(sbuf)));
+                        str_error_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_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index e08b8f7b6d3f34fb4e88bd0c3bd37d06e858f30b..13d414384739d9673089958aa2daa56de9a5b255 100644 (file)
@@ -2029,7 +2029,7 @@ static int hist_browser__dump(struct hist_browser *browser)
        fp = fopen(filename, "w");
        if (fp == NULL) {
                char bf[64];
-               const char *err = strerror_r(errno, bf, sizeof(bf));
+               const char *err = str_error_r(errno, bf, sizeof(bf));
                ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
                return -1;
        }
index fced8336e5fd3b27d0e7d9f9c2d08b303e4c2482..a6a80530231205386b557ceb1fe8237afa6017e4 100644 (file)
@@ -70,6 +70,7 @@ libperf-y += stat.o
 libperf-y += stat-shadow.o
 libperf-y += record.o
 libperf-y += srcline.o
+libperf-y += str_error_r.o
 libperf-y += data.o
 libperf-y += tsc.o
 libperf-y += cloexec.o
@@ -173,6 +174,10 @@ $(OUTPUT)util/libstring.o: ../lib/string.c FORCE
        $(call rule_mkdir)
        $(call if_changed_dep,cc_o_c)
 
+$(OUTPUT)util/str_error_r.o: ../lib/str_error_r.c FORCE
+       $(call rule_mkdir)
+       $(call if_changed_dep,cc_o_c)
+
 $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
        $(call rule_mkdir)
        $(call if_changed_dep,cc_o_c)
index dcc8845881aec9bea6ca1220669d89ad83b4c02b..8445e89621fe98e79d2e41f4eb35dea8360c9658 100644 (file)
@@ -1589,7 +1589,7 @@ bpf_loader_strerror(int err, char *buf, size_t size)
                snprintf(buf, size, "Unknown bpf loader error %d", err);
        else
                snprintf(buf, size, "%s",
-                        strerror_r(err, sbuf, sizeof(sbuf)));
+                        str_error_r(err, sbuf, sizeof(sbuf)));
 
        buf[size - 1] = '\0';
        return -1;
index 2babddaa24813102c0c9d7525ec8ab615b621775..fde772db1d5c0852f95b089d3ee5d2221a8907d6 100644 (file)
@@ -58,7 +58,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_r(err, sbuf, sizeof(sbuf)));
+                 err, str_error_r(err, sbuf, sizeof(sbuf)));
 
        /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
        while (1) {
@@ -76,7 +76,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_r(err, sbuf, sizeof(sbuf))))
+                     err, str_error_r(err, sbuf, sizeof(sbuf))))
                return -1;
 
        return 0;
index be83516155ee5d7914d699b48df33441b7f6f345..60bfc9ca1e22f3a1b10d58169d2ed70ccfe040cc 100644 (file)
@@ -57,7 +57,7 @@ static int open_file_read(struct perf_data_file *file)
                int err = errno;
 
                pr_err("failed to open %s: %s", file->path,
-                       strerror_r(err, sbuf, sizeof(sbuf)));
+                       str_error_r(err, sbuf, sizeof(sbuf)));
                if (err == ENOENT && !strcmp(file->path, "perf.data"))
                        pr_err("  (try 'perf record' first)");
                pr_err("\n");
@@ -99,7 +99,7 @@ static int open_file_write(struct perf_data_file *file)
 
        if (fd < 0)
                pr_err("failed to open %s : %s\n", file->path,
-                       strerror_r(errno, sbuf, sizeof(sbuf)));
+                       str_error_r(errno, sbuf, sizeof(sbuf)));
 
        return fd;
 }
index 14bafda79edaeba1bbd3e007b5faa8607d0570bf..d242adc3d5a2ac7217879a37d0f5ed26b344351a 100644 (file)
@@ -38,7 +38,7 @@ extern int debug_data_convert;
 #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 */
+#define STRERR_BUFSIZE 128     /* For the buffer size of str_error_r */
 
 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void trace_event(union perf_event *event);
index e1de6cc4863e89f3b1979140eb9b0a0e7b3402e5..774f6ec884d50cf0d2d3696689e0ca8c4e8e27c5 100644 (file)
@@ -335,7 +335,7 @@ static int do_open(char *name)
                        return fd;
 
                pr_debug("dso open failed: %s\n",
-                        strerror_r(errno, sbuf, sizeof(sbuf)));
+                        str_error_r(errno, sbuf, sizeof(sbuf)));
                if (!dso__data_open_cnt || errno != EMFILE)
                        break;
 
@@ -786,7 +786,7 @@ static int data_file_size(struct dso *dso, struct machine *machine)
        if (fstat(dso->data.fd, &st) < 0) {
                ret = -errno;
                pr_err("dso cache fstat failed: %s\n",
-                      strerror_r(errno, sbuf, sizeof(sbuf)));
+                      str_error_r(errno, sbuf, sizeof(sbuf)));
                dso->data.status = DSO_DATA_STATUS_ERROR;
                goto out;
        }
@@ -1366,7 +1366,7 @@ int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
        BUG_ON(buflen == 0);
 
        if (errnum >= 0) {
-               const char *err = strerror_r(errnum, buf, buflen);
+               const char *err = str_error_r(errnum, buf, buflen);
 
                if (err != buf)
                        scnprintf(buf, buflen, "%s", err);
index 113507716044a31a697214e6dce35b46452911fa..f2d478df8c3e40bcc661ace6d54c94a0189855da 100644 (file)
@@ -1790,7 +1790,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist,
                               int err, char *buf, size_t size)
 {
        int printed, value;
-       char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
+       char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
 
        switch (err) {
        case EACCES:
@@ -1842,7 +1842,7 @@ out_default:
 
 int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
 {
-       char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
+       char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
        int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
 
        switch (err) {
index 0fea724e735c34fb83fcc908bb63615e5e2c1fa0..d8c2298cd32a350a74ef2211c2611d11e927e61d 100644 (file)
@@ -2419,7 +2419,7 @@ 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"
        "/bin/dmesg may provide additional information.\n"
        "No CONFIG_PERF_EVENTS=y kernel support configured?",
-                        err, strerror_r(err, sbuf, sizeof(sbuf)),
+                        err, str_error_r(err, sbuf, sizeof(sbuf)),
                         perf_evsel__name(evsel));
 }
 
index 40b6f7269cb4cbc8c905929cd46a35614ca8dfb3..282c30f6a51d93e03d7e32962735dc3f4c2026c2 100644 (file)
@@ -106,7 +106,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
        file = popen(cmd, "r");
        if (!file) {
                pr_err("ERROR: unable to popen cmd: %s\n",
-                      strerror_r(errno, serr, sizeof(serr)));
+                      str_error_r(errno, serr, sizeof(serr)));
                return -EINVAL;
        }
 
@@ -140,7 +140,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
 
        if (ferror(file)) {
                pr_err("ERROR: error occurred when reading from pipe: %s\n",
-                      strerror_r(errno, serr, sizeof(serr)));
+                      str_error_r(errno, serr, sizeof(serr)));
                err = -EIO;
                goto errout;
        }
@@ -382,7 +382,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
        if (path[0] != '-' && realpath(path, abspath) == NULL) {
                err = errno;
                pr_err("ERROR: problems with path %s: %s\n",
-                      path, strerror_r(err, serr, sizeof(serr)));
+                      path, str_error_r(err, serr, sizeof(serr)));
                return -err;
        }
 
@@ -410,7 +410,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
        if (nr_cpus_avail <= 0) {
                pr_err(
 "WARNING:\tunable to get available CPUs in this system: %s\n"
-"        \tUse 128 instead.\n", strerror_r(errno, serr, sizeof(serr)));
+"        \tUse 128 instead.\n", str_error_r(errno, serr, sizeof(serr)));
                nr_cpus_avail = 128;
        }
        snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
index 0201f661ccb8216ecb347c8355cf5ac15500b0be..2b222a7955c9b1068cd74ff4dd6911ab6d2da9c6 100644 (file)
@@ -468,7 +468,7 @@ static struct debuginfo *open_debuginfo(const char *module, bool silent)
                err = kernel_get_module_dso(module, &dso);
                if (err < 0) {
                        if (!dso || dso->load_errno == 0) {
-                               if (!strerror_r(-err, reason, STRERR_BUFSIZE))
+                               if (!str_error_r(-err, reason, STRERR_BUFSIZE))
                                        strcpy(reason, "(unknown)");
                        } else
                                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)
 error:
        if (ferror(fp)) {
                pr_warning("File read error: %s\n",
-                          strerror_r(errno, sbuf, sizeof(sbuf)));
+                          str_error_r(errno, sbuf, sizeof(sbuf)));
                return -1;
        }
        return 0;
@@ -886,7 +886,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_r(errno, sbuf, sizeof(sbuf)));
+                          str_error_r(errno, sbuf, sizeof(sbuf)));
                return -errno;
        }
        /* Skip to starting line number */
index 5b563b2e8b1d14486a2f4e49e836465ea5c41e14..98398b55a03f4cd5ccf699fd5f367d5fc553f002 100644 (file)
@@ -50,7 +50,7 @@ static void print_open_warning(int err, bool uprobe)
        else
                pr_warning("Failed to open %cprobe_events: %s\n",
                           uprobe ? 'u' : 'k',
-                          strerror_r(-err, sbuf, sizeof(sbuf)));
+                          str_error_r(-err, sbuf, sizeof(sbuf)));
 }
 
 static void print_both_open_warning(int kerr, int uerr)
@@ -64,9 +64,9 @@ static void print_both_open_warning(int kerr, int uerr)
        else {
                char sbuf[STRERR_BUFSIZE];
                pr_warning("Failed to open kprobe events: %s.\n",
-                          strerror_r(-kerr, sbuf, sizeof(sbuf)));
+                          str_error_r(-kerr, sbuf, sizeof(sbuf)));
                pr_warning("Failed to open uprobe events: %s.\n",
-                          strerror_r(-uerr, sbuf, sizeof(sbuf)));
+                          str_error_r(-uerr, sbuf, sizeof(sbuf)));
        }
 }
 
@@ -224,7 +224,7 @@ int probe_file__add_event(int fd, struct probe_trace_event *tev)
                if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) {
                        ret = -errno;
                        pr_warning("Failed to write event: %s\n",
-                                  strerror_r(errno, sbuf, sizeof(sbuf)));
+                                  str_error_r(errno, sbuf, sizeof(sbuf)));
                }
        }
        free(buf);
@@ -262,7 +262,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
        return 0;
 error:
        pr_warning("Failed to delete event: %s\n",
-                  strerror_r(-ret, buf, sizeof(buf)));
+                  str_error_r(-ret, buf, sizeof(buf)));
        return ret;
 }
 
index 1259839dbf6d4982cdb814edbc164f1439764a97..f2d9ff064e2de720247e77f9645faf94b6b4ce57 100644 (file)
@@ -381,7 +381,7 @@ formatted:
                if (ret >= 16)
                        ret = -E2BIG;
                pr_warning("Failed to convert variable type: %s\n",
-                          strerror_r(-ret, sbuf, sizeof(sbuf)));
+                          str_error_r(-ret, sbuf, sizeof(sbuf)));
                return ret;
        }
        tvar->type = strdup(buf);
@@ -809,7 +809,7 @@ static int find_lazy_match_lines(struct intlist *list,
        fp = fopen(fname, "r");
        if (!fp) {
                pr_warning("Failed to open %s: %s\n", fname,
-                          strerror_r(errno, sbuf, sizeof(sbuf)));
+                          str_error_r(errno, sbuf, sizeof(sbuf)));
                return -errno;
        }
 
index 36c6862119e32c1fabd5001b892eb9bac0bd3ed9..49210b7a7925bd970d0cbdc7a31eac657881335a 100644 (file)
@@ -13,6 +13,7 @@ util/cpumap.c
 ../lib/bitmap.c
 ../lib/find_bit.c
 ../lib/hweight.c
+../lib/str_error_r.c
 util/thread_map.c
 util/util.c
 util/xyarray.c
index a53603b27e525864eeb328e934ba696dc3ea7e6e..5898af4510ccf1cb8e8ed8fed93405fdde4e1a0d 100644 (file)
@@ -121,7 +121,7 @@ int target__strerror(struct target *target, int errnum,
        BUG_ON(buflen == 0);
 
        if (errnum >= 0) {
-               const char *err = strerror_r(errnum, buf, buflen);
+               const char *err = str_error_r(errnum, buf, buflen);
 
                if (err != buf)
                        scnprintf(buf, buflen, "%s", err);
index 1e8c3167b9fb3ab070c05974fb028445600c6574..2370cfb902b29e37e051ac5fb0df99aeae8bcf0a 100644 (file)
@@ -360,4 +360,5 @@ typedef void (*print_binary_t)(enum binary_printer_ops,
 void print_binary(unsigned char *data, size_t len,
                  size_t bytes_per_line, print_binary_t printer,
                  void *extra);
+
 #endif /* GIT_COMPAT_UTIL_H */