linux/tools/lib/api/fs
Tiezhu Yang b48543c451 perf list: Give clues if failed to open tracing events directory
When executing the command "perf list", I met "Error: failed to open
tracing events directory" twice, the first reason is that 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 that there is no root privileges.

Add the error string to tell the users what happened and 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.

At the same time, just remove the redundant "/" of the file path in
the function get_tracing_file(), otherwise it shows something like
"/sys/kernel/tracing//events".

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

Committer testing:

Redirect stdout to null to quickly test the patch:

Before:

  $ perf list > /dev/null
  Error: failed to open tracing events directory
  $

After:

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

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/lkml/20240730062301.23244-3-yangtiezhu@loongson.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-08-01 12:11:33 -03:00
..
Build tools lib api fs: Move cgroupsfs_find_mountpoint() 2020-03-04 10:34:09 -03:00
cgroup.c tools api fs: Dynamically allocate cgroupfs mount point cache, removing 4128 bytes from .bss 2023-05-28 10:25:25 -03:00
fs.c tools api fs: Avoid reading whole file for a 1 byte bool 2023-11-30 19:25:19 -03:00
fs.h tools api fs: Make xxx__mountpoint() more scalable 2020-04-16 12:19:12 -03:00
tracing_path.c perf list: Give clues if failed to open tracing events directory 2024-08-01 12:11:33 -03:00
tracing_path.h tools lib api fs tracing_path: Add scandir alphasort 2022-11-15 10:24:09 -03:00