From: Todd C. Miller Date: Fri, 13 Apr 2012 12:36:58 +0000 (-0400) Subject: If struct dirent has d_type, use it to avoid an extra stat(). X-Git-Tag: SUDO_1_8_5~1^2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0993d877752c35f2517167cdb7c1f836db556da;p=sudo If struct dirent has d_type, use it to avoid an extra stat(). --- diff --git a/config.h.in b/config.h.in index 0574a4df7..8df0ad375 100644 --- a/config.h.in +++ b/config.h.in @@ -508,6 +508,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 aa3cd3041..7984cedcd 100755 --- a/configure +++ b/configure @@ -17358,6 +17358,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 1cbc83664..201a00940 100644 --- a/configure.in +++ b/configure.in @@ -2257,6 +2257,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/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 1173ccdeb..37c7e3218 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -881,6 +881,10 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *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) { @@ -908,7 +912,9 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *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); } }