linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>,
	Colin Patrick McCabe <cmccabe@alumni.cmu.edu>
Subject: [PATCH v3] tools/lib/traceevent: Replace str_error_r() with an open coded implementation
Date: Tue, 2 Oct 2018 17:55:39 -0400	[thread overview]
Message-ID: <20181002175539.2ac894c7@gandalf.local.home> (raw)


From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

While working on having PowerTop use libtracevent as a shared object
library, Tzvetomir hit "str_error_r not defined". This was added by commit
c3cec9e68f12d ("tools lib traceevent: Use str_error_r()") because
strerror_r() has two definitions, where one is GNU specific, and the other
is XSI complient. The strerror_r() is in a wrapper str_error_r() to keep the
code from having to worry about which compiler is being used.

The problem is that str_error_r() is external to libtraceevent, and not part
of the library. If it is used as a shared object then the tools using it
will need to define that function. I do not want that function defined in
libtraceevent itself, as it is out of scope for that library.

As there's only a single instance of this call, I replaced it with an open
coded algorithm that uses sys_nerr and sys_errlist error array with
strncpy() to place the error message in the given buffer. We don't need to
worry about the errors that strerror_r() returns. If the buffer isn't big
enough, we simply truncate it.

The sys_nerr and sys_errlist idea was found here:

  http://www.club.cc.cmu.edu/~cmccabe/blog_strerror.html

Cc: Colin Patrick McCabe <cmccabe@alumni.cmu.edu>
Reported-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Changes since v2:

  Use sys_nerr and sys_errlist idea.

 tools/lib/traceevent/event-parse.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 7980fc6c3bac..d23d10bc5314 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -18,7 +18,6 @@
 #include <errno.h>
 #include <stdint.h>
 #include <limits.h>
-#include <linux/string.h>
 #include <linux/time64.h>
 
 #include <netinet/in.h>
@@ -6215,7 +6214,13 @@ int tep_strerror(struct tep_handle *pevent __maybe_unused,
 	const char *msg;
 
 	if (errnum >= 0) {
-		str_error_r(errnum, buf, buflen);
+		if (buflen > 0) {
+			if (errnum < sys_nerr)
+				strncpy(buf, sys_errlist[errnum], buflen);
+			else
+				snprintf(buf, buflen, "Unknown error %d", errnum);
+			buf[buflen - 1] = 0;
+		}
 		return 0;
 	}
 
-- 
2.13.6


             reply	other threads:[~2018-10-02 21:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02 21:55 Steven Rostedt [this message]
2018-10-05 15:30 ` [PATCH v3] tools/lib/traceevent: Replace str_error_r() with an open coded implementation Steven Rostedt
2018-10-05 15:37   ` Arnaldo Carvalho de Melo
2018-10-05 15:45     ` Steven Rostedt
2018-10-05 15:47       ` Arnaldo Carvalho de Melo
2018-10-05 15:58         ` Steven Rostedt
2018-10-05 16:09           ` Arnaldo Carvalho de Melo
2018-10-05 16:27   ` Colin McCabe
2018-10-05 16:34     ` Steven Rostedt
2018-10-05 19:47     ` Arnaldo Carvalho de Melo
2018-10-05 21:41       ` Colin McCabe

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=20181002175539.2ac894c7@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=acme@kernel.org \
    --cc=cmccabe@alumni.cmu.edu \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).