lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1313091459-12049-3-git-send-email-vnagarnaik@google.com>
Date:	Thu, 11 Aug 2011 12:37:37 -0700
From:	Vaibhav Nagarnaik <vnagarnaik@...gle.com>
To:	Steven Rostedt <rostedt@...dmis.org>
Cc:	Michael Rubin <mrubin@...gle.com>,
	David Sharp <dhsharp@...gle.com>, linux-kernel@...r.kernel.org,
	Vaibhav Nagarnaik <vnagarnaik@...gle.com>
Subject: [PATCH 3/5] trace-cmd: Load plugins before parsing events in check-events

The target check-events parses the event format strings on the local
machine and returns whether they can be parsed or not. The parsing
functionality is extended by loading plugins, if available.

This patch loads the plugins before starting parsing of the event
formats.

Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@...gle.com>
---
 trace-cmd.c   |   21 ++++++++++++++++++---
 trace-cmd.h   |    1 +
 trace-usage.c |    3 ++-
 trace-util.c  |   47 +++++++++++++++++++++++++++++++----------------
 4 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/trace-cmd.c b/trace-cmd.c
index 5cfd97f..b5bcbb3 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -162,7 +162,19 @@ int main (int argc, char **argv)
 		char *tracing;
 		int ret;
 		struct pevent *pevent = NULL;
+		struct plugin_list *list = NULL;
 
+		while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) {
+			switch (c) {
+			case 'h':
+			default:
+				usage(argv);
+				break;
+			case 'N':
+				tracecmd_disable_plugins = 1;
+				break;
+			}
+		}
 		tracing = tracecmd_find_tracing_dir();
 
 		if (!tracing) {
@@ -175,11 +187,14 @@ int main (int argc, char **argv)
 		}
 
 		ret = 0;
-		pevent = tracecmd_local_events(tracing);
+		pevent = pevent_alloc();
 		if (!pevent)
 			exit(EINVAL);
-		if (pevent->parsing_failures)
+		list = tracecmd_load_plugins(pevent);
+		ret = tracecmd_fill_local_events(tracing, pevent);
+		if (ret || pevent->parsing_failures)
 			ret = EINVAL;
+		tracecmd_unload_plugins(list);
 		pevent_free(pevent);
 		exit(ret);
 
diff --git a/trace-cmd.h b/trace-cmd.h
index 66cdb28..d2d0cef 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -38,6 +38,7 @@ void tracecmd_unload_plugins(struct plugin_list *list);
 char **tracecmd_event_systems(const char *tracing_dir);
 char **tracecmd_system_events(const char *tracing_dir, const char *system);
 struct pevent *tracecmd_local_events(const char *tracing_dir);
+int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent);
 char **tracecmd_local_plugins(const char *tracing_dir);
 
 char **tracecmd_add_list(char **list, const char *name, int len);
diff --git a/trace-usage.c b/trace-usage.c
index 58ef167..7314657 100644
--- a/trace-usage.c
+++ b/trace-usage.c
@@ -152,7 +152,8 @@ static struct usage_help usage_help[] = {
 	{
 		"check-events",
 		"parse trace event formats",
-		" %s check-format\n"
+		" %s check-format [-N]\n"
+		"          -N do not load any plugins\n"
 	},
 	{
 		NULL, NULL, NULL
diff --git a/trace-util.c b/trace-util.c
index 01894f8..e128188 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -714,6 +714,28 @@ static int read_header(struct pevent *pevent, const char *events_dir)
 struct pevent *tracecmd_local_events(const char *tracing_dir)
 {
 	struct pevent *pevent = NULL;
+
+	pevent = pevent_alloc();
+	if (!pevent)
+		return NULL;
+
+	if (tracecmd_fill_local_events(tracing_dir, pevent)) {
+		pevent_free(pevent);
+		pevent = NULL;
+	}
+
+	return pevent;
+}
+
+/**
+ * tracecmd_fill_local_events - Fill a pevent with the events on system
+ * @tracing_dir: The directory that contains the events.
+ * @pevent: Allocated pevent which will be filled
+ *
+ * Returns whether the operation succeeded
+ */
+int tracecmd_fill_local_events(const char *tracing_dir, struct pevent *pevent)
+{
 	struct dirent *dent;
 	char *events_dir;
 	struct stat st;
@@ -721,35 +743,27 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
 	int ret, failure = 0;
 
 	if (!tracing_dir)
-		return NULL;
+		return -1;
 
 	events_dir = append_file(tracing_dir, "events");
 	if (!events_dir)
-		return NULL;
+		return -1;
 
 	ret = stat(events_dir, &st);
 	if (ret < 0 || !S_ISDIR(st.st_mode)) {
-		failure = 1;
+		ret = -1;
 		goto out_free;
 	}
 
 	dir = opendir(events_dir);
 	if (!dir) {
-		failure = 1;
-		goto out_free;
-	}
-
-	pevent = pevent_alloc();
-	if (!pevent) {
-		failure = 1;
+		ret = -1;
 		goto out_free;
 	}
 
 	ret = read_header(pevent, events_dir);
 	if (ret < 0) {
-		pevent_free(pevent);
-		pevent = NULL;
-		failure = 1;
+		ret = -1;
 		goto out_free;
 	}
 
@@ -777,14 +791,15 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
 	}
 
 	closedir(dir);
+	/* always succeed because parsing failures are not critical */
+	ret = 0;
 
  out_free:
 	free(events_dir);
 
-	if (pevent)
-		pevent->parsing_failures = failure;
+	pevent->parsing_failures = failure;
 
-	return pevent;
+	return ret;
 }
 
 /**
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ