From 354d04860687e5d3dd42550ce3ef634b067bc2f0 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 25 Feb 2018 21:40:11 -0500 Subject: [PATCH] Pass a stat structure pointer to any_can_execute() to avoid a re-stat. --- src/apply-default-acl.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index c4d0c3b..0030431 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -351,12 +351,15 @@ int acl_execute_masked(acl_t acl) { * @param fd * The file descriptor to check. * + * @param sp + * A pointer to a stat structure for @c fd. + * * @return * - @c ACL_SUCCESS - Someone has effective execute permissions on @c fd. * - @c ACL_FAILURE - Nobody can execute @c fd. * - @c ACL_ERROR - Unexpected library error. */ -int any_can_execute(int fd) { +int any_can_execute(int fd, const struct stat* sp) { acl_t acl = acl_get_fd(fd); if (acl == (acl_t)NULL) { @@ -368,13 +371,7 @@ int any_can_execute(int fd) { int result = ACL_FAILURE; if (acl_is_minimal(acl)) { - struct stat s; - if (fstat(fd, &s) == -1) { - perror("any_can_execute (fstat)"); - result = ACL_ERROR; - goto cleanup; - } - if (s.st_mode & (S_IXUSR | S_IXOTH | S_IXGRP)) { + if (sp->st_mode & (S_IXUSR | S_IXOTH | S_IXGRP)) { result = ACL_SUCCESS; goto cleanup; } @@ -633,7 +630,7 @@ int apply_default_acl(const char* path, if (!no_exec_mask) { /* Never mask the execute bit on directories. */ - int ace_result = any_can_execute(fd) || S_ISDIR(sp->st_mode); + int ace_result = any_can_execute(fd,sp) || S_ISDIR(sp->st_mode); if (ace_result == ACL_ERROR) { perror("apply_default_acl (any_can_execute)"); -- 2.43.2