On Android, faccessat2 syscall (which supports flags like AT_EACCESS) is
not allowed, so syscall.Faccessat tries to emulate AT_EACCESS check in
userspace using os.Stat, os.Geteuid etc.
Also, according to [1],
> Android doesn't have setuid programs, and never runs code with euid!=uid.
This means on Android the proper AT_EACCESS check is neither possible
nor really needed.
Let's skip the syscall.Faccessat userspace emulation of AT_EACCESS
check and return ENOSYS, so the callers can use a fallback.
This should speed up exec.LookPath on Android.
[1]: https://android.googlesource.com/platform/bionic/+/
508b2f6e5cba4bdadf1e47a4ff27e25ce66c40e3/libc/bionic/faccessat.cpp#50
Change-Id: If7b529fa314480b70e9ae9cdd8c7ce82cd55d233
Reviewed-on: https://go-review.googlesource.com/c/go/+/611298
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
package unix
+import (
+ "runtime"
+ "syscall"
+)
+
func Eaccess(path string, mode uint32) error {
+ if runtime.GOOS == "android" {
+ // syscall.Faccessat for Android implements AT_EACCESS check in
+ // userspace. Since Android doesn't have setuid programs and
+ // never runs code with euid!=uid, AT_EACCESS check is not
+ // really required. Return ENOSYS so the callers can fall back
+ // to permission bits check.
+ return syscall.ENOSYS
+ }
return faccessat(AT_FDCWD, path, mode, AT_EACCESS)
}