From: Mike Yuan Date: Mon, 20 May 2024 11:33:26 +0000 (+0800) Subject: fs-util: try AT_EMPTY_PATH for access_fd() first X-Git-Tag: v257-rc1~1193^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F32933%2Fhead;p=thirdparty%2Fsystemd.git fs-util: try AT_EMPTY_PATH for access_fd() first --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 6df53cb0c4c..92ceb3b352e 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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;