diff mbox series

trace-cmd: Load trace-cmd plugins from build folder, if exists

Message ID 20190419083002.17909-1-tstoyanov@vmware.com (mailing list archive)
State Superseded
Headers show
Series trace-cmd: Load trace-cmd plugins from build folder, if exists | expand

Commit Message

Tzvetomir Stoyanov April 19, 2019, 8:30 a.m. UTC
When a development version of trace-cmd is built and run on the machine,
by default it loads all plugins from predefined drierctories :
  (install_preffix)/lib/traceevent/plugins
  ~/.traceevent/plugins
  the path specified in TRACEEVENT_PLUGIN_DIR environment variable.
In case there is a legacy trace-cmd version already installed, there will be
a collision with the development version. Wrong, incompatible plugins will be
loaded. To simplify the development process, a new logic is added:
  On trace-cmd build stage, the full build path is stored in the
  trace-cmd binary. When the application is started, it checks if this build
  directory exists and loads only plugins from it.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 Makefile                   |  2 ++
 lib/trace-cmd/trace-util.c | 10 ++++++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index cde45f8..534d882 100644
--- a/Makefile
+++ b/Makefile
@@ -207,6 +207,8 @@  LDFLAGS ?=
 export CFLAGS
 export INCLUDES
 
+override CFLAGS += -DBUILD_PLUGIN_PATH="\"$(shell $(shell which pwd))/plugins"\"
+
 # Required CFLAGS
 override CFLAGS += -D_GNU_SOURCE
 
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 8d21fb2..ea4f430 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -1374,11 +1374,21 @@  int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
 	char *home;
 	char *path;
 	char *envdir;
+	struct stat sb;
 	int ret;
 
 	if (tracecmd_disable_plugins)
 		return -EBUSY;
 
+#ifdef BUILD_PLUGIN_PATH
+	if (stat(BUILD_PLUGIN_PATH, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+		trace_util_load_plugins_dir(pevent, suffix, BUILD_PLUGIN_PATH,
+					    load_plugin, data);
+		return 0;
+	}
+#endif
+
+
 /* If a system plugin directory was defined, check that first */
 #ifdef PLUGIN_DIR
 	if (!tracecmd_disable_sys_plugins)