linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2] libtraceevent: Add tep_warning()
Date: Thu,  8 Apr 2021 07:26:23 +0300	[thread overview]
Message-ID: <20210408042623.3112002-1-tz.stoyanov@gmail.com> (raw)

The traceevent library uses a function with generic name warning() to
print various warning messages. This function is implemented as a weak
and can be overridden by the application. However, as the name is
generic, there could be collisions with other libraries or application,
using the functin with the same name.
Renamed warning() to tep_warning().
Renamed__vwarning to tep_vwarning().
Both functions are weak and can be overrriden. Overriding tep_warning()
affects only the warnings of libtraceevent library. The tep_vwarning()
is used by all tracing libraries: libtraceevent, libtrasefs and
libtracecmd. Overriding tep_vwarning() affects the warnings of all those
libraries.
Removed the existing __warning() function, as it is not used by the
library.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 v2 changes:
  - Added tep_vwarning(), which is going to be used for all trace
    libraries.

 plugins/plugin_function.c |  4 ++--
 src/event-parse.c         | 22 +++++++++++-----------
 src/event-plugin.c        | 14 +++++++-------
 src/event-utils.h         |  7 +++----
 src/parse-utils.c         | 21 +++++++--------------
 5 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/plugins/plugin_function.c b/plugins/plugin_function.c
index 807b16e..93bdcc2 100644
--- a/plugins/plugin_function.c
+++ b/plugins/plugin_function.c
@@ -65,7 +65,7 @@ static void add_child(struct func_stack *stack, const char *child, int pos)
 		ptr = realloc(stack->stack, sizeof(char *) *
 			      (stack->size + STK_BLK));
 		if (!ptr) {
-			warning("could not allocate plugin memory\n");
+			tep_warning("could not allocate plugin memory\n");
 			return;
 		}
 
@@ -91,7 +91,7 @@ static int add_and_get_index(const char *parent, const char *child, int cpu)
 
 		ptr = realloc(fstack, sizeof(*fstack) * (cpu + 1));
 		if (!ptr) {
-			warning("could not allocate plugin memory\n");
+			tep_warning("could not allocate plugin memory\n");
 			return 0;
 		}
 
diff --git a/src/event-parse.c b/src/event-parse.c
index 2307e33..7c1f4cb 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -39,19 +39,19 @@ static int show_warning = 1;
 #define do_warning(fmt, ...)				\
 	do {						\
 		if (show_warning)			\
-			warning(fmt, ##__VA_ARGS__);	\
+			tep_warning(fmt, ##__VA_ARGS__);\
 	} while (0)
 
-#define do_warning_event(event, fmt, ...)			\
-	do {							\
-		if (!show_warning)				\
-			continue;				\
-								\
-		if (event)					\
-			warning("[%s:%s] " fmt, event->system,	\
-				event->name, ##__VA_ARGS__);	\
-		else						\
-			warning(fmt, ##__VA_ARGS__);		\
+#define do_warning_event(event, fmt, ...)				\
+	do {								\
+		if (!show_warning)					\
+			continue;					\
+									\
+		if (event)						\
+			tep_warning("[%s:%s] " fmt, event->system,	\
+				    event->name, ##__VA_ARGS__);	\
+		else							\
+			tep_warning(fmt, ##__VA_ARGS__);		\
 	} while (0)
 
 /**
diff --git a/src/event-plugin.c b/src/event-plugin.c
index e7f93d5..df4a0a3 100644
--- a/src/event-plugin.c
+++ b/src/event-plugin.c
@@ -454,14 +454,14 @@ load_plugin(struct tep_handle *tep, const char *path,
 
 	ret = asprintf(&plugin, "%s/%s", path, file);
 	if (ret < 0) {
-		warning("could not allocate plugin memory\n");
+		tep_warning("could not allocate plugin memory\n");
 		return;
 	}
 
 	handle = dlopen(plugin, RTLD_NOW | RTLD_GLOBAL);
 	if (!handle) {
-		warning("could not load plugin '%s'\n%s\n",
-			plugin, dlerror());
+		tep_warning("could not load plugin '%s'\n%s\n",
+			    plugin, dlerror());
 		goto out_free;
 	}
 
@@ -481,14 +481,14 @@ load_plugin(struct tep_handle *tep, const char *path,
 
 	func = dlsym(handle, TEP_PLUGIN_LOADER_NAME);
 	if (!func) {
-		warning("could not find func '%s' in plugin '%s'\n%s\n",
-			TEP_PLUGIN_LOADER_NAME, plugin, dlerror());
+		tep_warning("could not find func '%s' in plugin '%s'\n%s\n",
+			    TEP_PLUGIN_LOADER_NAME, plugin, dlerror());
 		goto out_free;
 	}
 
 	list = malloc(sizeof(*list));
 	if (!list) {
-		warning("could not allocate plugin memory\n");
+		tep_warning("could not allocate plugin memory\n");
 		goto out_free;
 	}
 
@@ -616,7 +616,7 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 
 	ret = asprintf(&path, "%s/%s", home, LOCAL_PLUGIN_DIR);
 	if (ret < 0) {
-		warning("could not allocate plugin memory\n");
+		tep_warning("could not allocate plugin memory\n");
 		return;
 	}
 
diff --git a/src/event-utils.h b/src/event-utils.h
index 0560b96..ff4d6c4 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -7,17 +7,16 @@
 #define __UTIL_H
 
 #include <ctype.h>
+#include <stdarg.h>
 
 /* Can be overridden */
-void warning(const char *fmt, ...);
+void tep_warning(const char *fmt, ...);
+int tep_vwarning(const char *name, const char *fmt, va_list ap);
 void pr_stat(const char *fmt, ...);
 void vpr_stat(const char *fmt, va_list ap);
 
 /* Always available */
-void __warning(const char *fmt, ...);
 void __pr_stat(const char *fmt, ...);
-
-void __vwarning(const char *fmt, ...);
 void __vpr_stat(const char *fmt, ...);
 
 #define min(x, y) ({				\
diff --git a/src/parse-utils.c b/src/parse-utils.c
index e998671..6a4a2cd 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -11,33 +11,26 @@
 
 #define __weak __attribute__((weak))
 
-void __vwarning(const char *fmt, va_list ap)
+int __weak tep_vwarning(const char *name, const char *fmt, va_list ap)
 {
+	int ret = errno;
+
 	if (errno)
-		perror("libtraceevent");
-	errno = 0;
+		perror(name);
 
 	fprintf(stderr, "  ");
 	vfprintf(stderr, fmt, ap);
-
 	fprintf(stderr, "\n");
-}
-
-void __warning(const char *fmt, ...)
-{
-	va_list ap;
 
-	va_start(ap, fmt);
-	__vwarning(fmt, ap);
-	va_end(ap);
+	return ret;
 }
 
-void __weak warning(const char *fmt, ...)
+void __weak tep_warning(const char *fmt, ...)
 {
 	va_list ap;
 
 	va_start(ap, fmt);
-	__vwarning(fmt, ap);
+	tep_vwarning("libtraceevent", fmt, ap);
 	va_end(ap);
 }
 
-- 
2.30.2


                 reply	other threads:[~2021-04-08  4:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210408042623.3112002-1-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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).