All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: Implement warning() in the library
@ 2021-04-05  9:33 Tzvetomir Stoyanov (VMware)
  2021-04-05 13:59 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-04-05  9:33 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The warning() function is used in a lot of places in the trace-cmd
library, but there is no implementation. The function is implemented in
the trace-cmd application. Added a weak implementation in the library, in
case the function in not implemented in the application, using that
library.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 Depends on "[v4] trace-cmd: Remove all die()s from trace-cmd library"
 https://patchwork.kernel.org/project/linux-trace-devel/patch/20210405092100.869572-1-tz.stoyanov@gmail.com/

 lib/trace-cmd/trace-util.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index db7bead6..0ee842e5 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -368,6 +368,16 @@ static int __vlib_warning(const char *fmt, va_list ap)
 	return ret;
 }
 
+void __weak warning(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	__vlib_warning(fmt, ap);
+	va_end(ap);
+}
+
+
 void __weak tracecmd_lib_fatal(const char *fmt, ...)
 {
 	int ret;
-- 
2.30.2


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

* Re: [PATCH] trace-cmd: Implement warning() in the library
  2021-04-05  9:33 [PATCH] trace-cmd: Implement warning() in the library Tzvetomir Stoyanov (VMware)
@ 2021-04-05 13:59 ` Steven Rostedt
  2021-04-05 14:23   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2021-04-05 13:59 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Mon,  5 Apr 2021 12:33:57 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> The warning() function is used in a lot of places in the trace-cmd
> library, but there is no implementation. The function is implemented in
> the trace-cmd application. Added a weak implementation in the library, in
> case the function in not implemented in the application, using that
> library.
> 

Isn't the "warning()" function implemented in libtraceevent? That's where
it would be used as it is weak there.

But honestly, I think we should change the libtraceveent warning to
"tep_warning()" if we haven't already done so.

/me goes to look at the code.

-- Steve

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

* Re: [PATCH] trace-cmd: Implement warning() in the library
  2021-04-05 13:59 ` Steven Rostedt
@ 2021-04-05 14:23   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-04-05 14:23 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Mon, 5 Apr 2021 09:59:20 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Mon,  5 Apr 2021 12:33:57 +0300
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
> 
> > The warning() function is used in a lot of places in the trace-cmd
> > library, but there is no implementation. The function is implemented in
> > the trace-cmd application. Added a weak implementation in the library, in
> > case the function in not implemented in the application, using that
> > library.
> >   
> 
> Isn't the "warning()" function implemented in libtraceevent? That's where
> it would be used as it is weak there.
> 
> But honestly, I think we should change the libtraceveent warning to
> "tep_warning()" if we haven't already done so.
> 
> /me goes to look at the code.

OK, so what I think we need to do is have this:


void __weak tep_print_error(const char *fmt, const char *app, va_list ap)
{
	if (errno)
		perror(app);
	fprintf(stderr, " ");
	vfprintf(stderr, fmt, ap);
	fprintf(stderr, "\n");
}

That gets the format and a va_list, and this is the weak function that
anything can overwrite (like KernelShark to have a pop up on error?).

Then we can have functions:

void __weak tep_vwarning(const char *fmt, va_list ap)
{
	tep_print_error(fmt, "libtraceevent", ap);
}
	
void __weak tep_warning(const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	tep_vwarning(fmt, ap);
	va_end(ap);
}


And the same for libtracefs and libtracecmd.

where it will have a tracefs_warning() and a tracecmd_warning() functions
defined. Then an app can overwrite how tep_print_error() works, as well as
tep_vwarning works (or tracefs_vwarning() etc).

Hmm, thinking about this, there's no reason to have tep_warning() weak,
because by overwriting tep_vwarning(), you have full control of
tep_warning().

-- Steve

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05  9:33 [PATCH] trace-cmd: Implement warning() in the library Tzvetomir Stoyanov (VMware)
2021-04-05 13:59 ` Steven Rostedt
2021-04-05 14:23   ` Steven Rostedt

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.