Fix a hang when shutting down Android (#772)

This commit is contained in:
John Maguire 2022-11-11 09:18:43 -07:00 committed by GitHub
parent 9af242dc47
commit 85f5849d0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -28,11 +28,13 @@ func newTunFromFd(l *logrus.Logger, deviceFd int, cidr *net.IPNet, _ int, routes
return nil, err
}
// XXX Android returns an fd in non-blocking mode which is necessary for shutdown to work properly.
// Be sure not to call file.Fd() as it will set the fd to blocking mode.
file := os.NewFile(uintptr(deviceFd), "/dev/net/tun")
return &tun{
ReadWriteCloser: file,
fd: int(file.Fd()),
fd: deviceFd,
cidr: cidr,
l: l,
routeTree: routeTree,