aboutsummaryrefslogtreecommitdiffstats
path: root/src/uapi_linux.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-07 15:25:04 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-07 15:25:04 +0200
commitcba1d6585ab9b12ae3e0897db85675ba452c3f09 (patch)
tree13d0975bf53a107c2760c833fd07f36d860a338a /src/uapi_linux.go
parentFirst set of code review patches (diff)
downloadwireguard-go-cba1d6585ab9b12ae3e0897db85675ba452c3f09.tar.xz
wireguard-go-cba1d6585ab9b12ae3e0897db85675ba452c3f09.zip
Number of fixes in response to code review
This version cannot complete a handshake. The program will panic upon receiving any message on the UDP socket.
Diffstat (limited to '')
-rw-r--r--src/uapi_linux.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/uapi_linux.go b/src/uapi_linux.go
index d6d78e7..fd56b5a 100644
--- a/src/uapi_linux.go
+++ b/src/uapi_linux.go
@@ -7,7 +7,6 @@ import (
"net"
"os"
"path"
- "time"
)
const (
@@ -26,9 +25,10 @@ const (
*/
type UAPIListener struct {
- listener net.Listener // unix socket listener
- connNew chan net.Conn
- connErr chan error
+ listener net.Listener // unix socket listener
+ connNew chan net.Conn
+ connErr chan error
+ inotifyFd int
}
func (l *UAPIListener) Accept() (net.Conn, error) {
@@ -106,9 +106,28 @@ func NewUAPIListener(name string) (net.Listener, error) {
// watch for deletion of socket
+ uapi.inotifyFd, err = unix.InotifyInit()
+ if err != nil {
+ return nil, err
+ }
+
+ _, err = unix.InotifyAddWatch(
+ uapi.inotifyFd,
+ socketPath,
+ unix.IN_ATTRIB|
+ unix.IN_DELETE|
+ unix.IN_DELETE_SELF,
+ )
+
+ if err != nil {
+ return nil, err
+ }
+
go func(l *UAPIListener) {
- for ; ; time.Sleep(time.Second) {
- if _, err := os.Stat(socketPath); os.IsNotExist(err) {
+ var buff [4096]byte
+ for {
+ unix.Read(uapi.inotifyFd, buff[:])
+ if _, err := os.Lstat(socketPath); os.IsNotExist(err) {
l.connErr <- err
return
}