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>] [day] [month] [year] [list]
Message-ID: <4b101d3d-e216-0a43-30f3-19ef20c0522a@loongson.cn>
Date: Sat, 18 May 2024 14:12:46 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Question about "perf list"

Hi all,

Please let me know whether it makes sense to do the following change,
if yes, I will post a formal patch after the merge window, thank you.

-- >8 --
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 7b54e9385442..9fa15b32280f 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -67,11 +67,12 @@ void print_tracepoint_events(const struct 
print_callbacks *print_cb __maybe_unus
         struct dirent **sys_namelist = NULL;
         int sys_items;

-       put_tracing_file(events_path);
         if (events_fd < 0) {
                 pr_err("Error: failed to open tracing events directory\n");
+               pr_err("%s: %s\n", events_path, strerror(errno));
                 return;
         }
+       put_tracing_file(events_path);

         sys_items = tracing_events__scandir_alphasort(&sys_namelist);

Here are the motivations:

I met "Error: failed to open tracing events directory" twice when execute
"perf list", the first reason is there is no "/sys/kernel/tracing/events"
directory due to it does not enable the kernel tracing infrastructure
with CONFIG_FTRACE, the second reason is there is no root privileges, so
add the error string to tell the users what should to do, and also call
put_tracing_file() to free events_path a little later to avoid messy code
in the error message.

(1) Without CONFIG_FTRACE

   $ file /sys/kernel/tracing/events
   /sys/kernel/tracing/events: cannot open `/sys/kernel/tracing/events' 
(No such file or directory)
   # file /sys/kernel/tracing/events
   /sys/kernel/tracing/events: cannot open `/sys/kernel/tracing/events' 
(No such file or directory)


(2) With CONFIG_FTRACE but no root privileges

   $ file /sys/kernel/tracing/events
   /sys/kernel/tracing/events: cannot open `/sys/kernel/tracing/events' 
(Permission denied)
   # file /sys/kernel/tracing/events
   /sys/kernel/tracing/events: directory

Before:

   $ ./perf list
   Error: failed to open tracing events directory

After:

(1) Without CONFIG_FTRACE

   $ ./perf list
   Error: failed to open tracing events directory
   /sys/kernel/tracing//events: No such file or directory

(2) With CONFIG_FTRACE but no root privileges

   $ ./perf list
   Error: failed to open tracing events directory
   /sys/kernel/tracing//events: Permission denied

At the same time, maybe it needs to do the following tiny change
to avoid duplicate "/" in the file path.

-- >8 --
diff --git a/tools/lib/api/fs/tracing_path.c 
b/tools/lib/api/fs/tracing_path.c
index 30745f35d0d2..834fd64c7130 100644
--- a/tools/lib/api/fs/tracing_path.c
+++ b/tools/lib/api/fs/tracing_path.c
@@ -69,7 +69,7 @@ char *get_tracing_file(const char *name)
  {
         char *file;

-       if (asprintf(&file, "%s/%s", tracing_path_mount(), name) < 0)
+       if (asprintf(&file, "%s%s", tracing_path_mount(), name) < 0)
                 return NULL;

         return file;

Before:

   /sys/kernel/tracing//events

After:

   /sys/kernel/tracing/events

Thanks,
Tiezhu


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ