From cba1d6585ab9b12ae3e0897db85675ba452c3f09 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Mon, 7 Aug 2017 15:25:04 +0200 Subject: 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. --- src/uapi_linux.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/uapi_linux.go') 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 } -- cgit v1.2.3