From b0bfa5dc15c2b67dc2172a76b1684a053ca4cd1c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 10 Dec 2018 01:43:08 +0100 Subject: [PATCH] unix: always use inotify_init1 over inotify_init on AMD64 ARM64 does this exact same thing, and in fact this is required on Android 9, where Bionic now only allows inotify_init on 32-bit platforms. Folks are running into this when using Android on Chromebooks, which are keeping AMD64 Android alive. So, we change the AMD64 behavior to model that of ARM64. However, since Go must run on kernels between 2.6.27 and 2.6.23, we must still fall back to the original call. Fixes: https://lore.kernel.org/wireguard/CALv=V9Gv6apdWJ9P-80zf9bgByd=c3QqPhRHuw6o0_OaH0=W6g@mail.gmail.com Change-Id: I183e82679cb7d702d12a35457920ccd422176254 Reviewed-on: https://go-review.googlesource.com/c/153318 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/syscall_linux_amd64.go | 12 +++++++++++- unix/zsyscall_linux_amd64.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/unix/syscall_linux_amd64.go b/unix/syscall_linux_amd64.go index 5247d9f9..912b4200 100644 --- a/unix/syscall_linux_amd64.go +++ b/unix/syscall_linux_amd64.go @@ -20,7 +20,17 @@ package unix //sysnb Getgid() (gid int) //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) //sysnb Getuid() (uid int) -//sysnb InotifyInit() (fd int, err error) +//sysnb inotifyInit() (fd int, err error) + +func InotifyInit() (fd int, err error) { + // First try inotify_init1, because Android's seccomp policy blocks the latter. + fd, err = InotifyInit1(0) + if err == ENOSYS { + fd, err = inotifyInit() + } + return +} + //sys Ioperm(from int, num int, on int) (err error) //sys Iopl(level int) (err error) //sys Lchown(path string, uid int, gid int) (err error) diff --git a/unix/zsyscall_linux_amd64.go b/unix/zsyscall_linux_amd64.go index 5e3abfc1..41010d6a 100644 --- a/unix/zsyscall_linux_amd64.go +++ b/unix/zsyscall_linux_amd64.go @@ -1806,7 +1806,7 @@ func Getuid() (uid int) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func InotifyInit() (fd int, err error) { +func inotifyInit() (fd int, err error) { r0, _, e1 := RawSyscall(SYS_INOTIFY_INIT, 0, 0, 0) fd = int(r0) if e1 != 0 {