All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [PATCH 2/2] perf: use XSI-complaint version of strerror_r() instead of GNU-specific
Date: Mon, 23 Jul 2012 18:00:45 +0300	[thread overview]
Message-ID: <1343055645-24083-2-git-send-email-kirill@shutemov.name> (raw)
In-Reply-To: <1343055645-24083-1-git-send-email-kirill@shutemov.name>

From: "Kirill A. Shutemov" <kirill@shutemov.name>

Perf uses GNU-specific version of strerror_r(). The GNU-specific
strerror_r() returns a pointer to a string containing the error message.
This may be either a pointer to a string that the function stores in
buf, or a pointer to some (immutable) static string (in which case buf
is unused).

In glibc-2.16 GNU version was marked with attribute warn_unused_result.
It triggers few warnings in perf:

util/target.c: In function ‘perf_target__strerror’:
util/target.c:114:13: error: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Werror=unused-result]
ui/browsers/hists.c: In function ‘hist_browser__dump’:
ui/browsers/hists.c:981:13: error: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Werror=unused-result]

They are bugs.

The right way to fix it is to switch to XSI-compliant version.
Unfortunately, glibc doesn't allow to get XSI-complaint strerror_r() and
_GNU_SOURCE at the same time.

Let's bundle XSI-complaint version to perf and use it.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 tools/perf/ui/browsers/hists.c |  2 +-
 tools/perf/util/string.c       | 25 +++++++++++++++++++++++++
 tools/perf/util/target.c       |  3 ++-
 tools/perf/util/util.h         |  1 +
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 482f051..8bd1780 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -978,7 +978,7 @@ static int hist_browser__dump(struct hist_browser *browser)
 	fp = fopen(filename, "w");
 	if (fp == NULL) {
 		char bf[64];
-		strerror_r(errno, bf, sizeof(bf));
+		xsi_strerror_r(errno, bf, sizeof(bf));
 		ui_helpline__fpush("Couldn't write to %s: %s", filename, bf);
 		return -1;
 	}
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 199bc4d..71b68b9 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,5 +1,6 @@
 #include "util.h"
 #include "string.h"
+#include <linux/kernel.h>
 
 #define K 1024LL
 /*
@@ -335,3 +336,27 @@ char *rtrim(char *s)
 
 	return s;
 }
+
+/**
+ * xsi_strerror_r() - XSI-compliant version of strerror_r()
+ */
+int xsi_strerror_r(int errnum, char *buf, size_t buflen)
+{
+	const char *p;
+	size_t len;
+
+	/* GNU-specific version of strerror_r() */
+	p = strerror_r(errnum, buf, buflen);
+
+	/* glibc use the buffer only if errnum is not correct */
+	if (p == buf)
+		return EINVAL;
+
+	len = strlen(p);
+	if (buflen > 0) {
+		char *c = mempcpy(buf, p, min(buflen - 1, len));
+		*c = '\0';
+	}
+
+	return buflen > len ? 0 : ERANGE;
+}
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index 1064d5b..0ec1a30 100644
--- a/tools/perf/util/target.c
+++ b/tools/perf/util/target.c
@@ -8,6 +8,7 @@
 
 #include "target.h"
 #include "debug.h"
+#include "util.h"
 
 #include <pwd.h>
 #include <string.h>
@@ -111,7 +112,7 @@ int perf_target__strerror(struct perf_target *target, int errnum,
 	const char *msg;
 
 	if (errnum >= 0) {
-		strerror_r(errnum, buf, buflen);
+		xsi_strerror_r(errnum, buf, buflen);
 		return 0;
 	}
 
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index b13c733..3e85d63 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -265,5 +265,6 @@ bool is_power_of_2(unsigned long n)
 size_t hex_width(u64 v);
 
 char *rtrim(char *s);
+int xsi_strerror_r(int errnum, char *buf, size_t buflen);
 
 #endif
-- 
1.7.11.2


  reply	other threads:[~2012-07-23 15:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-23 15:00 [PATCH 1/2] perf: fix build error Kirill A. Shutemov
2012-07-23 15:00 ` Kirill A. Shutemov [this message]
2012-07-23 18:00   ` [PATCH 2/2] perf: use XSI-complaint version of strerror_r() instead of GNU-specific Ulrich Drepper
2012-07-23 20:31     ` Kirill A. Shutemov
2012-07-23 20:48       ` Ulrich Drepper
2012-07-23 21:06         ` Kirill A. Shutemov
2012-07-23 22:03           ` Ulrich Drepper
2012-07-24  0:56           ` Namhyung Kim
2012-07-25 19:30           ` [tip:perf/core] perf tools: " tip-bot for Kirill A. Shutemov
2012-07-23 18:02 ` [PATCH 1/2] perf: fix build error Arnaldo Carvalho de Melo
2012-07-23 18:16   ` Kirill A. Shutemov
2012-07-23 18:18     ` Arnaldo Carvalho de Melo
2012-07-23 19:51       ` Kirill A. Shutemov
2012-07-23 21:04         ` Kirill A. Shutemov
2012-07-24  0:38           ` Namhyung Kim
2012-07-25 19:30           ` [tip:perf/core] perf tools: Fix build error with bison 2.6 tip-bot for Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343055645-24083-2-git-send-email-kirill@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --subject='Re: [PATCH 2/2] perf: use XSI-complaint version of strerror_r() instead of GNU-specific' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.