diff options
author | Ian Rogers <irogers@google.com> | 2024-02-20 19:41:49 -0800 |
---|---|---|
committer | Namhyung Kim <namhyung@kernel.org> | 2024-02-22 09:11:41 -0800 |
commit | 8ece26ad5ad33a1de7231059ec9692d303cb5f2f (patch) | |
tree | 3ad973b5d36d53520c02fab587e269659dbd1169 /tools/perf/util/util.c | |
parent | 510e528786395e419e9a827ee5d42add021111ee (diff) | |
download | linux-8ece26ad5ad33a1de7231059ec9692d303cb5f2f.tar.gz linux-8ece26ad5ad33a1de7231059ec9692d303cb5f2f.tar.bz2 linux-8ece26ad5ad33a1de7231059ec9692d303cb5f2f.zip |
perf list: Add scandirat compatibility function
scandirat is used during the printing of tracepoint events but may be
missing from certain libcs. Add a compatibility implementation that
uses the symlink of an fd in /proc as a path for the reliably present
scandir.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: llvm@lists.linux.dev
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240221034155.1500118-3-irogers@google.com
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r-- | tools/perf/util/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index c1fd9ba6d697..4f561e5e4162 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -552,3 +552,22 @@ int sched_getcpu(void) return -1; } #endif + +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)) +{ + char path[PATH_MAX]; + int err, fd = openat(dirfd, dirp, O_PATH); + + if (fd < 0) + return fd; + + snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd); + err = scandir(path, namelist, filter, compar); + close(fd); + return err; +} +#endif |