Module: Mesa Branch: master Commit: 8490b7d917c46951e3bc6708000fb542350b814b URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8490b7d917c46951e3bc6708000fb542350b814b
Author: Alan Coopersmith <[email protected]> Date: Tue Nov 5 16:56:46 2019 -0800 intel/perf: adapt to platforms like Solaris without d_type in struct dirent Signed-off-by: Alan Coopersmith <[email protected]> [Eric: factor out the is_dir_or_link() check and fix a bug in v1] Signed-off-by: Eric Engestrom <[email protected]> v3: include directory path when lstat'ing files v4: fix inverted check in enumerate_sysfs_metrics() Reviewed-by: Eric Engestrom <[email protected]> Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2258> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2258> --- meson.build | 5 +++++ src/intel/perf/gen_perf.c | 25 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 35cd2e6f632..2cf0ee7fe0c 100644 --- a/meson.build +++ b/meson.build @@ -1178,6 +1178,11 @@ if host_machine.system() != 'windows' endif endif +if cc.has_member('struct dirent', 'd_type', prefix: '''#include <sys/types.h> + #include <dirent.h>''') + pre_args += '-DHAVE_DIRENT_D_TYPE' +endif + # strtod locale support if cc.links(''' #define _GNU_SOURCE diff --git a/src/intel/perf/gen_perf.c b/src/intel/perf/gen_perf.c index 421dfb8db52..38dc0166106 100644 --- a/src/intel/perf/gen_perf.c +++ b/src/intel/perf/gen_perf.c @@ -29,6 +29,10 @@ #include <unistd.h> #include <errno.h> +#ifndef HAVE_DIRENT_D_TYPE +#include <limits.h> // PATH_MAX +#endif + #include <drm-uapi/i915_drm.h> #include "common/gen_gem.h" @@ -395,6 +399,20 @@ static inline uint64_t to_user_pointer(void *ptr) return (uintptr_t) ptr; } +static bool +is_dir_or_link(const struct dirent *entry, const char *parent_dir) +{ +#ifdef HAVE_DIRENT_D_TYPE + return entry->d_type == DT_DIR || entry->d_type == DT_LNK; +#else + struct stat st; + char path[PATH_MAX + 1]; + snprintf(path, sizeof(path), "%s/%s", parent_dir, entry->d_name); + lstat(path, &st); + return S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode); +#endif +} + static bool get_sysfs_dev_dir(struct gen_perf_config *perf, int fd) { @@ -434,8 +452,7 @@ get_sysfs_dev_dir(struct gen_perf_config *perf, int fd) } while ((drm_entry = readdir(drmdir))) { - if ((drm_entry->d_type == DT_DIR || - drm_entry->d_type == DT_LNK) && + if (is_dir_or_link(drm_entry, perf->sysfs_dev_dir) && strncmp(drm_entry->d_name, "card", 4) == 0) { len = snprintf(perf->sysfs_dev_dir, @@ -551,9 +568,7 @@ enumerate_sysfs_metrics(struct gen_perf_config *perf) while ((metric_entry = readdir(metricsdir))) { struct hash_entry *entry; - - if ((metric_entry->d_type != DT_DIR && - metric_entry->d_type != DT_LNK) || + if (!is_dir_or_link(metric_entry, buf) || metric_entry->d_name[0] == '.') continue; _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
