fs-util: try AT_EMPTY_PATH for access_fd() first

This commit is contained in:
Mike Yuan
2024-05-22 00:50:44 +08:00
parent 94d94f0c0a
commit c675851d5f
+8
View File
@@ -675,6 +675,14 @@ int access_fd(int fd, int mode) {
/* Like access() but operates on an already open fd */
if (faccessat(fd, "", mode, AT_EMPTY_PATH) >= 0)
return 0;
if (errno != EINVAL)
return -errno;
/* Support for AT_EMPTY_PATH is added rather late (kernel 5.8), so fall back to going through /proc/
* if unavailable. */
if (access(FORMAT_PROC_FD_PATH(fd), mode) < 0) {
if (errno != ENOENT)
return -errno;