diff options
| author | Kir Kolyshkin <kolyshkin@gmail.com> | 2022-06-30 15:19:59 -0700 |
|---|---|---|
| committer | Tobias Klauser <tobias.klauser@gmail.com> | 2022-09-01 22:00:28 +0000 |
| commit | 4048f3ffb6b74fef0a7e0e2f9d47bc944d805578 (patch) | |
| tree | fecd1de7ddd4de591e0965878c792506c48bcaa1 /src/syscall/syscall_linux.go | |
| parent | 36f191abcd633a7795195adf89153cc7f373c90f (diff) | |
| download | go-4048f3ffb6b74fef0a7e0e2f9d47bc944d805578.tar.xz | |
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 <tklauser@distanz.ch>
Change-Id: Ib7fe5ba853c15d92e869df9a16b56b79b96e43a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/416115
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/syscall/syscall_linux.go')
| -rw-r--r-- | src/syscall/syscall_linux.go | 13 |
1 files changed, 9 insertions, 4 deletions
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 |
