From 4ba5be03d9fc6a6211b62c2b9805d28e9abdd97d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 23 May 2012 11:14:41 -0400 Subject: [PATCH] iIf struct dirent has d_type, use it to avoid an extra stat(). --HG-- branch : 1.7 --- config.h.in | 3 +++ configure | 14 ++++++++++++++ configure.in | 4 ++++ sudoreplay.c | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/config.h.in b/config.h.in index e313da8e9..667a7fa55 100644 --- a/config.h.in +++ b/config.h.in @@ -516,6 +516,9 @@ /* Define to 1 if you have the `strsignal' function. */ #undef HAVE_STRSIGNAL +/* Define to 1 if `d_type' is a member of `struct dirent'. */ +#undef HAVE_STRUCT_DIRENT_D_TYPE + /* Define to 1 if the system has the type `struct in6_addr'. */ #undef HAVE_STRUCT_IN6_ADDR diff --git a/configure b/configure index 35ac56592..a05f8b74e 100755 --- a/configure +++ b/configure @@ -17115,6 +17115,20 @@ rm -f core conftest.err conftest.$ac_objext \ fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext +ac_fn_c_check_member "$LINENO" "struct dirent" "d_type" "ac_cv_member_struct_dirent_d_type" " +$ac_includes_default +#include <$ac_header_dirent> + +" +if test "x$ac_cv_member_struct_dirent_d_type" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_DIRENT_D_TYPE 1 +_ACEOF + + +fi + if test -n "$NEED_SNPRINTF"; then case " $LIBOBJS " in *" snprintf.$ac_objext "* ) ;; diff --git a/configure.in b/configure.in index 46cb47834..1745afa85 100644 --- a/configure.in +++ b/configure.in @@ -2133,6 +2133,10 @@ dnl AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include #include <$ac_header_dirent>]], [[DIR *d; (void)dirfd(d);]])], [AC_DEFINE(HAVE_DIRFD)], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include #include <$ac_header_dirent>]], [[DIR d; memset(&d, 0, sizeof(d)); return(d.dd_fd);]])], [AC_DEFINE(HAVE_DD_FD)], [])]) +AC_CHECK_MEMBERS([struct dirent.d_type], [], [], [ +AC_INCLUDES_DEFAULT +#include <$ac_header_dirent> +]) dnl dnl If NEED_SNPRINTF is set, add snprintf.c to LIBOBJS dnl (it contains snprintf, vsnprintf, asprintf, and vasprintf) diff --git a/sudoreplay.c b/sudoreplay.c index 4fff1107d..019aa65d0 100644 --- a/sudoreplay.c +++ b/sudoreplay.c @@ -871,6 +871,10 @@ find_sessions(dir, re, user, tty) if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) continue; +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + if (dp->d_type != DT_DIR) + continue; +#endif /* Add name to session list. */ if (sessions_len + 1 > sessions_size) { @@ -898,7 +902,9 @@ find_sessions(dir, re, user, tty) } else { /* Strip off "/log" and recurse if a dir. */ pathbuf[sdlen + len - 4] = '\0'; +#ifndef HAVE_STRUCT_DIRENT_D_TYPE if (lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode)) +#endif find_sessions(pathbuf, re, user, tty); } } -- 2.50.1