]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: try AT_EMPTY_PATH for access_fd() first 32933/head
authorMike Yuan <me@yhndnzj.com>
Mon, 20 May 2024 11:33:26 +0000 (19:33 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 16:50:44 +0000 (00:50 +0800)
src/basic/fs-util.c

index 6df53cb0c4c00310df1c1ef6680c79162e89e5fb..92ceb3b352ef0701f73c09283c01eaae84c63ac6 100644 (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;