linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim
@ 2020-07-16  9:19 Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 1/8] tools lib traceevent: Document tep_load_plugins_hook() Tzvetomir Stoyanov (VMware)
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

libtraceevent fixes, backported from trace-cmd repository,
suggested by Namhyung Kim <namhyung@kernel.org>.
There is one additional enhancement over the original patch set:
a man page, describing tep_load_plugins_hook() API is added in
"tools lib traceevent: Document tep_load_plugins_hook()"

Tzvetomir Stoyanov (VMware) (8):
  tools lib traceevent: Document tep_load_plugins_hook()
  tools lib traceevent: Handle strdup() error in parse_option_name()
  tools lib traceevent: Fix typo in tep_plugin_add_option() description
  tools lib traceevent: Improve error handling of
    tep_plugin_add_option() API
  tools lib traceevent: Fixed broken indentation in
    parse_ip4_print_args()
  tools lib traceevent: Fixed type in PRINT_FMT_STING
  tools lib traceevent: Fixed description of tep_add_plugin_path() API
  tools lib traceevent: Handle possible strdup() error in
    tep_add_plugin_path() API

 .../Documentation/libtraceevent-plugins.txt   | 25 +++++++++-
 tools/lib/traceevent/event-parse-local.h      |  2 +-
 tools/lib/traceevent/event-parse.c            | 10 ++--
 tools/lib/traceevent/event-plugin.c           | 50 ++++++++++++++-----
 4 files changed, 67 insertions(+), 20 deletions(-)

-- 
2.26.2


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

* [PATCH 1/8] tools lib traceevent: Document tep_load_plugins_hook()
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name() Tzvetomir Stoyanov (VMware)
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Add description of tep_load_plugins_hook() traceevent API. Updated
library man pages with description of the tep_load_plugins_hook() API.

Link: https://lore.kernel.org/r/CAM9d7cgLBWCrEHwz+Lhv5x5EXGcNWB0QQoeGh3OKh2JfR=dV9Q@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-2-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 .../Documentation/libtraceevent-plugins.txt   | 25 ++++++++++++++++++-
 tools/lib/traceevent/event-plugin.c           | 16 ++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/Documentation/libtraceevent-plugins.txt b/tools/lib/traceevent/Documentation/libtraceevent-plugins.txt
index 596032ade31f..4d6394397d92 100644
--- a/tools/lib/traceevent/Documentation/libtraceevent-plugins.txt
+++ b/tools/lib/traceevent/Documentation/libtraceevent-plugins.txt
@@ -3,7 +3,7 @@ libtraceevent(3)
 
 NAME
 ----
-tep_load_plugins, tep_unload_plugins - Load / unload traceevent plugins.
+tep_load_plugins, tep_unload_plugins, tep_load_plugins_hook - Load / unload traceevent plugins.
 
 SYNOPSIS
 --------
@@ -13,6 +13,12 @@ SYNOPSIS
 
 struct tep_plugin_list pass:[*]*tep_load_plugins*(struct tep_handle pass:[*]_tep_);
 void *tep_unload_plugins*(struct tep_plugin_list pass:[*]_plugin_list_, struct tep_handle pass:[*]_tep_);
+void *tep_load_plugins_hook*(struct tep_handle pass:[*]_tep_, const char pass:[*]_suffix_,
+			   void (pass:[*]_load_plugin_)(struct tep_handle pass:[*]tep,
+					       const char pass:[*]path,
+					       const char pass:[*]name,
+					       void pass:[*]data),
+			   void pass:[*]_data_);
 --
 
 DESCRIPTION
@@ -22,11 +28,13 @@ directories. The _tep_ argument is trace event parser context.
 The plugin directories are :
 [verse]
 --
+	- Directories, specified in _tep_->plugins_dir with priority TEP_PLUGIN_FIRST
 	- System's plugin directory, defined at the library compile time. It
 	  depends on the library installation prefix and usually is
 	  _(install_preffix)/lib/traceevent/plugins_
 	- Directory, defined by the environment variable _TRACEEVENT_PLUGIN_DIR_
 	- User's plugin directory, located at _~/.local/lib/traceevent/plugins_
+	- Directories, specified in _tep_->plugins_dir with priority TEP_PLUGIN_LAST
 --
 Loading of plugins can be controlled by the _tep_flags_, using the
 _tep_set_flag()_ API:
@@ -44,6 +52,12 @@ _tep_load_plugins()_. The _tep_ argument is trace event parser context. The
 _plugin_list_ is the list of loaded plugins, returned by
 the _tep_load_plugins()_ function.
 
+The _tep_load_plugins_hook_ function walks through all directories with plugins
+and calls user specified _load_plugin()_ hook for each plugin file. Only files
+with given _suffix_ are considered to be plugins. The _data_ is a user specified
+context, passed to _load_plugin()_. Directories and the walk order are the same
+as in _tep_load_plugins()_ API.
+
 RETURN VALUE
 ------------
 The _tep_load_plugins()_ function returns a list of successfully loaded plugins,
@@ -63,6 +77,15 @@ if (plugins == NULL) {
 }
 ...
 tep_unload_plugins(plugins, tep);
+...
+void print_plugin(struct tep_handle *tep, const char *path,
+		  const char *name, void *data)
+{
+	pritnf("Found libtraceevent plugin %s/%s\n", path, name);
+}
+...
+tep_load_plugins_hook(tep, ".so", print_plugin, NULL);
+...
 --
 
 FILES
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index 1d4f1809cf17..aa6f43290cd3 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -543,6 +543,22 @@ load_plugins_dir(struct tep_handle *tep, const char *suffix,
 	closedir(dir);
 }
 
+/**
+ * tep_load_plugins_hook - call a user specified callback to load a plugin
+ * @tep: handler to traceevent context
+ * @suffix: filter only plugin files with given suffix
+ * @load_plugin: user specified callback, called for each plugin file
+ * @data: custom context, passed to @load_plugin
+ *
+ * Searches for traceevent plugin files and calls @load_plugin for each
+ * The order of plugins search is:
+ *  - Directories, specified in @tep->plugins_dir and priority TEP_PLUGIN_FIRST
+ *  - Directory, specified at compile time with PLUGIN_TRACEEVENT_DIR
+ *  - Directory, specified by environment variable TRACEEVENT_PLUGIN_DIR
+ *  - In user's home: ~/.local/lib/traceevent/plugins/
+ *  - Directories, specified in @tep->plugins_dir and priority TEP_PLUGIN_LAST
+ *
+ */
 void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 			   void (*load_plugin)(struct tep_handle *tep,
 					       const char *path,
-- 
2.26.2


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

* [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name()
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 1/8] tools lib traceevent: Document tep_load_plugins_hook() Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 3/8] tools lib traceevent: Fix typo in tep_plugin_add_option() description Tzvetomir Stoyanov (VMware)
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Modified internal function parse_option_name() to return error and handle
that error in function callers in case strdup() fails.

Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-3-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index aa6f43290cd3..a39eeb6ef1f2 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -254,7 +254,7 @@ void tep_plugin_remove_options(struct tep_plugin_option *options)
 	}
 }
 
-static void parse_option_name(char **option, char **plugin)
+static int parse_option_name(char **option, char **plugin)
 {
 	char *p;
 
@@ -265,8 +265,9 @@ static void parse_option_name(char **option, char **plugin)
 		*p = '\0';
 		*option = strdup(p + 1);
 		if (!*option)
-			return;
+			return -1;
 	}
+	return 0;
 }
 
 static struct tep_plugin_option *
@@ -325,7 +326,8 @@ int tep_plugin_add_option(const char *name, const char *val)
 	if (!option_str)
 		return -ENOMEM;
 
-	parse_option_name(&option_str, &plugin);
+	if (parse_option_name(&option_str, &plugin) < 0)
+		return -ENOMEM;
 
 	/* If the option exists, update the val */
 	for (op = trace_plugin_options; op; op = op->next) {
-- 
2.26.2


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

* [PATCH 3/8] tools lib traceevent: Fix typo in tep_plugin_add_option() description
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 1/8] tools lib traceevent: Document tep_load_plugins_hook() Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name() Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 4/8] tools lib traceevent: Improve error handling of tep_plugin_add_option() API Tzvetomir Stoyanov (VMware)
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

A typo "optiona" -> "optional" is fixed in description of
tep_plugin_add_option() API.

Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-4-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index a39eeb6ef1f2..f8d253a61970 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -310,7 +310,7 @@ static int process_option(const char *plugin, const char *option, const char *va
 /**
  * tep_plugin_add_option - add an option/val pair to set plugin options
  * @name: The name of the option (format: <plugin>:<option> or just <option>)
- * @val: (optiona) the value for the option
+ * @val: (optional) the value for the option
  *
  * Modify a plugin option. If @val is given than the value of the option
  * is set (note, some options just take a boolean, so @val must be either
-- 
2.26.2


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

* [PATCH 4/8] tools lib traceevent: Improve error handling of tep_plugin_add_option() API
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
                   ` (2 preceding siblings ...)
  2020-07-16  9:19 ` [PATCH 3/8] tools lib traceevent: Fix typo in tep_plugin_add_option() description Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 5/8] tools lib traceevent: Fixed broken indentation in parse_ip4_print_args() Tzvetomir Stoyanov (VMware)
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

In case of memory error, ensure all allocated resources are freed.
Do not append broken option in trace_plugin_options list.

Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-5-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index f8d253a61970..6b84b9c4e6ba 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -361,23 +361,25 @@ int tep_plugin_add_option(const char *name, const char *val)
 	if (!op) {
 		op = malloc(sizeof(*op));
 		if (!op)
-			return -ENOMEM;
+			goto out_free;
 		memset(op, 0, sizeof(*op));
-		op->next = trace_plugin_options;
-		trace_plugin_options = op;
-
 		op->plugin = plugin;
 		op->option = option_str;
-
 		if (val) {
 			op->value = strdup(val);
-			if (!op->value)
+			if (!op->value) {
+				free(op);
 				goto out_free;
+			}
 		}
+		op->next = trace_plugin_options;
+		trace_plugin_options = op;
 	}
 
 	return process_option(plugin, option_str, val);
- out_free:
+
+out_free:
+	free(plugin);
 	free(option_str);
 	return -ENOMEM;
 }
-- 
2.26.2


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

* [PATCH 5/8] tools lib traceevent: Fixed broken indentation in parse_ip4_print_args()
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
                   ` (3 preceding siblings ...)
  2020-07-16  9:19 ` [PATCH 4/8] tools lib traceevent: Improve error handling of tep_plugin_add_option() API Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 6/8] tools lib traceevent: Fixed type in PRINT_FMT_STING Tzvetomir Stoyanov (VMware)
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Fixed the "break" indentation in a switch() inside
parse_ip4_print_args() static function.

Link: https://lore.kernel.org/r/CAM9d7cjboXGg+iMOA4BQo=E01iLGcJNB1MyPJ4doPP1XeGVJRA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-6-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index ee16be96697b..8ee83f1e4e01 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4633,11 +4633,11 @@ static int parse_ip4_print_args(struct tep_handle *tep,
 		else
 			*reverse = true;
 		ret++;
-	break;
+		break;
 	case 'l':
 		*reverse = true;
 		ret++;
-	break;
+		break;
 	case 'n':
 	case 'b':
 		ret++;
-- 
2.26.2


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

* [PATCH 6/8] tools lib traceevent: Fixed type in PRINT_FMT_STING
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
                   ` (4 preceding siblings ...)
  2020-07-16  9:19 ` [PATCH 5/8] tools lib traceevent: Fixed broken indentation in parse_ip4_print_args() Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 7/8] tools lib traceevent: Fixed description of tep_add_plugin_path() API Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 8/8] tools lib traceevent: Handle possible strdup() error in " Tzvetomir Stoyanov (VMware)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

PRINT_FMT_STING -> PRINT_FMT_STRING

Link: https://lore.kernel.org/r/CAM9d7cj1LJ=QO8QxhBo_oDM9APpAswX4BbTwge0JhZ3Y4-Bv9w@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-7-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-parse-local.h | 2 +-
 tools/lib/traceevent/event-parse.c       | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/lib/traceevent/event-parse-local.h b/tools/lib/traceevent/event-parse-local.h
index e71296a62236..d805a920af6f 100644
--- a/tools/lib/traceevent/event-parse-local.h
+++ b/tools/lib/traceevent/event-parse-local.h
@@ -86,7 +86,7 @@ struct tep_handle {
 };
 
 enum tep_print_parse_type {
-	PRINT_FMT_STING,
+	PRINT_FMT_STRING,
 	PRINT_FMT_ARG_DIGIT,
 	PRINT_FMT_ARG_POINTER,
 	PRINT_FMT_ARG_STRING,
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 8ee83f1e4e01..af56b60e5f89 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -5612,7 +5612,7 @@ static int parse_arg_format(struct tep_print_parse **parse,
 		default:
 			snprintf(print_format, 32, ">%c<", *format);
 			parse_arg_add(parse, print_format,
-					PRINT_FMT_STING, NULL, NULL, 0);
+					PRINT_FMT_STRING, NULL, NULL, 0);
 			ret++;
 			return ret;
 		}
@@ -5664,7 +5664,7 @@ static int parse_arg_string(struct tep_print_parse **parse, const char *format)
 		ret++;
 	}
 	trace_seq_terminate(&s);
-	parse_arg_add(parse, s.buffer, PRINT_FMT_STING, NULL, NULL, 0);
+	parse_arg_add(parse, s.buffer, PRINT_FMT_STRING, NULL, NULL, 0);
 	trace_seq_destroy(&s);
 
 	return ret;
@@ -5722,7 +5722,7 @@ static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s
 					 parse->len_as_arg ? len_arg : -1,
 					 data, size, event, parse->arg);
 			break;
-		case PRINT_FMT_STING:
+		case PRINT_FMT_STRING:
 		default:
 			trace_seq_printf(s, "%s", parse->format);
 			break;
-- 
2.26.2


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

* [PATCH 7/8] tools lib traceevent: Fixed description of tep_add_plugin_path() API
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
                   ` (5 preceding siblings ...)
  2020-07-16  9:19 ` [PATCH 6/8] tools lib traceevent: Fixed type in PRINT_FMT_STING Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  2020-07-16  9:19 ` [PATCH 8/8] tools lib traceevent: Handle possible strdup() error in " Tzvetomir Stoyanov (VMware)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Changed the description of tep_add_plugin_path() API to reflect the
logic of the function. The suffix of plugin files is not hardcoded
to ".so", it depends on the custom plugin loader callback.

Link: https://lore.kernel.org/CAM9d7cgMgqFDvKhs6xwdBSMsaG=3ZG0RtxwgQDCTLGkML1MY4Q@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-8-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index 6b84b9c4e6ba..f0877a7e3e8d 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -646,8 +646,8 @@ tep_load_plugins(struct tep_handle *tep)
 /**
  * tep_add_plugin_path - Add a new plugin directory.
  * @tep: Trace event handler.
- * @path: Path to a directory. All files with extension .so in that
- *	  directory will be loaded as plugins.
+ * @path: Path to a directory. All plugin files in that
+ *	  directory will be loaded.
  *@prio: Load priority of the plugins in that directory.
  *
  * Returns -1 in case of an error, 0 otherwise.
-- 
2.26.2


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

* [PATCH 8/8] tools lib traceevent: Handle possible strdup() error in tep_add_plugin_path() API
  2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
                   ` (6 preceding siblings ...)
  2020-07-16  9:19 ` [PATCH 7/8] tools lib traceevent: Fixed description of tep_add_plugin_path() API Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:19 ` Tzvetomir Stoyanov (VMware)
  7 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:19 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Free allocated resources and return -1 in case strdup() fails in
tep_add_plugin_path() API.

Link: https://lore.kernel.org/r/CAM9d7chfvJwodpVrHGc5E2J80peRojmYV_fD8x3cpn9HFRUw2g@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-9-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index f0877a7e3e8d..e7c2acb8680f 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -665,6 +665,10 @@ int tep_add_plugin_path(struct tep_handle *tep, char *path,
 		return -1;
 
 	dir->path = strdup(path);
+	if (!dir->path) {
+		free(dir);
+		return -1;
+	}
 	dir->prio = prio;
 	dir->next = tep->plugins_dir;
 	tep->plugins_dir = dir;
-- 
2.26.2


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

* [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name()
  2020-07-16  9:20 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
@ 2020-07-16  9:20 ` Tzvetomir Stoyanov (VMware)
  0 siblings, 0 replies; 10+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-07-16  9:20 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, namhyung

Modified internal function parse_option_name() to return error and handle
that error in function callers in case strdup() fails.

Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com
Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-3-tz.stoyanov@gmail.com

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/lib/traceevent/event-plugin.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index aa6f43290cd3..a39eeb6ef1f2 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -254,7 +254,7 @@ void tep_plugin_remove_options(struct tep_plugin_option *options)
 	}
 }
 
-static void parse_option_name(char **option, char **plugin)
+static int parse_option_name(char **option, char **plugin)
 {
 	char *p;
 
@@ -265,8 +265,9 @@ static void parse_option_name(char **option, char **plugin)
 		*p = '\0';
 		*option = strdup(p + 1);
 		if (!*option)
-			return;
+			return -1;
 	}
+	return 0;
 }
 
 static struct tep_plugin_option *
@@ -325,7 +326,8 @@ int tep_plugin_add_option(const char *name, const char *val)
 	if (!option_str)
 		return -ENOMEM;
 
-	parse_option_name(&option_str, &plugin);
+	if (parse_option_name(&option_str, &plugin) < 0)
+		return -ENOMEM;
 
 	/* If the option exists, update the val */
 	for (op = trace_plugin_options; op; op = op->next) {
-- 
2.26.2


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

end of thread, other threads:[~2020-07-16  9:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16  9:19 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 1/8] tools lib traceevent: Document tep_load_plugins_hook() Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name() Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 3/8] tools lib traceevent: Fix typo in tep_plugin_add_option() description Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 4/8] tools lib traceevent: Improve error handling of tep_plugin_add_option() API Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 5/8] tools lib traceevent: Fixed broken indentation in parse_ip4_print_args() Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 6/8] tools lib traceevent: Fixed type in PRINT_FMT_STING Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 7/8] tools lib traceevent: Fixed description of tep_add_plugin_path() API Tzvetomir Stoyanov (VMware)
2020-07-16  9:19 ` [PATCH 8/8] tools lib traceevent: Handle possible strdup() error in " Tzvetomir Stoyanov (VMware)
2020-07-16  9:20 [PATCH 0/8] Backported libtraceevent fixes, suggested by Namhyung Kim Tzvetomir Stoyanov (VMware)
2020-07-16  9:20 ` [PATCH 2/8] tools lib traceevent: Handle strdup() error in parse_option_name() Tzvetomir Stoyanov (VMware)

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