From 4048f3ffb6b74fef0a7e0e2f9d47bc944d805578 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 30 Jun 2022 15:19:59 -0700 Subject: syscall: Faccessat: use faccessat2 on linux Linux kernel 5.8 added the faccessat2 syscall taking a flags argument. Attempt to use it in Faccessat and fall back to the existing implementation mimicking glibc faccessat. Do not export the new syscall value so we keep syscall API intact. Part of this commit is generated by: GOOS=linux ./mkall.sh -syscalls zsyscall_linux_*.go This is similar to [1] amended by [2]. Required for [3]. [1] https://go-review.googlesource.com/c/sys/+/246537 [2] https://go-review.googlesource.com/c/sys/+/246817 [3] https://go-review.googlesource.com/c/go/+/414824 Co-authored-by: Tobias Klauser Change-Id: Ib7fe5ba853c15d92e869df9a16b56b79b96e43a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/416115 Reviewed-by: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills --- src/syscall/syscall_linux.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/syscall/syscall_linux.go') diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index 55a49cc3eb..c3038fc09a 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -137,10 +137,15 @@ func isGroupMember(gid int) bool { } //sys faccessat(dirfd int, path string, mode uint32) (err error) +//sys faccessat2(dirfd int, path string, mode uint32, flags int) (err error) = _SYS_faccessat2 func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { - if flags & ^(_AT_SYMLINK_NOFOLLOW|_AT_EACCESS) != 0 { - return EINVAL + if flags == 0 { + return faccessat(dirfd, path, mode) + } + + if err := faccessat2(dirfd, path, mode, flags); err != ENOSYS && err != EPERM { + return err } // The Linux kernel faccessat system call does not take any flags. @@ -149,8 +154,8 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { // Because people naturally expect syscall.Faccessat to act // like C faccessat, we do the same. - if flags == 0 { - return faccessat(dirfd, path, mode) + if flags & ^(_AT_SYMLINK_NOFOLLOW|_AT_EACCESS) != 0 { + return EINVAL } var st Stat_t -- cgit v1.3-5-g45d5