From 32fcb3fccf060cb11e7ae0e2b434f6ff06e10bd0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 19 Apr 2018 07:55:24 +0200 Subject: Work around go fd closing limitation and version bump Signed-off-by: Jason A. Donenfeld --- app/tools/libwg-go/api-android.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'app/tools/libwg-go') diff --git a/app/tools/libwg-go/api-android.go b/app/tools/libwg-go/api-android.go index 6b864bce..af64f51f 100644 --- a/app/tools/libwg-go/api-android.go +++ b/app/tools/libwg-go/api-android.go @@ -11,6 +11,7 @@ import ( "math" "os" "strings" + "syscall" ) type AndroidLogger struct { @@ -42,15 +43,27 @@ func wgTurnOn(ifnameRef string, tun_fd int32, settings string) int32 { logger.Debug.Println("Debug log enabled") tun := &NativeTun{ - fd: os.NewFile(uintptr(tun_fd), ""), + fd: os.NewFile(uintptr(tun_fd), "/dev/tun"), events: make(chan TUNEvent, 5), errors: make(chan error, 5), nopi: true, } + var err error + + err = syscall.SetNonblock(int(tun_fd), true) + if err != nil { + logger.Error.Println(err) + return -1 + } + tun.closingReader, tun.closingWriter, err = os.Pipe() + if err != nil { + logger.Error.Println(err) + return -1 + } name, err := tun.Name() if err != nil { - logger.Error.Println(err) - return -1 + logger.Error.Println(err) + return -1 } logger.Info.Println("Attaching to interface", name) device := NewDevice(tun, logger) -- cgit v1.2.3