linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides
@ 2021-05-14 20:50 Steven Rostedt
  2021-05-14 20:50 ` [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-05-14 20:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

I found that I wanted to override tep_vprint() but still call the
default function from my override, and found that I could not do so.
That is the purpose of the "__" versions that were used before.

Also, do some clean ups that were discovered while creating this.

Steven Rostedt (VMware) (3):
  libtraceevent: Add include of event-parse.h into event-utils.h
  libtraceevent: Have the header protection be more name space safe
  libtraceevent: Add __tep_vprint() for overrides to use

 src/event-parse.h |  4 ++--
 src/event-utils.h | 12 ++++++++++--
 src/parse-utils.c | 23 +++++++++++++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h
  2021-05-14 20:50 [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides Steven Rostedt
@ 2021-05-14 20:50 ` Steven Rostedt
  2021-05-14 20:50 ` [PATCH 2/3] libtraceevent: Have the header protection be more name space safe Steven Rostedt
  2021-05-14 20:50 ` [PATCH 3/3] libtraceevent: Add __tep_vprint() for overrides to use Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-05-14 20:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

The event-parse.h references enum tep_loglevel which is defined in
event-utils.h. If a program includes event-utils.h first, it will get a
warning about using that enum in a parameter before it is declared.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/event-utils.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/event-utils.h b/src/event-utils.h
index 695905d..da95027 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -10,6 +10,8 @@
 #include <stdarg.h>
 #include <stdbool.h>
 
+#include <event-parse.h>
+
 void tep_warning(const char *fmt, ...);
 void tep_info(const char *fmt, ...);
 /* Can be overridden */
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] libtraceevent: Have the header protection be more name space safe
  2021-05-14 20:50 [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides Steven Rostedt
  2021-05-14 20:50 ` [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h Steven Rostedt
@ 2021-05-14 20:50 ` Steven Rostedt
  2021-05-14 20:50 ` [PATCH 3/3] libtraceevent: Add __tep_vprint() for overrides to use Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-05-14 20:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

The header protection for event-utils.h is just _UTIL_H which is not very
name space safe and if another header were to use that, it could cause
this header not to be included (or this header could cause the other
header not to be included). Also update event-parse.h as well.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/event-parse.h | 4 ++--
 src/event-utils.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/event-parse.h b/src/event-parse.h
index 77be2b9..d4a876f 100644
--- a/src/event-parse.h
+++ b/src/event-parse.h
@@ -3,8 +3,8 @@
  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  *
  */
-#ifndef _PARSE_EVENTS_H
-#define _PARSE_EVENTS_H
+#ifndef __TEP_PARSE_EVENTS_H
+#define __TEP_PARSE_EVENTS_H
 
 #include <stdbool.h>
 #include <stdarg.h>
diff --git a/src/event-utils.h b/src/event-utils.h
index da95027..607be0c 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -3,8 +3,8 @@
  * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  *
  */
-#ifndef __UTIL_H
-#define __UTIL_H
+#ifndef __TEP_EVENT_UTIL_H
+#define __TEP_EVENT_UTIL_H
 
 #include <ctype.h>
 #include <stdarg.h>
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] libtraceevent: Add __tep_vprint() for overrides to use
  2021-05-14 20:50 [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides Steven Rostedt
  2021-05-14 20:50 ` [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h Steven Rostedt
  2021-05-14 20:50 ` [PATCH 2/3] libtraceevent: Have the header protection be more name space safe Steven Rostedt
@ 2021-05-14 20:50 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-05-14 20:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

If a program wants to add something special to tep_vprint() but then also
call the default tep_vprint() it can't. If it overrides the function, it
loses the functionality for it.

Add __tep_vprint() for this use case.

Example:

 int tep_vprint(const char *name, enum tep_loglevel level,
	       bool print_err, const char *fmt, va_list ap)
 {
	if (quiet && !strcmp(name, "myprog"))
		return 0;
	return __tep_vprint(name, level, print_err, fmt, ap);
 }

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/event-utils.h |  6 ++++++
 src/parse-utils.c | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/event-utils.h b/src/event-utils.h
index 607be0c..d377201 100644
--- a/src/event-utils.h
+++ b/src/event-utils.h
@@ -14,10 +14,16 @@
 
 void tep_warning(const char *fmt, ...);
 void tep_info(const char *fmt, ...);
+
 /* Can be overridden */
 int tep_vprint(const char *name, enum tep_loglevel level,
 	       bool print_err, const char *fmt, va_list ap);
 
+/* The actual call of tep_vprint() for overrides to use */
+int __tep_vprint(const char *name, enum tep_loglevel level,
+		 bool print_err, const char *fmt, va_list ap);
+
+
 #define __deprecated(msg) __attribute__((deprecated("msg")))
 
 /* For backward compatibilty, do not use */
diff --git a/src/parse-utils.c b/src/parse-utils.c
index 04237ba..89bf1cd 100644
--- a/src/parse-utils.c
+++ b/src/parse-utils.c
@@ -9,6 +9,7 @@
 #include <stdarg.h>
 #include <errno.h>
 
+#include "event-utils.h"
 #include "event-parse.h"
 
 #define __weak __attribute__((weak))
@@ -42,6 +43,28 @@ void tep_set_loglevel(enum tep_loglevel level)
  */
 int __weak tep_vprint(const char *name, enum tep_loglevel level,
 		      bool print_err, const char *fmt, va_list ap)
+{
+	return __tep_vprint(name, level, print_err, fmt, ap);
+}
+
+/**
+ * __tep_vprint - print library log messages
+ * @name: name of the library.
+ * @level: severity of the log message. This parameter is not used in this implementation, but as
+ *	   the function is weak and can be overridden, having the log level could be useful
+ *	   for other implementations.
+ * @print_err: whether to print the errno, if non zero.
+ * @fmt: printf format string of the message.
+ * @ap: list of printf parameters.
+ *
+ * This function is used to print all messages from traceevent, tracefs and trace-cmd libraries.
+ * It is defined as weak, so the application that uses those libraries can override it in order
+ * to implement its own logic for printing library logs.
+ *
+ * Return the value of errno at the function enter.
+ */
+int __tep_vprint(const char *name, enum tep_loglevel level,
+		      bool print_err, const char *fmt, va_list ap)
 {
 	int ret = errno;
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-14 20:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 20:50 [PATCH 0/3] libtraceevent: Add __tep_vprint() for overrides Steven Rostedt
2021-05-14 20:50 ` [PATCH 1/3] libtraceevent: Add include of event-parse.h into event-utils.h Steven Rostedt
2021-05-14 20:50 ` [PATCH 2/3] libtraceevent: Have the header protection be more name space safe Steven Rostedt
2021-05-14 20:50 ` [PATCH 3/3] libtraceevent: Add __tep_vprint() for overrides to use Steven Rostedt

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).