From: Michael Orlitzky Date: Mon, 26 Feb 2018 02:40:11 +0000 (-0500) Subject: Pass a stat structure pointer to any_can_execute() to avoid a re-stat. X-Git-Tag: v0.1.0~21 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=354d04860687e5d3dd42550ce3ef634b067bc2f0;p=apply-default-acl.git Pass a stat structure pointer to any_can_execute() to avoid a re-stat. --- 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)");