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: <d580114523f838994fb6a03a07327d557138e4e1.1439775095.git.raphael.beamonte@gmail.com>
Date:	Sun, 16 Aug 2015 21:39:12 -0400
From:	Raphaël Beamonte <raphael.beamonte@...il.com>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	Raphaël Beamonte <raphael.beamonte@...il.com>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Ingo Molnar <mingo@...hat.com>, Jiri Olsa <jolsa@...nel.org>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Yunlong Song <yunlong.song@...wei.com>,
	Matt Fleming <matt.fleming@...el.com>,
	Kan Liang <kan.liang@...el.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Hemant Kumar <hemant@...ux.vnet.ibm.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Wang Nan <wangnan0@...wei.com>, linux-kernel@...r.kernel.org
Subject: [PATCH] perf: fix confusing messages when not able to read trace events files

If a non-root user tries to specify a trace event and the tracefs
files can't be read, it will tell about it in a somewhat cryptic
way and as well say that the tracepoint is unknown, which is
obvious, since the tracefs files were not read.

This patch changes this behavior by using the debugfs__strerror_open
function to report the access error in a more elegant way, as well as
provide a hint like the one provided by the perf trace tool.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=100781
Signed-off-by: Raphaël Beamonte <raphael.beamonte@...il.com>
---
 tools/perf/util/parse-events.c  | 14 +++++++++++---
 tools/perf/util/parse-options.c |  6 ++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 09f8d23..17f787c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -398,6 +398,7 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
 				      char *sys_name, char *evt_name)
 {
 	char evt_path[MAXPATHLEN];
+	char errbuf[BUFSIZ];
 	struct dirent *evt_ent;
 	DIR *evt_dir;
 	int ret = 0;
@@ -405,7 +406,10 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
 	snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
 	evt_dir = opendir(evt_path);
 	if (!evt_dir) {
-		perror("Can't open event dir");
+		debugfs__strerror_open(
+			errno, errbuf, sizeof(errbuf),
+			evt_path + strlen(debugfs_mountpoint) + 1);
+		fprintf(stderr, "%s\n", errbuf);
 		return -1;
 	}
 
@@ -437,13 +441,17 @@ static int add_tracepoint_event(struct list_head *list, int *idx,
 static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 				    char *sys_name, char *evt_name)
 {
+	char errbuf[BUFSIZ];
 	struct dirent *events_ent;
 	DIR *events_dir;
 	int ret = 0;
 
 	events_dir = opendir(tracing_events_path);
 	if (!events_dir) {
-		perror("Can't open event dir");
+		debugfs__strerror_open(
+			errno, errbuf, sizeof(errbuf),
+			tracing_events_path + strlen(debugfs_mountpoint) + 1);
+		fprintf(stderr, "%s\n", errbuf);
 		return -1;
 	}
 
@@ -1156,7 +1164,7 @@ int parse_events_option(const struct option *opt, const char *str,
 	struct parse_events_error err = { .idx = 0, };
 	int ret = parse_events(evlist, str, &err);
 
-	if (ret)
+	if (ret && errno != EACCES)
 		parse_events_print_error(&err, str);
 
 	return ret;
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 01626be..55319d9 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -400,6 +400,12 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 				return usage_with_options_internal(usagestr, options, 0);
 			switch (parse_short_opt(ctx, options)) {
 			case -1:
+				/* If the error is an access error, we should already have
+				 * taken care of it, and the usage information will provide
+				 * no help to the user.
+				 */
+				if (errno == EACCES)
+					return -1;
 				return parse_options_usage(usagestr, options, arg, 1);
 			case -2:
 				goto unknown;
-- 
2.1.4

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